36
36
#include " UniversalTelegramBot.h"
37
37
38
38
#define ZERO_COPY (STR ) ((char *)STR.c_str())
39
+ #define BOT_CMD (STR ) buildCommand(F(STR))
39
40
40
41
UniversalTelegramBot::UniversalTelegramBot (String token, Client &client) {
41
42
_token = token;
@@ -338,7 +339,7 @@ String UniversalTelegramBot::sendMultipartFormDataToTelegram(
338
339
339
340
340
341
bool UniversalTelegramBot::getMe () {
341
- String response = sendGetToTelegram (buildCommand ( F ( " getMe" ) )); // receive reply from telegram.org
342
+ String response = sendGetToTelegram (BOT_CMD ( " getMe" )); // receive reply from telegram.org
342
343
DynamicJsonDocument doc (maxMessageLength);
343
344
DeserializationError error = deserializeJson (doc, ZERO_COPY (response));
344
345
closeClient ();
@@ -371,7 +372,7 @@ bool UniversalTelegramBot::setMyCommands(const String& commandArray) {
371
372
unsigned long sttime = millis ();
372
373
373
374
while (millis () < sttime + 8000ul ) { // loop for a while to send the message
374
- response = sendPostToTelegram (buildCommand ( F ( " setMyCommands" ) ), payload.as <JsonObject>());
375
+ response = sendPostToTelegram (BOT_CMD ( " setMyCommands" ), payload.as <JsonObject>());
375
376
#ifdef _debug
376
377
Serial.println (" setMyCommands response" + response);
377
378
#endif
@@ -394,7 +395,7 @@ int UniversalTelegramBot::getUpdates(long offset) {
394
395
#ifdef _debug
395
396
Serial.println (F (" GET Update Messages" ));
396
397
#endif
397
- String command = buildCommand ( F ( " getUpdates?offset=" ) );
398
+ String command = BOT_CMD ( " getUpdates?offset=" );
398
399
command += offset;
399
400
command += F (" &limit=" );
400
401
command += HANDLE_MESSAGES;
@@ -576,7 +577,7 @@ bool UniversalTelegramBot::sendSimpleMessage(String chat_id, String text,
576
577
577
578
if (text != " " ) {
578
579
while (millis () < sttime + 8000 ) { // loop for a while to send the message
579
- String command = buildCommand ( F ( " sendMessage?chat_id=" ) );
580
+ String command = BOT_CMD ( " sendMessage?chat_id=" );
580
581
command += chat_id;
581
582
command += F (" &text=" );
582
583
command += text;
@@ -669,7 +670,7 @@ bool UniversalTelegramBot::sendPostMessage(JsonObject payload) {
669
670
670
671
if (payload.containsKey (" text" )) {
671
672
while (millis () < sttime + 8000 ) { // loop for a while to send the message
672
- String response = sendPostToTelegram (buildCommand ( F ( " sendMessage" ) ), payload);
673
+ String response = sendPostToTelegram (BOT_CMD ( " sendMessage" ), payload);
673
674
#ifdef _debug
674
675
Serial.println (response);
675
676
#endif
@@ -693,7 +694,7 @@ String UniversalTelegramBot::sendPostPhoto(JsonObject payload) {
693
694
694
695
if (payload.containsKey (" photo" )) {
695
696
while (millis () < sttime + 8000 ) { // loop for a while to send the message
696
- response = sendPostToTelegram (buildCommand ( F ( " sendPhoto" ) ), payload);
697
+ response = sendPostToTelegram (BOT_CMD ( " sendPhoto" ), payload);
697
698
#ifdef _debug
698
699
Serial.println (response);
699
700
#endif
@@ -776,7 +777,7 @@ bool UniversalTelegramBot::sendChatAction(String chat_id, String text) {
776
777
777
778
if (text != " " ) {
778
779
while (millis () < sttime + 8000 ) { // loop for a while to send the message
779
- String command = buildCommand ( F ( " sendChatAction?chat_id=" ) );
780
+ String command = BOT_CMD ( " sendChatAction?chat_id=" );
780
781
command += chat_id;
781
782
command += F (" &action=" );
782
783
command += text;
@@ -808,7 +809,7 @@ void UniversalTelegramBot::closeClient() {
808
809
809
810
bool UniversalTelegramBot::getFile (String *file_path, long *file_size, String file_id)
810
811
{
811
- String command = buildCommand ( F ( " getFile?file_id=" ) );
812
+ String command = BOT_CMD ( " getFile?file_id=" );
812
813
command += file_id;
813
814
String response = sendGetToTelegram (command); // receive reply from telegram.org
814
815
DynamicJsonDocument doc (maxMessageLength);
0 commit comments