Arduino / Telegram Bot,编辑消息/按钮

问题描述 投票:0回答:1

下午好。我正在 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)
                {
             
}
c++ arduino esp32
1个回答
0
投票

我假设您正在使用 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
时使用它。

© www.soinside.com 2019 - 2024. All rights reserved.