Using node-telegram-bot-api
. I have a Webhook that works properly – i get updates when messages are sent, but no update is sent when the user presses a button in an inline keyboard.
class BotController {
async handleUpdate(req, res, next){
console.log(req.body);
if (req.body.message.text === "/getTypes"){
sendTypesKeyboard(req.body.message.chat.id);
}
return res.json({message: "update handled"});
}
}
const sendTypesKeyboard = async (chatId) => {
const types = await typeDbHandler.getAll();
const options = {
reply_markup: JSON.stringify({
inline_keyboard: types.map((type) =>
[{"text": type.name, "callback_data": type.id}]
)
})
}
bot.sendMessage(chatId, "Choose the type", options);
}
I tried to use polling
and handle a callback_query
event, but it didn’t work either
const TelegramApi = require('node-telegram-bot-api');
const BOT_TOKEN = process.env.BOT_TOKEN;
const bot = new TelegramApi(BOT_TOKEN, {polling: true});
// bot.setWebHook(`${process.env.URL}/bot`);
bot.on('callback_query', (query) => {
console.log(query);
})
bot.on('message', msg => {
console.log(msg);
})
module.exports = bot;
Again, updates with messages are recieved, but callback_query is never fired