c++ Arduino / Telegram Bot,editmessage/button

brqmpdu1  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(69)

下午好。我正在ESP32上为智能温室编写一个机器人。我目前使用的是bool sendMessageWithInlineKeyboard(Stringchat_id, String text, String parse_mode, String Keyboard),但每次都会发送一条新消息。相反,我想更新现有消息,以便机器人不会发送大量消息。我该如何操作?

{
            if (text == ("LAMP"))
            { // Команды от кнопки (Включение/выключение)
                if (isLightTurned == 0)
                {
                    fill_solid(leds, NUM_LEDS, CRGB(255, 255, 255));
                    isLightTurned = 1;
                    FastLED.show();
                    String keyboardJson = "[[{ \"text\" : \"⏪ Назад\", \"callback_data\" : \"TEPLISA\" }]]";
                    bot.sendMessageWithInlineKeyboard(chat_id, "⚪ Освещение включено", "", keyboardJson);
                }
                else if (isLightTurned == 1)
                {
             
}

字符串

gwo2fgha

gwo2fgha1#

我假设你正在使用Universal-Arduino-Telegram-Bot库。
虽然README上的主要参考页面没有提到如何做到这一点,但提供的一个示例(UpdateInlineKeyboard.ino)显示您可以向sendMessageWithInlineKeyboard传递第五个参数,其中包含您想要更新的消息的消息ID:

// Now send this message including the current message_id as the 5th input to UPDATE that message
bot.sendMessageWithInlineKeyboard(chat_id, msg, "Markdown", keyboardJson, message_id);

字符串
UniversalTelegramBot.h中,您还可以看到sendMessageWithInlineKeyboard方法的完整签名是:

bool sendMessageWithInlineKeyboard(const String& chat_id, const String& text,
                                   const String& parse_mode, const String& keyboard, 
                                   int message_id = 0);


因此,在您的场景中,您应该获取要更新的消息的message_id,并在调用sendMessageWithInlineKeyboard时使用它。

相关问题