feat(bot): add cancel command to conversation middleware

- Implemented a '/cancel' command in the bot's conversation middleware to allow users to exit all conversations gracefully.
- Removed the manual cancellation check from the addContact conversation, streamlining the code and improving user experience.
This commit is contained in:
vchikalkin 2025-09-07 16:09:39 +03:00
parent 5671ad5b02
commit 5f1ad4028c
2 changed files with 4 additions and 6 deletions

View File

@ -34,11 +34,6 @@ export async function addContact(conversation: Conversation<Context, Context>, c
// Ждем любое сообщение от пользователя
const waitCtx = await conversation.wait();
// Проверяем команду отмены
if (waitCtx.message?.text === '/cancel') {
return ctx.reply(await conversation.external(({ t }) => t('msg-cancel')));
}
// Проверяем, что отправлен контакт
if (!waitCtx.message?.contact) {
return ctx.reply(await conversation.external(({ t }) => t('msg-send-contact')));

View File

@ -38,7 +38,10 @@ export function createBot({ token }: Parameters_) {
}),
);
bot.use(grammyConversations());
bot.use(grammyConversations()).command('cancel', async (ctx) => {
await ctx.conversation.exitAll();
await ctx.reply(ctx.t('msg-cancel'));
});
for (const conversation of Object.values(conversations)) {
bot.use(createConversation(conversation));