windkh / node-red-contrib-telegrambot

Telegram bot nodes for node-red.
Other
264 stars 117 forks source link

ReplyKeyboardRemove #326

Closed SimoneGuido04 closed 1 year ago

SimoneGuido04 commented 1 year ago

Hi, I was wondering if there is an option to remove the custom keyboard, I found out that on the telegram APIs there is an option called "ReplyKeyboardRemove" that can force remove the custom keyboard, how can implement that? any suggestions?

windkh commented 1 year ago

I will add this for you in the next version if possible

SimoneGuido04 commented 1 year ago

Thank you vary much!

windkh commented 1 year ago

Please reopen it. I will close it when the feature is implemented

SimoneGuido04 commented 1 year ago

Sure Man! Do you know when u gonna release new version?

SimoneGuido04 commented 1 year ago

If someone was wondering how to overcome to that issue (until new version came out) there is a workaround:

const token = 'BOT TOKEN';
    const chatId = msg.payload.chatId;
    const messageText = 'Grazie per aver consultato gli appunti';

    const keyboardRemove = {
        remove_keyboard: true
    };

    axios.post(`https://api.telegram.org/bot${token}/sendMessage`, {
        chat_id: chatId,
        text: messageText,
        reply_markup: JSON.stringify(keyboardRemove)
    })
        .then(response => {
            console.log(response.data);
        })
        .catch(error => {
            console.error(error);
        });

you need to include "axios" module in Setup Tab.

windkh commented 1 year ago

@SimoneGuido04 looking at the api doc I recognized that ReplyKeyboardRemove is just an object like InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply

which can be passed as optional parameter named reply_markup.

So there is no need for any changes in the code: just add reply_markup property to the options of your message. Just have a look at the keyboard examples and look for InlineKeyboardMarkup.... just do it the same way but with ReplyKeyboardRemove.

I just do not have the time to test this, but if you fail, then let me know.