diff --git a/examples/ESP32/SendPhoto/PhotoFromFileID/PhotoFromFileID.ino b/examples/ESP32/SendPhoto/PhotoFromFileID/PhotoFromFileID.ino index 0c0a29a..0d62777 100644 --- a/examples/ESP32/SendPhoto/PhotoFromFileID/PhotoFromFileID.ino +++ b/examples/ESP32/SendPhoto/PhotoFromFileID/PhotoFromFileID.ino @@ -58,7 +58,7 @@ void handleNewMessages(int numNewMessages) if (bot.checkForOkResponse(response)) { - DynamicJsonDocument images(1500); + JsonDocument images; DeserializationError error = deserializeJson(images, response); // There are 3 image sizes after Telegram has process photo diff --git a/examples/ESP8266/BulkMessages/BulkMessages.ino b/examples/ESP8266/BulkMessages/BulkMessages.ino index eed97db..3508255 100644 --- a/examples/ESP8266/BulkMessages/BulkMessages.ino +++ b/examples/ESP8266/BulkMessages/BulkMessages.ino @@ -23,7 +23,7 @@ const unsigned long BOT_MTBS = 1000; // Mean time b WiFiClientSecure secured_client; X509List cert(TELEGRAM_CERTIFICATE_ROOT); UniversalTelegramBot bot(BOT_TOKEN, secured_client); -DynamicJsonDocument usersDoc(1500); +JsonDocument usersDoc; unsigned long bot_lasttime; // last time messages' scan has been done JsonObject getSubscribedUsers() diff --git a/examples/ESP8266/SendPhoto/PhotoFromFileID/PhotoFromFileID.ino b/examples/ESP8266/SendPhoto/PhotoFromFileID/PhotoFromFileID.ino index 6db436f..e7d65eb 100644 --- a/examples/ESP8266/SendPhoto/PhotoFromFileID/PhotoFromFileID.ino +++ b/examples/ESP8266/SendPhoto/PhotoFromFileID/PhotoFromFileID.ino @@ -44,7 +44,7 @@ void handleNewMessages(int numNewMessages) if (bot.checkForOkResponse(response)) { - DynamicJsonDocument images(1500); + JsonDocument images; DeserializationError error = deserializeJson(images, response); // There are 3 image sizes after Telegram has process photo diff --git a/library.json b/library.json index 8584e98..31b63de 100644 --- a/library.json +++ b/library.json @@ -18,7 +18,7 @@ "platforms": "*", "dependencies": [ { - "name": "bblanchon/ArduinoJson" + "bblanchon/ArduinoJson": "^7.0.0" } ], "build": { diff --git a/platformio.ini b/platformio.ini index f6fdfd6..061245c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,7 +13,7 @@ default_envs = d1_mini [env] lib_deps = - ArduinoJson + bblanchon/ArduinoJson@^7.0.0 monitor_speed = 115200 [env:d1_mini] diff --git a/src/UniversalTelegramBot.cpp b/src/UniversalTelegramBot.cpp index 86cd747..6edad69 100644 --- a/src/UniversalTelegramBot.cpp +++ b/src/UniversalTelegramBot.cpp @@ -302,7 +302,7 @@ String UniversalTelegramBot::sendMultipartFormDataToTelegram( bool UniversalTelegramBot::getMe() { String response = sendGetToTelegram(BOT_CMD("getMe")); // receive reply from telegram.org - DynamicJsonDocument doc(maxMessageLength); + JsonDocument doc; DeserializationError error = deserializeJson(doc, ZERO_COPY(response)); closeClient(); @@ -324,7 +324,7 @@ bool UniversalTelegramBot::getMe() { * Returns true, if the command list was updated successfully * ********************************************************************************/ bool UniversalTelegramBot::setMyCommands(const String& commandArray) { - DynamicJsonDocument payload(maxMessageLength); + JsonDocument payload; payload["commands"] = serialized(commandArray); bool sent = false; String response = ""; @@ -383,7 +383,7 @@ int UniversalTelegramBot::getUpdates(long offset) { #endif // Parse response into Json object - DynamicJsonDocument doc(maxMessageLength); + JsonDocument doc; DeserializationError error = deserializeJson(doc, ZERO_COPY(response)); if (!error) { @@ -562,7 +562,7 @@ bool UniversalTelegramBot::sendSimpleMessage(const String& chat_id, const String bool UniversalTelegramBot::sendMessage(const String& chat_id, const String& text, const String& parse_mode, int message_id) { // added message_id - DynamicJsonDocument payload(maxMessageLength); + JsonDocument payload; payload["chat_id"] = chat_id; payload["text"] = text; @@ -579,14 +579,14 @@ bool UniversalTelegramBot::sendMessageWithReplyKeyboard( const String& chat_id, const String& text, const String& parse_mode, const String& keyboard, bool resize, bool oneTime, bool selective) { - DynamicJsonDocument payload(maxMessageLength); + JsonDocument payload; payload["chat_id"] = chat_id; payload["text"] = text; if (parse_mode != "") payload["parse_mode"] = parse_mode; - JsonObject replyMarkup = payload.createNestedObject("reply_markup"); + JsonObject replyMarkup = payload["reply_markup"].to(); replyMarkup["keyboard"] = serialized(keyboard); @@ -610,7 +610,7 @@ bool UniversalTelegramBot::sendMessageWithInlineKeyboard(const String& chat_id, const String& keyboard, int message_id) { // added message_id - DynamicJsonDocument payload(maxMessageLength); + JsonDocument payload; payload["chat_id"] = chat_id; payload["text"] = text; @@ -620,7 +620,7 @@ bool UniversalTelegramBot::sendMessageWithInlineKeyboard(const String& chat_id, if (parse_mode != "") payload["parse_mode"] = parse_mode; - JsonObject replyMarkup = payload.createNestedObject("reply_markup"); + JsonObject replyMarkup = payload["reply_markup"].to(); replyMarkup["inline_keyboard"] = serialized(keyboard); return sendPostMessage(payload.as(), message_id); // if message id == 0 then edit is false, else edit is true } @@ -705,7 +705,7 @@ String UniversalTelegramBot::sendPhoto(const String& chat_id, const String& phot int reply_to_message_id, const String& keyboard) { - DynamicJsonDocument payload(maxMessageLength); + JsonDocument payload; payload["chat_id"] = chat_id; payload["photo"] = photo; @@ -719,7 +719,7 @@ String UniversalTelegramBot::sendPhoto(const String& chat_id, const String& phot payload["reply_to_message_id"] = reply_to_message_id; if (keyboard.length() > 0) { - JsonObject replyMarkup = payload.createNestedObject("reply_markup"); + JsonObject replyMarkup = payload["reply_markup"].to(); replyMarkup["keyboard"] = serialized(keyboard); } @@ -728,7 +728,7 @@ String UniversalTelegramBot::sendPhoto(const String& chat_id, const String& phot bool UniversalTelegramBot::checkForOkResponse(const String& response) { int last_id; - DynamicJsonDocument doc(response.length()); + JsonDocument doc; deserializeJson(doc, response); // Save last sent message_id @@ -783,7 +783,7 @@ bool UniversalTelegramBot::getFile(String& file_path, long& file_size, const Str String command = BOT_CMD("getFile?file_id="); command += file_id; String response = sendGetToTelegram(command); // receive reply from telegram.org - DynamicJsonDocument doc(maxMessageLength); + JsonDocument doc; DeserializationError error = deserializeJson(doc, ZERO_COPY(response)); closeClient(); @@ -799,7 +799,7 @@ bool UniversalTelegramBot::getFile(String& file_path, long& file_size, const Str } bool UniversalTelegramBot::answerCallbackQuery(const String &query_id, const String &text, bool show_alert, const String &url, int cache_time) { - DynamicJsonDocument payload(maxMessageLength); + JsonDocument payload; payload["callback_query_id"] = query_id; payload["show_alert"] = show_alert;