Skip to content

Commit d17bf72

Browse files
committed
Issue #5: define for factoring out common code
1 parent 76464a8 commit d17bf72

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/UniversalTelegramBot.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "UniversalTelegramBot.h"
3737

3838
#define ZERO_COPY(STR) ((char*)STR.c_str())
39+
#define BOT_CMD(STR) buildCommand(F(STR))
3940

4041
UniversalTelegramBot::UniversalTelegramBot(String token, Client &client) {
4142
_token = token;
@@ -338,7 +339,7 @@ String UniversalTelegramBot::sendMultipartFormDataToTelegram(
338339

339340

340341
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
342343
DynamicJsonDocument doc(maxMessageLength);
343344
DeserializationError error = deserializeJson(doc, ZERO_COPY(response));
344345
closeClient();
@@ -371,7 +372,7 @@ bool UniversalTelegramBot::setMyCommands(const String& commandArray) {
371372
unsigned long sttime = millis();
372373

373374
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>());
375376
#ifdef _debug
376377
Serial.println("setMyCommands response" + response);
377378
#endif
@@ -394,7 +395,7 @@ int UniversalTelegramBot::getUpdates(long offset) {
394395
#ifdef _debug
395396
Serial.println(F("GET Update Messages"));
396397
#endif
397-
String command = buildCommand(F("getUpdates?offset="));
398+
String command = BOT_CMD("getUpdates?offset=");
398399
command += offset;
399400
command += F("&limit=");
400401
command += HANDLE_MESSAGES;
@@ -576,7 +577,7 @@ bool UniversalTelegramBot::sendSimpleMessage(String chat_id, String text,
576577

577578
if (text != "") {
578579
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=");
580581
command += chat_id;
581582
command += F("&text=");
582583
command += text;
@@ -669,7 +670,7 @@ bool UniversalTelegramBot::sendPostMessage(JsonObject payload) {
669670

670671
if (payload.containsKey("text")) {
671672
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);
673674
#ifdef _debug
674675
Serial.println(response);
675676
#endif
@@ -693,7 +694,7 @@ String UniversalTelegramBot::sendPostPhoto(JsonObject payload) {
693694

694695
if (payload.containsKey("photo")) {
695696
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);
697698
#ifdef _debug
698699
Serial.println(response);
699700
#endif
@@ -776,7 +777,7 @@ bool UniversalTelegramBot::sendChatAction(String chat_id, String text) {
776777

777778
if (text != "") {
778779
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=");
780781
command += chat_id;
781782
command += F("&action=");
782783
command += text;
@@ -808,7 +809,7 @@ void UniversalTelegramBot::closeClient() {
808809

809810
bool UniversalTelegramBot::getFile(String *file_path, long *file_size, String file_id)
810811
{
811-
String command = buildCommand(F("getFile?file_id="));
812+
String command = BOT_CMD("getFile?file_id=");
812813
command += file_id;
813814
String response = sendGetToTelegram(command); // receive reply from telegram.org
814815
DynamicJsonDocument doc(maxMessageLength);

0 commit comments

Comments
 (0)