Files
hh-auto-reply/src/index.ts

36 lines
944 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 🚀')