yagop / node-telegram-bot-api

Telegram Bot API for NodeJS
MIT License
8.17k stars 1.5k forks source link

How can i send inline_keyboard to topic (thread)? #1073

Closed alexkomsp closed 1 year ago

alexkomsp commented 1 year ago

Can't figured out how to send inline_keyboard into topic of group. It works only in "General" topic.

My code:


const keyboardButtons = {
        reply_markup: JSON.stringify( {
            inline_keyboard: [
                [{text: 'Btn1', callback_data: 'test1'}],
                [{text: 'Btn2', callback_data: 'test2'}],
            ]
        })
}

bot.on('message', async (msg) => {
        const chatId = msg.chat.id;
        const text = msg.text;
        const topic = {};
        if (msg.is_topic_message) {
                topic.message_thread_id = msg.message_thread_id;
        }

        if (text === 'test') {
                await bot.sendMessage(chatId, 'some text', topic, keyboardButtons );
        }

It sended just 'some text' without keyboardButtons

VDS13 commented 1 year ago

@alexkomsp, Hi)

Three parameters are passed to the sendMessage function: _chatid, message, and an options object. You are passing 4 parameters, splitting the option into two objects. Below is a solution that should help.

const keyboardButtons = {
        reply_markup: {
            inline_keyboard: [
                [{text: 'Btn1', callback_data: 'test1'}],
                [{text: 'Btn2', callback_data: 'test2'}],
            ]
        })
}

bot.on('message', async (msg) => {
        const chatId = msg.chat.id;
        const text = msg.text;
        const topic = {};
        if (msg.is_topic_message) {
                topic.message_thread_id = msg.message_thread_id;
        }

        if (text === 'test') {
                await bot.sendMessage(chatId, 'some text', Object.assign(topic, keyboardButtons) );
        }
alexkomsp commented 1 year ago

@VDS13 Hi!) It works! Thank you so much!