@@ -606,25 +606,29 @@ bool UniversalTelegramBot::sendMessageWithReplyKeyboard(
606
606
bool UniversalTelegramBot::sendMessageWithInlineKeyboard (const String& chat_id,
607
607
const String& text,
608
608
const String& parse_mode,
609
- const String& keyboard) {
609
+ const String& keyboard,
610
+ const int & message_id) { // added message_id
610
611
611
612
DynamicJsonDocument payload (maxMessageLength);
612
613
payload[" chat_id" ] = chat_id;
613
614
payload[" text" ] = text;
614
615
616
+ if (message_id != 0 )
617
+ payload[" message_id" ] = message_id; // added message_id
618
+
615
619
if (parse_mode != " " )
616
620
payload[" parse_mode" ] = parse_mode;
617
621
618
622
JsonObject replyMarkup = payload.createNestedObject (" reply_markup" );
619
623
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
621
625
}
622
626
623
627
/* **********************************************************************
624
- * SendPostMessage - function to send message to telegram *
628
+ * SendPostMessage - function to send message to telegram *
625
629
* (Arguments to pass: chat_id, text to transmit and markup(optional)) *
626
630
***********************************************************************/
627
- bool UniversalTelegramBot::sendPostMessage (JsonObject payload) {
631
+ bool UniversalTelegramBot::sendPostMessage (JsonObject payload, bool edit = false ) { // added message_id
628
632
629
633
bool sent = false ;
630
634
#ifdef TELEGRAM_DEBUG
@@ -636,8 +640,8 @@ bool UniversalTelegramBot::sendPostMessage(JsonObject payload) {
636
640
637
641
if (payload.containsKey (" text" )) {
638
642
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
641
645
Serial.println (response);
642
646
#endif
643
647
sent = checkForOkResponse (response);
0 commit comments