mirror of
https://github.com/hempyhemp/hh-auto-reply.git
synced 2026-06-08 18:04:57 +00:00
36 lines
944 B
TypeScript
36 lines
944 B
TypeScript
import bot from '@bot'
|
||
|
||
import prisma from '@prisma'
|
||
import { registerHHCommands, triggerHHStart } from './hh/bot-commands.js'
|
||
|
||
registerHHCommands()
|
||
|
||
bot.onText(/\/start/, async (msg) => {
|
||
const chatId = msg.chat.id
|
||
const telegramId = BigInt(chatId)
|
||
|
||
const existingUser = await prisma.user.findUnique({ where: { telegramId } })
|
||
|
||
await prisma.user.upsert({
|
||
where: { telegramId },
|
||
update: { username: msg.from?.username ?? null },
|
||
create: {
|
||
telegramId,
|
||
username: msg.from?.username ?? null,
|
||
firstName: msg.from?.first_name ?? null,
|
||
Settings: { create: {} },
|
||
},
|
||
})
|
||
|
||
if (!existingUser) {
|
||
await bot.sendMessage(
|
||
chatId,
|
||
`👋 Привет, ${msg.from?.first_name ?? 'друг'}!\n\nЭто бот для авто-откликов на hh.ru.\nНачни с логина — нажми 🔑 Логин.`,
|
||
)
|
||
}
|
||
|
||
await triggerHHStart(chatId)
|
||
})
|
||
|
||
console.log('Bot started 🚀')
|