Skip to content

Commit 4148ae1

Browse files
committed
Merge branch 'issue_9_answerCallbackQuery'
2 parents 4e42dd0 + fa6bff5 commit 4148ae1

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/UniversalTelegramBot.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ String UniversalTelegramBot::sendPostToTelegram(const String& command, JsonObjec
152152
serializeJson(payload, out);
153153

154154
client->println(out);
155+
#ifdef _debug
156+
Serial.println(String("Posting:") + out);
157+
#endif
155158

156159
int ch_count = 0;
157160
now = millis();
@@ -834,21 +837,20 @@ bool UniversalTelegramBot::getFile(String& file_path, long& file_size, const Str
834837
}
835838

836839
bool UniversalTelegramBot::answerCallbackQuery(const String &query_id, const String &text, bool show_alert, const String &url, int cache_time) {
837-
String command = BOT_CMD("answerCallbackQuery?callback_query_id=");
838-
command += query_id;
839-
command += F("&show_alert=");
840-
command += show_alert;
841-
command += F("&cache_time=");
842-
command += cache_time;
843-
if (!text.isEmpty()) {
844-
command += F("&text=");
845-
command += text;
846-
}
847-
if (!url.isEmpty()) {
848-
command += F("&url=");
849-
command += url;
850-
}
851-
String response = sendGetToTelegram(command); // receive reply from telegram.org
840+
DynamicJsonDocument payload(maxMessageLength);
841+
842+
payload["callback_query_id"] = query_id;
843+
payload["show_alert"] = show_alert;
844+
payload["cache_time"] = cache_time;
845+
846+
if (!text.isEmpty()) payload["text"] = text;
847+
if (!url.isEmpty()) payload["url"] = url;
848+
849+
String response = sendPostToTelegram(BOT_CMD("answerCallbackQuery"), payload.as<JsonObject>());
850+
#ifdef _debug
851+
Serial.print(F("answerCallbackQuery response:"));
852+
Serial.println(response);
853+
#endif
852854
bool answer = checkForOkResponse(response);
853855
closeClient();
854856
return answer;

0 commit comments

Comments
 (0)