[英]How to unregister middleware in Telegraf?
當我添加bot.hears(...)
時,它會注冊用於處理匹配文本消息的中間件。 但是現在它會處理這些消息,即使它們是隨時發送的,即使不是預期的。 因此,如果我正在創建一個有狀態的服務,我想只在適當的時間收聽特定的消息。
如何取消注冊中間件,使其不再hear
以前處理過的消息?
我原來是在尋找Scenes 。 Github上描述了如何使用它們。
我將從上面的鏈接中發布一個稍微修改過的代碼:
const { Telegraf, Scenes, session } = require('telegraf')
const contactDataWizard = new Scenes.WizardScene(
'CONTACT_DATA_WIZARD_SCENE_ID', // first argument is Scene_ID, same as for BaseScene
(ctx) => {
ctx.reply('Please enter guest\'s first name', Markup.removeKeyboard());
ctx.wizard.state.contactData = {};
return ctx.wizard.next();
},
(ctx) => {
// validation example
if (ctx.message.text.length < 2) {
ctx.reply('Please enter real name');
return;
}
ctx.wizard.state.contactData.firstName = ctx.message.text;
ctx.reply('And last name...');
return ctx.wizard.next();
},
);
const stage = new Scenes.Stage();
stage.register(contactDataWizard);
bot.use(session());
bot.use(stage.middleware());
但是我仍然不知道如何大致實現它,所以我需要在 Telegraf 的 Scenes 代碼中找到它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.