我正在创建一个使用node-telegram-bot-api包的电报机器人。该包使用EventEmitter3来发出事件。
我有一个监听程序,它在所有其他监听程序之前执行:
Bot.prependListener( 'message', ( msg ) =>
if ( CHECK msg.from.id FOR AUTHORIZED USERS == false ) {
// IGNORE ALL OTHER LISTENERS
}
} );
Bot.onText( /\/start/i, ( msg ) => {
Bot.sendMessage( msg.from.id, `You're an authorized user for sure!` );
} );如何让EventEmitter忽略所有其他监听程序?
发布于 2016-08-15 12:04:25
你需要一些具有真正中间件支持的东西。例如:Telegraf
const Telegraf = require('telegraf')
const app = new Telegraf(process.env.BOT_TOKEN)
app.use((ctx, next) => {
if(AUTHORIZED_USERS.includes(ctx.from.id)){
return next()
}
})
app.command('/start', (ctx) => ctx.reply('You`re an authorized user for sure!'))
app.startPolling()
https://stackoverflow.com/questions/38418784
复制相似问题