@@ -38,18 +38,26 @@ void handleNewMessages(int numNewMessages) {
38
38
if (text == " /get_test_photo" ) {
39
39
String response = bot.sendPhoto (chat_id, test_photo_url, " This photo was sent using URL" );
40
40
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
+ }
53
61
}
54
62
}
55
63
}
0 commit comments