Skip to content

Commit 480320b

Browse files
committed
Moved checkForOk response to public functions
1 parent a659ac3 commit 480320b

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

examples/ESP8266/SendPhoto/PhotoFromFileID/PhotoFromFileID.ino

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,26 @@ void handleNewMessages(int numNewMessages) {
3838
if (text == "/get_test_photo") {
3939
String response = bot.sendPhoto(chat_id, test_photo_url, "This photo was sent using URL");
4040

41-
DynamicJsonBuffer jsonBuffer;
42-
JsonObject& images = jsonBuffer.parseObject(response);
43-
44-
// There are 3 image sizes after Telegram has process photo
45-
// You may choose what you want, in example was choosed bigger size
46-
int photosArrayLength = images["result"]["photo"].size();
47-
48-
if (photosArrayLength > 0) {
49-
String file_id = images["result"]["photo"][photosArrayLength-1]["file_id"];
50-
51-
if (file_id) {
52-
bot.sendPhoto(chat_id, file_id, "This photo was sent using File ID");
41+
if (bot.checkForOkResponse(response)) {
42+
DynamicJsonBuffer jsonBuffer;
43+
JsonObject& images = jsonBuffer.parseObject(response);
44+
45+
// There are 3 image sizes after Telegram has process photo
46+
// You may choose what you want, in example was choosed bigger size
47+
int photosArrayLength = images["result"]["photo"].size();
48+
49+
if (photosArrayLength > 0) {
50+
String file_id = images["result"]["photo"][photosArrayLength-1]["file_id"];
51+
52+
if (file_id) {
53+
String send_photo_by_file_id_response = bot.sendPhoto(chat_id, file_id, "This photo was sent using File ID");
54+
55+
if (bot.checkForOkResponse(send_photo_by_file_id_response)) {
56+
// do something
57+
} else {
58+
// or not to do
59+
}
60+
}
5361
}
5462
}
5563
}

src/UniversalTelegramBot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class UniversalTelegramBot
7474
bool disable_notification = false, int reply_to_message_id = 0, String keyboard = "");
7575

7676
int getUpdates(long offset);
77+
bool checkForOkResponse(String response);
7778
telegramMessage messages[HANDLE_MESSAGES];
7879
long last_message_received;
7980
String name;
@@ -84,7 +85,6 @@ class UniversalTelegramBot
8485
String _token;
8586
Client *client;
8687
const int maxMessageLength = 1300;
87-
bool checkForOkResponse(String response);
8888
bool _debug = false;
8989
};
9090

0 commit comments

Comments
 (0)