@@ -343,6 +343,54 @@ bool UniversalTelegramBot::getMe() {
343
343
return false ;
344
344
}
345
345
346
+ /* ********************************************************************************
347
+ * SetMyCommands - Update the command list of the bot on the telegram server *
348
+ * (Argument to pass: Serialied array of BotCommand) *
349
+ * CAUTION: All commands must be lower-case *
350
+ * Returns true, if the command list was updated successfully *
351
+ ********************************************************************************/
352
+ bool UniversalTelegramBot::setMyCommands (const String& commandArray) {
353
+ if (commandArray.isEmpty ()) {
354
+ #if defined(_debug)
355
+ Serial.println (F (" sendSetMyCommands: commandArray is empty" ));
356
+ #endif // defined(_debug)
357
+ return false ;
358
+ }
359
+
360
+ DynamicJsonDocument _commandArray (maxMessageLength);
361
+ DeserializationError err = deserializeJson (_commandArray, commandArray);
362
+ if (err) {
363
+ #if defined(_debug)
364
+ Serial.println (F (" sendSetMyCommands: Deserialization Error" ));
365
+ Serial.println (commandArray);
366
+ #endif // defined(_debug)
367
+ return false ;
368
+ }
369
+
370
+ DynamicJsonDocument payload (maxMessageLength);
371
+ payload[" commands" ] = serialized (commandArray);
372
+ bool sent = false ;
373
+ String response = " " ;
374
+ #if defined(_debug)
375
+ Serial.println (F (" sendSetMyCommands: SEND Post /setMyCommands" ));
376
+ #endif // defined(_debug)
377
+ unsigned long sttime = millis ();
378
+
379
+ while (millis () < sttime + 8000ul ) { // loop for a while to send the message
380
+ String command = " bot" + _token + " /setMyCommands" ;
381
+ response = sendPostToTelegram (command, payload.as <JsonObject>());
382
+ #ifdef _debug
383
+ Serial.println (" setMyCommands response" + response);
384
+ #endif
385
+ sent = checkForOkResponse (response);
386
+ if (sent) break ;
387
+
388
+ }
389
+ closeClient ();
390
+ return response;
391
+ }
392
+
393
+
346
394
/* **************************************************************
347
395
* GetUpdates - function to receive messages from telegram *
348
396
* (Argument to pass: the last+1 message to read) *
@@ -691,7 +739,7 @@ String UniversalTelegramBot::sendPhoto(String chat_id, String photo,
691
739
payload[" chat_id" ] = chat_id;
692
740
payload[" photo" ] = photo;
693
741
694
- if (caption)
742
+ if (! caption. isEmpty () )
695
743
payload[" caption" ] = caption;
696
744
697
745
if (disable_notification)
@@ -700,7 +748,7 @@ String UniversalTelegramBot::sendPhoto(String chat_id, String photo,
700
748
if (reply_to_message_id && reply_to_message_id != 0 )
701
749
payload[" reply_to_message_id" ] = reply_to_message_id;
702
750
703
- if (keyboard) {
751
+ if (! keyboard. isEmpty () ) {
704
752
JsonObject replyMarkup = payload.createNestedObject (" reply_markup" );
705
753
DynamicJsonDocument keyboardBuffer (maxMessageLength); // assuming keyboard buffer will alwas be limited to 1024 bytes
706
754
deserializeJson (keyboardBuffer, keyboard);
0 commit comments