Skip to content

Commit e3a0089

Browse files
committed
Sending images now return file_id, image has been replaced by photo as thats what telegram uses
1 parent fea4d09 commit e3a0089

File tree

8 files changed

+214
-69
lines changed

8 files changed

+214
-69
lines changed

.travis.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@ cache:
99
- "~/.platformio"
1010

1111
env:
12-
- SCRIPT=platformioSingle EXAMPLE_FOLDER=EchoBot EXAMPLE_FILE=EchoBot BOARDTYPE=ESP8266 BOARD=d1_mini
13-
- SCRIPT=platformioSingle EXAMPLE_FOLDER=CustomKeyboard/ReplyKeyboardMarkup EXAMPLE_FILE=ReplyKeyboardMarkup BOARDTYPE=ESP8266 BOARD=d1_mini
14-
- SCRIPT=platformioSingle EXAMPLE_FOLDER=CustomKeyboard/InlineKeyboardMarkup EXAMPLE_FILE=InlineKeyboardMarkup BOARDTYPE=ESP8266 BOARD=d1_mini
15-
- SCRIPT=platformioSingle EXAMPLE_FOLDER=FlashledBot EXAMPLE_FILE=FlashledBot BOARDTYPE=ESP8266 BOARD=d1_mini
16-
- SCRIPT=platformioSingle EXAMPLE_FOLDER=UsingWiFiManager EXAMPLE_FILE=UsingWiFiManager BOARDTYPE=ESP8266 BOARD=d1_mini
17-
- SCRIPT=platformioSingle EXAMPLE_FOLDER=BulkMessages EXAMPLE_FILE=BulkMessages BOARDTYPE=ESP8266 BOARD=d1_mini
18-
- SCRIPT=platformioSingle EXAMPLE_FOLDER=SendPhoto/ImageFromSD EXAMPLE_FILE=ImageFromSD BOARDTYPE=ESP8266 BOARD=d1_mini
19-
- SCRIPT=platformioSingle EXAMPLE_FOLDER=SendPhoto/ImageFromURL EXAMPLE_FILE=ImageFromURL BOARDTYPE=ESP8266 BOARD=d1_mini
12+
- SCRIPT=platformioSingle EXAMPLE_NAME=EchoBot BOARDTYPE=ESP8266 BOARD=d1_mini
13+
- SCRIPT=platformioSingle EXAMPLE_NAME=ReplyKeyboardMarkup EXAMPLE_FOLDER=CustomKeyboard/ BOARDTYPE=ESP8266 BOARD=d1_mini
14+
- SCRIPT=platformioSingle EXAMPLE_NAME=InlineKeyboardMarkup EXAMPLE_FOLDER=CustomKeyboard/ BOARDTYPE=ESP8266 BOARD=d1_mini
15+
- SCRIPT=platformioSingle EXAMPLE_NAME=FlashledBot BOARDTYPE=ESP8266 BOARD=d1_mini
16+
- SCRIPT=platformioSingle EXAMPLE_NAME=UsingWiFiManager BOARDTYPE=ESP8266 BOARD=d1_mini
17+
- SCRIPT=platformioSingle EXAMPLE_NAME=BulkMessages BOARDTYPE=ESP8266 BOARD=d1_mini
18+
- SCRIPT=platformioSingle EXAMPLE_NAME=ImageFromSD EXAMPLE_FOLDER=SendPhoto/ EXAMPLE_NAME=ImageFromSD BOARDTYPE=ESP8266 BOARD=d1_mini
19+
- SCRIPT=platformioSingle EXAMPLE_NAME=ImageFromURL EXAMPLE_FOLDER=SendPhoto/ BOARDTYPE=ESP8266 BOARD=d1_mini
20+
- SCRIPT=platformioSingle EXAMPLE_NAME=ImageFromURL EXAMPLE_FOLDER=SendPhoto/ BOARDTYPE=ESP8266 BOARD=d1_mini
2021

21-
# This will run all the ESP8266 examples
22-
#- SCRIPT=platformioEsp8266 BOARD=d1_mini
2322

2423
install:
2524
- pip install -U platformio
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*******************************************************************
2+
* An example of how to use a custom reply keyboard markup. *
3+
* *
4+
* *
5+
* written by Vadim Sinitski *
6+
*******************************************************************/
7+
#include <ESP8266WiFi.h>
8+
#include <WiFiClientSecure.h>
9+
#include <UniversalTelegramBot.h>
10+
11+
// Initialize Wifi connection to the router
12+
char ssid[] = "XXXXXX"; // your network SSID (name)
13+
char password[] = "YYYYYY"; // your network key
14+
15+
// Initialize Telegram BOT
16+
#define BOTtoken "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // your Bot Token (Get from Botfather)
17+
18+
WiFiClientSecure client;
19+
UniversalTelegramBot bot(BOTtoken, client);
20+
21+
int Bot_mtbs = 1000; //mean time between scan messages
22+
long Bot_lasttime; //last time messages' scan has been done
23+
24+
String test_photo_url = "https://www.arduino.cc/en/uploads/Trademark/ArduinoCommunityLogo.png";
25+
26+
void handleNewMessages(int numNewMessages) {
27+
Serial.println("handleNewMessages");
28+
Serial.println(String(numNewMessages));
29+
30+
for (int i=0; i<numNewMessages; i++) {
31+
String chat_id = String(bot.messages[i].chat_id);
32+
String text = bot.messages[i].text;
33+
34+
String from_name = bot.messages[i].from_name;
35+
if (from_name == "") from_name = "Guest";
36+
37+
if (text == "/get_test_photo") {
38+
String file_id = bot.sendPhoto(chat_id, test_photo_url, "This photo was sent using URL");
39+
bot.sendPhoto(chat_id, file_id, "This photo was sent using File ID");
40+
}
41+
42+
if (text == "/start") {
43+
String welcome = "Welcome to Universal Arduino Telegram Bot library, " + from_name + ".\n";
44+
welcome += "This is Send Photo From File Id example.\n\n";
45+
welcome += "/get_test_photo : getting test photo\n";
46+
//welcome += "You will receive photo from " + test_photo_url + "\n";
47+
48+
bot.sendMessage(chat_id, welcome, "");
49+
}
50+
}
51+
}
52+
53+
void setup() {
54+
Serial.begin(115200);
55+
56+
// Set WiFi to station mode and disconnect from an AP if it was Previously connected
57+
WiFi.mode(WIFI_STA);
58+
WiFi.disconnect();
59+
delay(100);
60+
61+
// attempt to connect to Wifi network:
62+
Serial.print("Connecting Wifi: ");
63+
Serial.println(ssid);
64+
WiFi.begin(ssid, password);
65+
66+
while (WiFi.status() != WL_CONNECTED) {
67+
Serial.print(".");
68+
delay(500);
69+
}
70+
71+
Serial.println("");
72+
Serial.println("WiFi connected");
73+
Serial.print("IP address: ");
74+
Serial.println(WiFi.localIP());
75+
}
76+
77+
void loop() {
78+
if (millis() > Bot_lasttime + Bot_mtbs) {
79+
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
80+
81+
while(numNewMessages) {
82+
Serial.println("got response");
83+
handleNewMessages(numNewMessages);
84+
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
85+
}
86+
87+
Bot_lasttime = millis();
88+
}
89+
}

examples/ESP8266/SendPhoto/ImageFromSD/ImageFromSD.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,20 @@ void loop() {
9191
Serial.println("box.jpg:");
9292

9393
//Content type for PNG image/png
94-
bool sent = bot.sendImage(chat_id, "image/jpeg", myFile.size(),
94+
bool sent = bot.sendPhotoByBinary(chat_id, "image/jpeg", myFile.size(),
9595
isMoreDataAvailable,
9696
getNextByte);
9797

9898
if(sent){
99-
Serial.println("Succesfully sent image");
99+
Serial.println("Succesfully sent photo");
100100
} else {
101-
Serial.println("Error sending image");
101+
Serial.println("Error sending photo");
102102
}
103103

104104
myFile.close();
105105
} else {
106106
// if the file didn't open, print an error:
107-
Serial.println("error opening image.jpg");
107+
Serial.println("error opening photo.jpg");
108108
}
109109
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
110110
}

examples/ESP8266/SendPhoto/ImageFromURL/ImageFromURL.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ UniversalTelegramBot bot(BOTtoken, client);
2121
int Bot_mtbs = 1000; //mean time between scan messages
2222
long Bot_lasttime; //last time messages' scan has been done
2323

24-
String test_image_url = "https://www.arduino.cc/en/uploads/Trademark/ArduinoCommunityLogo.png";
24+
String test_photo_url = "https://www.arduino.cc/en/uploads/Trademark/ArduinoCommunityLogo.png";
2525

2626
void handleNewMessages(int numNewMessages) {
2727
Serial.println("handleNewMessages");
@@ -34,15 +34,15 @@ void handleNewMessages(int numNewMessages) {
3434
String from_name = bot.messages[i].from_name;
3535
if (from_name == "") from_name = "Guest";
3636

37-
if (text == "/get_test_image") {
38-
bot.sendImageAsURL(chat_id, test_image_url, "Caption is optional, you may not use image caption");
37+
if (text == "/get_test_photo") {
38+
bot.sendPhoto(chat_id, test_photo_url, "Caption is optional, you may not use photo caption");
3939
}
4040

4141
if (text == "/start") {
4242
String welcome = "Welcome to Universal Arduino Telegram Bot library, " + from_name + ".\n";
4343
welcome += "This is Send Image From URL example.\n\n";
44-
welcome += "/get_test_image : getting test image\n";
45-
//welcome += "You will receive image from " + test_image_url + "\n";
44+
welcome += "/get_test_photo : getting test photo\n";
45+
//welcome += "You will receive photo from " + test_photo_url + "\n";
4646

4747
bot.sendMessage(chat_id, welcome, "");
4848
}

scripts/travis/platformioEsp8266.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

scripts/travis/platformioSingle.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/sh -eux
22

3-
platformio ci $PWD/examples/$BOARDTYPE/$EXAMPLE_FOLDER/$EXAMPLE_FILE.ino -l '.' -b $BOARD
3+
platformio ci $PWD/examples/$BOARDTYPE/$EXAMPLE_FOLDER$EXAMPLE_FILE/$EXAMPLE_FILE.ino -l '.' -b $BOARD

0 commit comments

Comments
 (0)