Skip to content

Commit 5958034

Browse files
committed
AndroidJson6 compatibility
1 parent 7f885c0 commit 5958034

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/UniversalTelegramBot.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -763,19 +763,16 @@ void UniversalTelegramBot::closeClient() {
763763
bool UniversalTelegramBot::getFile(String *file_path, long *file_size, String file_id)
764764
{
765765
String command = "bot" + _token + "/getFile?file_id=" + file_id;
766-
String response =
767-
sendGetToTelegram(command); // receive reply from telegram.org
768-
DynamicJsonBuffer jsonBuffer;
769-
JsonObject &root = jsonBuffer.parseObject(response);
770-
766+
String response = sendGetToTelegram(command); // receive reply from telegram.org
767+
DynamicJsonDocument doc(maxMessageLength);
768+
DeserializationError error = deserializeJson(doc, response);
769+
JsonObject obj = doc.as<JsonObject>(); //there is nothing better right now to use obj.containsKey("result")
771770
closeClient();
772771

773-
if (root.success())
774-
{
775-
if (root.containsKey("result"))
776-
{
777-
*file_path = "https://api.telegram.org/file/bot" + _token + "/" + root["result"]["file_path"].as<String>();
778-
*file_size = root["result"]["file_size"].as<long>();
772+
if (!error) {
773+
if (obj.containsKey("result")) {
774+
*file_path = "https://api.telegram.org/file/bot" + _token + "/" + obj["result"]["file_path"].as<String>();
775+
*file_size = obj["result"]["file_size"].as<long>();
779776
return true;
780777
}
781778
}

0 commit comments

Comments
 (0)