diff --git a/src/bot/conversations/greeting.ts b/src/bot/conversations/greeting.ts deleted file mode 100644 index 8ac4113..0000000 --- a/src/bot/conversations/greeting.ts +++ /dev/null @@ -1,34 +0,0 @@ -import type { Conversation } from '@grammyjs/conversations' -import { createConversation } from '@grammyjs/conversations' -import type { Context } from '#root/bot/context.js' -import { i18n } from '#root/bot/i18n.js' - -export const GREETING_CONVERSATION = 'greeting' - -export function greetingConversation() { - return createConversation( - async (conversation: Conversation, ctx: Context) => { - await conversation.run(i18n) - - await ctx.reply('Please send me your name') - - while (true) { - ctx = await conversation.wait() - - if (ctx.hasCommand('cancel')) { - return ctx.reply('Cancelled') - } - else if (ctx.has('message:text')) { - ctx.chatAction = 'typing' - await conversation.sleep(1000) - - await ctx.reply(`Hello, ${ctx.message.text}!`) - } - else { - await ctx.reply('Please send me your name') - } - } - }, - GREETING_CONVERSATION, - ) -} diff --git a/src/bot/conversations/index.ts b/src/bot/conversations/index.ts index de53144..28f287d 100644 --- a/src/bot/conversations/index.ts +++ b/src/bot/conversations/index.ts @@ -1 +1 @@ -export * from './greeting.js' +export * from './send.js' diff --git a/src/bot/conversations/send.ts b/src/bot/conversations/send.ts new file mode 100644 index 0000000..56bbaec --- /dev/null +++ b/src/bot/conversations/send.ts @@ -0,0 +1,37 @@ +import type { Conversation } from '@grammyjs/conversations' +import { createConversation } from '@grammyjs/conversations' +import type { Context } from '#root/bot/context.js' +import { i18n } from '#root/bot/i18n.js' + +export const SEND_CONVERSATION = 'send' + +export function sendConversation() { + return createConversation( + async (conversation: Conversation, ctx: Context) => { + await conversation.run(i18n) + + await ctx.reply('Please send me the photo') + + while (true) { + ctx = await conversation.wait() + + if (ctx.hasCommand('cancel')) { + return ctx.reply('Cancelled') + } + else if (ctx.has('message:photo')) { + const fileId = ctx.message?.photo?.pop()?.file_id + const [adminId] = JSON.parse(`${Bun.env.BOT_ADMINS}`) + if (fileId) { + await ctx.reply(`Thanks for the photo!`) + await ctx.api.sendPhoto(adminId, fileId) + await ctx.api.sendMessage(adminId, `User @${ctx.message?.from.username} suggest photo:\nApprove? /approve_${ctx.message?.message_id} Reject? /reject_${ctx.message?.message_id}`) + } + } + else { + await ctx.reply('Please send me your name') + } + } + }, + SEND_CONVERSATION, + ) +} diff --git a/src/bot/features/welcome.ts b/src/bot/features/welcome.ts index 329a959..3acef0a 100644 --- a/src/bot/features/welcome.ts +++ b/src/bot/features/welcome.ts @@ -1,7 +1,7 @@ import { Composer } from 'grammy' import type { Context } from '#root/bot/context.js' import { logHandle } from '#root/bot/helpers/logging.js' -import { GREETING_CONVERSATION } from '#root/bot/conversations/index.js' +import { SEND_CONVERSATION } from '#root/bot/conversations/index.js' const composer = new Composer() @@ -11,8 +11,8 @@ feature.command('start', logHandle('command-start'), (ctx) => { return ctx.reply(ctx.t('welcome')) }) -feature.command('greeting', logHandle('command-greeting'), (ctx) => { - return ctx.conversation.enter(GREETING_CONVERSATION) +feature.command(SEND_CONVERSATION, logHandle('command-send'), (ctx) => { + return ctx.conversation.enter(SEND_CONVERSATION) }) export { composer as welcomeFeature } diff --git a/src/bot/index.ts b/src/bot/index.ts index ff50bd8..35cd50b 100644 --- a/src/bot/index.ts +++ b/src/bot/index.ts @@ -22,7 +22,7 @@ import { i18n, isMultipleLocales } from '#root/bot/i18n.js' import { updateLogger } from '#root/bot/middlewares/index.js' import { config } from '#root/config.js' import { logger } from '#root/logger.js' -import { greetingConversation } from '#root/bot/conversations/index.js' +import { sendConversation } from '#root/bot/conversations/index.js' interface Options { sessionStorage?: StorageAdapter @@ -54,7 +54,7 @@ export function createBot(token: string, options: Options = {}) { ) protectedBot.use(i18n) protectedBot.use(conversations()) - protectedBot.use(greetingConversation()) + protectedBot.use(sendConversation()) // Handlers protectedBot.use(welcomeFeature)