@@ -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) *
0 commit comments