@@ -360,22 +360,12 @@ bool UniversalTelegramBot::setMyCommands(const String& commandArray) {
360
360
return false ;
361
361
}
362
362
363
- DynamicJsonDocument _commandArray (maxMessageLength);
364
- DeserializationError err = deserializeJson (_commandArray, commandArray);
365
- if (err) {
366
- #if defined(_debug)
367
- Serial.println (F (" sendSetMyCommands: Deserialization Error" ));
368
- Serial.println (commandArray);
369
- #endif // defined(_debug)
370
- return false ;
371
- }
372
-
373
363
DynamicJsonDocument payload (maxMessageLength);
374
364
payload[" commands" ] = serialized (commandArray);
375
365
bool sent = false ;
376
366
String response = " " ;
377
367
#if defined(_debug)
378
- Serial.println (F (" sendSetMyCommands: SEND Post /setMyCommands" ));
368
+ Serial.println (F (" sendSetMyCommands: SEND Post /setMyCommands" ));
379
369
#endif // defined(_debug)
380
370
unsigned long sttime = millis ();
381
371
@@ -621,14 +611,7 @@ bool UniversalTelegramBot::sendMessageWithReplyKeyboard(
621
611
622
612
JsonObject replyMarkup = payload.createNestedObject (" reply_markup" );
623
613
624
- // Reply keyboard is an array of arrays.
625
- // Outer array represents rows
626
- // Inner arrays represents columns
627
- // This example "ledon" and "ledoff" are two buttons on the top row
628
- // and "status is a single button on the next row"
629
- DynamicJsonDocument keyboardBuffer (maxMessageLength); // creating a buffer enough to keep keyboard string
630
- deserializeJson (keyboardBuffer, keyboard);
631
- replyMarkup[" keyboard" ] = keyboardBuffer.as <JsonArray>();
614
+ replyMarkup[" keyboard" ] = serialized (keyboard);
632
615
633
616
// Telegram defaults these values to false, so to decrease the size of the
634
617
// payload we will only send them if needed
@@ -657,9 +640,7 @@ bool UniversalTelegramBot::sendMessageWithInlineKeyboard(String chat_id,
657
640
payload[" parse_mode" ] = parse_mode;
658
641
659
642
JsonObject replyMarkup = payload.createNestedObject (" reply_markup" );
660
- DynamicJsonDocument keyboardBuffer (maxMessageLength); // assuming keyboard buffer will alwas be limited to 1024 bytes
661
- deserializeJson (keyboardBuffer, keyboard);
662
- replyMarkup[" inline_keyboard" ] = keyboardBuffer.as <JsonArray>();
643
+ replyMarkup[" inline_keyboard" ] = serialized (keyboard);
663
644
return sendPostMessage (payload.as <JsonObject>());
664
645
}
665
646
@@ -760,15 +741,13 @@ String UniversalTelegramBot::sendPhoto(String chat_id, String photo,
760
741
761
742
if (!keyboard.isEmpty ()) {
762
743
JsonObject replyMarkup = payload.createNestedObject (" reply_markup" );
763
- DynamicJsonDocument keyboardBuffer (maxMessageLength); // assuming keyboard buffer will alwas be limited to 1024 bytes
764
- deserializeJson (keyboardBuffer, keyboard);
765
- replyMarkup[" keyboard" ] = keyboardBuffer.as <JsonArray>();
744
+ replyMarkup[" keyboard" ] = serialized (keyboard);
766
745
}
767
746
768
747
return sendPostPhoto (payload.as <JsonObject>());
769
748
}
770
749
771
- bool UniversalTelegramBot::checkForOkResponse (String response) {
750
+ bool UniversalTelegramBot::checkForOkResponse (String & response) {
772
751
int last_id;
773
752
DynamicJsonDocument doc (response.length ());
774
753
deserializeJson (doc, response);
0 commit comments