Skip to content

Commit fa6bff5

Browse files
committed
Issue witnessmenow#9: answerCallbackQuery changed to use POST instead of GET
1 parent e9c1c4d commit fa6bff5

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();
@@ -839,21 +842,20 @@ bool UniversalTelegramBot::getFile(String& file_path, long& file_size, const Str
839842
}
840843

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

0 commit comments

Comments
 (0)