mirror of
https://github.com/hempyhemp/hh-auto-reply.git
synced 2026-06-08 18:04:57 +00:00
36 lines
764 B
TypeScript
36 lines
764 B
TypeScript
import bot from '@bot'
|
|
import prisma from '@prisma'
|
|
|
|
import { sendMenu } from './bot-menu'
|
|
import { registerHHCommands } 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 },
|
|
})
|
|
|
|
const isFirstTime = !existingUser
|
|
|
|
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: {} },
|
|
},
|
|
})
|
|
|
|
await sendMenu(chatId, isFirstTime)
|
|
})
|
|
|
|
console.log('Bot started 🚀')
|