0

I'm currently build a telegram bot and i have one issue. In my case has had a few inline keyboard. here are enter image description here but all inline keyboard has a one handler

bot.on('callback_query',query=>{
    bot.answerCallbackQuery(query.id,{text:query.data,show_alert:false})
    console.log(query)
})

so i will need check with a if else condition for all handler in callback_query event but i don't like this way. Then i will had find one to get rid of 'if else'. In this i will had use a EventEmitter to separate each handler

emitter.on('eventOne',(chatId)=>{
    ... business logic of handler
})
emitter.on('eventTwo',(chatId)=>{
    ... business logic of handler
})
bot.on('callback_query',query=>{
    emitter.emit(query.data,query.message.chat.id)
    bot.answerCallbackQuery(query.id,{text:query.data,show_alert:false})
    console.log(query)
})

is this way right or not, if not i need a right implementation of this issue.

Sorry for grammar mistakes, my native language is Uzbek ;)

I need a right implamentation of inline_keyboards handler

0 Answers0