Skip to content

Commit a659ac3

Browse files
committed
Changed code that get photo from array
1 parent 7f5a9ee commit a659ac3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

examples/ESP8266/SendPhoto/PhotoFromFileID/PhotoFromFileID.ino

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ void handleNewMessages(int numNewMessages) {
4343

4444
// There are 3 image sizes after Telegram has process photo
4545
// You may choose what you want, in example was choosed bigger size
46-
String file_id = images["result"]["photo"][2]["file_id"];
46+
int photosArrayLength = images["result"]["photo"].size();
4747

48-
if (file_id) {
49-
bot.sendPhoto(chat_id, file_id, "This photo was sent using File ID");
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");
53+
}
5054
}
5155
}
5256

0 commit comments

Comments
 (0)