Skip to content

Commit 1eda34d

Browse files
committed
Added option to send editMessageText
1 parent b8ba7b0 commit 1eda34d

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/UniversalTelegramBot.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -606,25 +606,29 @@ bool UniversalTelegramBot::sendMessageWithReplyKeyboard(
606606
bool UniversalTelegramBot::sendMessageWithInlineKeyboard(const String& chat_id,
607607
const String& text,
608608
const String& parse_mode,
609-
const String& keyboard) {
609+
const String& keyboard,
610+
const int& message_id) { // added message_id
610611

611612
DynamicJsonDocument payload(maxMessageLength);
612613
payload["chat_id"] = chat_id;
613614
payload["text"] = text;
614615

616+
if (message_id != 0)
617+
payload["message_id"] = message_id; // added message_id
618+
615619
if (parse_mode != "")
616620
payload["parse_mode"] = parse_mode;
617621

618622
JsonObject replyMarkup = payload.createNestedObject("reply_markup");
619623
replyMarkup["inline_keyboard"] = serialized(keyboard);
620-
return sendPostMessage(payload.as<JsonObject>());
624+
return sendPostMessage(payload.as<JsonObject>(), message_id); // if message id == 0 then edit is false, else edit is true
621625
}
622626

623627
/***********************************************************************
624-
* SendPostMessage - function to send message to telegram *
628+
* SendPostMessage - function to send message to telegram *
625629
* (Arguments to pass: chat_id, text to transmit and markup(optional)) *
626630
***********************************************************************/
627-
bool UniversalTelegramBot::sendPostMessage(JsonObject payload) {
631+
bool UniversalTelegramBot::sendPostMessage(JsonObject payload, bool edit = false) { // added message_id
628632

629633
bool sent = false;
630634
#ifdef TELEGRAM_DEBUG
@@ -636,8 +640,8 @@ bool UniversalTelegramBot::sendPostMessage(JsonObject payload) {
636640

637641
if (payload.containsKey("text")) {
638642
while (millis() < sttime + 8000) { // loop for a while to send the message
639-
String response = sendPostToTelegram(BOT_CMD("sendMessage"), payload);
640-
#ifdef TELEGRAM_DEBUG
643+
String response = sendPostToTelegram((edit ? BOT_CMD("editMessageText") : BOT_CMD("sendMessage")), payload); // if edit is true we send a editMessageText CMD
644+
#ifdef TELEGRAM_DEBUG
641645
Serial.println(response);
642646
#endif
643647
sent = checkForOkResponse(response);

src/UniversalTelegramBot.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ class UniversalTelegramBot {
9090
bool resize = false, bool oneTime = false,
9191
bool selective = false);
9292
bool sendMessageWithInlineKeyboard(const String& chat_id, const String& text,
93-
const String& parse_mode, const String& keyboard);
93+
const String& parse_mode, const String& keyboard, const int& message_id = 0); // added message id
9494

9595
bool sendChatAction(const String& chat_id, const String& text);
9696

97-
bool sendPostMessage(JsonObject payload);
97+
bool sendPostMessage(JsonObject payload, bool edit = false); // added message id option to send an editMessageText command
9898
String sendPostPhoto(JsonObject payload);
9999
String sendPhotoByBinary(const String& chat_id, const String& contentType, int fileSize,
100100
MoreDataAvailable moreDataAvailableCallback,

0 commit comments

Comments
 (0)