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:
parent
5671ad5b02
commit
5f1ad4028c
@ -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')));
|
||||
|
||||
@ -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));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user