Skip to content

Commit b4ebcae

Browse files
authored
Merge pull request witnessmenow#55 from witnessmenow/V1.1.0
V1.1.0
2 parents 3f101b3 + 70a393e commit b4ebcae

File tree

29 files changed

+1827
-291
lines changed

29 files changed

+1827
-291
lines changed

.travis.yml

+14
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ cache:
99
- "~/.platformio"
1010

1111
env:
12+
# ESP8266
1213
- SCRIPT=platformioSingle EXAMPLE_NAME=EchoBot EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
1314
- SCRIPT=platformioSingle EXAMPLE_NAME=ReplyKeyboardMarkup EXAMPLE_FOLDER=/CustomKeyboard/ BOARDTYPE=ESP8266 BOARD=d1_mini
1415
- SCRIPT=platformioSingle EXAMPLE_NAME=InlineKeyboardMarkup EXAMPLE_FOLDER=/CustomKeyboard/ BOARDTYPE=ESP8266 BOARD=d1_mini
@@ -18,6 +19,19 @@ env:
1819
- SCRIPT=platformioSingle EXAMPLE_NAME=PhotoFromSD EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP8266 BOARD=d1_mini
1920
- SCRIPT=platformioSingle EXAMPLE_NAME=PhotoFromURL EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP8266 BOARD=d1_mini
2021
- SCRIPT=platformioSingle EXAMPLE_NAME=PhotoFromFileID EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP8266 BOARD=d1_mini
22+
- SCRIPT=platformioSingle EXAMPLE_NAME=Location EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
23+
- SCRIPT=platformioSingle EXAMPLE_NAME=ChannelPost EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
24+
- SCRIPT=platformioSingle EXAMPLE_NAME=ChatAction EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
25+
- SCRIPT=platformioSingle EXAMPLE_NAME=LongPoll EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
26+
# ESP32
27+
- SCRIPT=platformioSingle EXAMPLE_NAME=EchoBot EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=esp32dev
28+
- SCRIPT=platformioSingle EXAMPLE_NAME=ReplyKeyboardMarkup EXAMPLE_FOLDER=/CustomKeyboard/ BOARDTYPE=ESP32 BOARD=esp32dev
29+
- SCRIPT=platformioSingle EXAMPLE_NAME=InlineKeyboardMarkup EXAMPLE_FOLDER=/CustomKeyboard/ BOARDTYPE=ESP32 BOARD=esp32dev
30+
- SCRIPT=platformioSingle EXAMPLE_NAME=FlashLED EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=esp32dev
31+
- SCRIPT=platformioSingle EXAMPLE_NAME=Location EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=esp32dev
32+
- SCRIPT=platformioSingle EXAMPLE_NAME=ChannelPost EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=esp32dev
33+
- SCRIPT=platformioSingle EXAMPLE_NAME=ChatAction EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=esp32dev
34+
- SCRIPT=platformioSingle EXAMPLE_NAME=LongPoll EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=esp32dev
2135

2236

2337
install:

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ Here is a list of features that this library covers. (Note: The examples link to
5353
|*Receiving Messages*|Your bot can read messages that are sent to it. This is useful for sending commands to your arduino such as toggle and LED|`int getUpdates(long offset)` <br><br> Gets any pending messages from Telegram and stores them in **bot.messages** . Offset should be set to **bot.last_message_received** + 1. Returns the numbers new messages received.| [FlashLED](https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/blob/master/examples/ESP8266/FlashLED/FlashLED.ino) or any other example|
5454
|*Sending messages*|Your bot can send messages to any Telegram or group. This can be useful to get the arduino to notify you of an event e.g. Button pressed etc (Note: bots can only message you if you messaged them first)|`bool sendMessage(String chat_id, String text, String parse_mode = "")` <br><br> Sends the message to the chat_id. Returns if the message sent or not.| [EchoBot](https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/blob/master/examples/ESP8266/EchoBot/EchoBot.ino#L51) or any other example|
5555
|*Reply Keyboards*|Your bot can send [reply keyboards](https://camo.githubusercontent.com/2116a60fa614bf2348074a9d7148f7d0a7664d36/687474703a2f2f692e696d6775722e636f6d2f325268366c42672e6a70673f32) that can be used as a type of menu.|`bool sendMessageWithReplyKeyboard(String chat_id, String text, String parse_mode, String keyboard, bool resize = false, bool oneTime = false, bool selective = false)` <br><br> Send a keyboard to the specified chat_id. parse_mode can be left blank. Will return true if the message sends successfully.| [ReplyKeyboard](https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/blob/master/examples/ESP8266/CustomKeyboard/ReplyKeyboardMarkup/ReplyKeyboardMarkup.ino)|
56-
|*Inline Keyboards*|Your bot can send [inline keyboards](https://camo.githubusercontent.com/55dde972426e5bc77120ea17a9c06bff37856eb6/68747470733a2f2f636f72652e74656c656772616d2e6f72672f66696c652f3831313134303939392f312f324a536f55566c574b61302f346661643265323734336463386564613034). <br><br>Note: Only URLS are supported currently|`bool sendMessageWithInlineKeyboard(String chat_id, String text, String parse_mode, String keyboard)` <br><br> Send a keyboard to the specified chat_id. parse_mode can be left blank. Will return true if the message sends successfully.| [InlineKeyboard](https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/blob/master/examples/ESP8266/CustomKeyboard/InlineKeyboardMarkup/InlineKeyboardMarkup.ino)|
56+
|*Inline Keyboards*|Your bot can send [inline keyboards](https://camo.githubusercontent.com/55dde972426e5bc77120ea17a9c06bff37856eb6/68747470733a2f2f636f72652e74656c656772616d2e6f72672f66696c652f3831313134303939392f312f324a536f55566c574b61302f346661643265323734336463386564613034). <br><br>Note: URLS & callbacks are supported currently|`bool sendMessageWithInlineKeyboard(String chat_id, String text, String parse_mode, String keyboard)` <br><br> Send a keyboard to the specified chat_id. parse_mode can be left blank. Will return true if the message sends successfully.| [InlineKeyboard](https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/blob/master/examples/ESP8266/CustomKeyboard/InlineKeyboardMarkup/InlineKeyboardMarkup.ino)|
5757
|*Send Photos*|It is possible to send phtos from your bot. You can send images from the web or from the arduino directly (Only sending from an SD card has been tested, but it should be able to send from a camera module)|Check the examples for more info| [From URL](https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/blob/master/examples/ESP8266/SendPhoto/PhotoFromURL/PhotoFromURL.ino)<br><br>[Binary from SD](https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/blob/master/examples/ESP8266/SendPhoto/PhotoFromSD/PhotoFromSD.ino)<br><br>[From File Id](https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/blob/master/examples/ESP8266/SendPhoto/PhotoFromFileID/PhotoFromFileID.ino)|
58-
|*Chat Actions*|Your bot can send chat actions, such as *typing* or *sending photo* to let the user know that the bot is doing something. |`bool sendChatAction(String chat_id, String chat_action)` <br><br> Send a the chat action to the specified chat_id. There is a set list of chat actions that Telegram support, see the example for details. Will return true if the chat actions sends successfully.| [InlineKeyboard](https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/tree/master/examples/ESP8266/ChatAction)|
58+
|*Chat Actions*|Your bot can send chat actions, such as *typing* or *sending photo* to let the user know that the bot is doing something. |`bool sendChatAction(String chat_id, String chat_action)` <br><br> Send a the chat action to the specified chat_id. There is a set list of chat actions that Telegram support, see the example for details. Will return true if the chat actions sends successfully.|
59+
|*Location*|Your bot can receive location data, either from a single location data point or live location data. |Check the example.| [Location](https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/tree/master/examples/ESP8266/Location/Location.ino)|
60+
|*Channel Post*|Reads posts from channels. |Check the example.| [ChannelPost](https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/tree/master/examples/ESP8266/ChannelPost/ChannelPost.ino)|
61+
|*Long Poll*|Set how long the bot will wait checking for a new message before returning now messages. <br><br> This will decrease the amount of requests and data used by the bot, but it will tie up the arduino while it waits for messages |`bot.longPoll = 60;` <br><br> Where 60 is the amount of seconds it should wait | [LongPoll](https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/tree/master/examples/ESP8266/LongPoll/LongPoll.ino)|
5962

6063
The full Telegram Bot API documentation can be read [here](https://core.telegram.org/bots/api). If there is a feature you would like added to the library please either raise a Github issue or please feel free to raise a Pull Request.
6164

examples/101/FlashledBot/FlashledBot.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const int ledPin = 13;
2323
#define BOTtoken "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // your Bot Token (Get from Botfather)
2424

2525
WiFiSSLClient client;
26-
UniversalTelegramBot bot(BOTtoken, client);s
26+
UniversalTelegramBot bot(BOTtoken, client);
2727

2828
int Bot_mtbs = 1000; //mean time between scan messages
2929
long Bot_lasttime; //last time messages' scan has been done
+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*******************************************************************
2+
* An example of bot that echos back any messages received,
3+
* including ones from channels
4+
*
5+
* written by Brian Lough
6+
*******************************************************************/
7+
#include <WiFi.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+
void setup() {
25+
Serial.begin(115200);
26+
27+
// Attempt to connect to Wifi network:
28+
Serial.print("Connecting Wifi: ");
29+
Serial.println(ssid);
30+
31+
// Set WiFi to station mode and disconnect from an AP if it was Previously
32+
// connected
33+
WiFi.mode(WIFI_STA);
34+
WiFi.begin(ssid, password);
35+
36+
while (WiFi.status() != WL_CONNECTED) {
37+
Serial.print(".");
38+
delay(500);
39+
}
40+
41+
Serial.println("");
42+
Serial.println("WiFi connected");
43+
Serial.print("IP address: ");
44+
Serial.println(WiFi.localIP());
45+
}
46+
47+
void loop() {
48+
if (millis() > Bot_lasttime + Bot_mtbs) {
49+
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
50+
51+
while(numNewMessages) {
52+
Serial.println("got response");
53+
for (int i=0; i<numNewMessages; i++) {
54+
if(bot.messages[i].type == "channel_post") {
55+
bot.sendMessage(bot.messages[i].chat_id, bot.messages[i].chat_title + " " + bot.messages[i].text, "");
56+
} else {
57+
bot.sendMessage(bot.messages[i].chat_id, bot.messages[i].text, "");
58+
}
59+
}
60+
61+
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
62+
}
63+
64+
Bot_lasttime = millis();
65+
}
66+
}
+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*******************************************************************
2+
* An example of bot that show bot action message. *
3+
* *
4+
* *
5+
* *
6+
* written by Vadim Sinitski *
7+
*******************************************************************/
8+
#include <WiFi.h>
9+
#include <WiFiClientSecure.h>
10+
#include <UniversalTelegramBot.h>
11+
12+
// Initialize Wifi connection to the router
13+
char ssid[] = "XXXXXX"; // your network SSID (name)
14+
char password[] = "YYYYYY"; // your network key
15+
16+
// Initialize Telegram BOT
17+
#define BOTtoken "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // your Bot Token (Get from Botfather)
18+
19+
WiFiClientSecure client;
20+
UniversalTelegramBot bot(BOTtoken, client);
21+
22+
int Bot_mtbs = 1000; //mean time between scan messages
23+
long Bot_lasttime; //last time messages' scan has been done
24+
bool Start = false;
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 == "/send_test_action") {
38+
bot.sendChatAction(chat_id, "typing");
39+
delay(4000);
40+
bot.sendMessage(chat_id, "Did you see the action message?");
41+
42+
// You can't use own message, just choose from one of bellow
43+
44+
//typing for text messages
45+
//upload_photo for photos
46+
//record_video or upload_video for videos
47+
//record_audio or upload_audio for audio files
48+
//upload_document for general files
49+
//find_location for location data
50+
51+
//more info here - https://core.telegram.org/bots/api#sendchataction
52+
}
53+
54+
if (text == "/start") {
55+
String welcome = "Welcome to Universal Arduino Telegram Bot library, " + from_name + ".\n";
56+
welcome += "This is Chat Action Bot example.\n\n";
57+
welcome += "/send_test_action : to send test chat action message\n";
58+
bot.sendMessage(chat_id, welcome);
59+
}
60+
}
61+
}
62+
63+
64+
void setup() {
65+
Serial.begin(115200);
66+
67+
// Attempt to connect to Wifi network:
68+
Serial.print("Connecting Wifi: ");
69+
Serial.println(ssid);
70+
71+
// Set WiFi to station mode and disconnect from an AP if it was Previously
72+
// connected
73+
WiFi.mode(WIFI_STA);
74+
WiFi.begin(ssid, password);
75+
76+
while (WiFi.status() != WL_CONNECTED) {
77+
Serial.print(".");
78+
delay(500);
79+
}
80+
81+
Serial.println("");
82+
Serial.println("WiFi connected");
83+
Serial.print("IP address: ");
84+
Serial.println(WiFi.localIP());
85+
}
86+
87+
void loop() {
88+
if (millis() > Bot_lasttime + Bot_mtbs) {
89+
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
90+
91+
while(numNewMessages) {
92+
Serial.println("got response");
93+
handleNewMessages(numNewMessages);
94+
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
95+
}
96+
97+
Bot_lasttime = millis();
98+
}
99+
}

examples/ESP32/ChatAction/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ESP8266 - Chat Action
2+
3+
This is a basic example of how to use chat action using UniversalTelegramBot for ESP8266 based boards.
4+
5+
Application originally written by [Giancarlo Bacchio](giancarlo.bacchio@gmail.com) for [ESP8266-TelegramBot library](https://github.com/Gianbacchio/ESP8266-TelegramBot)
6+
7+
Adapted by [Brian Lough](https://github.com/witnessmenow)
8+
9+
NOTE: You will need to enter your SSID, password and bot Token for the example to work.
10+
11+
## License
12+
13+
You may copy, distribute and modify the software provided that modifications are described and licensed for free under [LGPL-3](http://www.gnu.org/licenses/lgpl-3.0.html). Derivatives works (including modifications or anything statically linked to the library) can only be redistributed under [LGPL-3](http://www.gnu.org/licenses/lgpl-3.0.html), but applications that use the library don't have to be.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*******************************************************************
2+
An example of how to use a custom reply keyboard markup.
3+
4+
5+
written by Vadim Sinitski (modified by Brian Lough)
6+
*******************************************************************/
7+
#include <WiFi.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+
void handleNewMessages(int numNewMessages) {
25+
26+
for (int i = 0; i < numNewMessages; i++) {
27+
28+
// Inline buttons with callbacks when pressed will raise a callback_query message
29+
if (bot.messages[i].type == "callback_query") {
30+
Serial.print("Call back button pressed by: ");
31+
Serial.println(bot.messages[i].from_id);
32+
Serial.print("Data on the button: ");
33+
Serial.println(bot.messages[i].text);
34+
bot.sendMessage(bot.messages[i].from_id, bot.messages[i].text, "");
35+
} else {
36+
String chat_id = String(bot.messages[i].chat_id);
37+
String text = bot.messages[i].text;
38+
39+
String from_name = bot.messages[i].from_name;
40+
if (from_name == "") from_name = "Guest";
41+
42+
if (text == "/options") {
43+
String keyboardJson = "[[{ \"text\" : \"Go to Google\", \"url\" : \"https://www.google.com\" }],[{ \"text\" : \"Send\", \"callback_data\" : \"This was sent by inline\" }]]";
44+
bot.sendMessageWithInlineKeyboard(chat_id, "Choose from one of the following options", "", keyboardJson);
45+
}
46+
47+
if (text == "/start") {
48+
String welcome = "Welcome to Universal Arduino Telegram Bot library, " + from_name + ".\n";
49+
welcome += "This is Inline Keyboard Markup example.\n\n";
50+
welcome += "/options : returns the inline keyboard\n";
51+
52+
bot.sendMessage(chat_id, welcome, "Markdown");
53+
}
54+
}
55+
}
56+
}
57+
58+
void setup() {
59+
Serial.begin(115200);
60+
61+
// Attempt to connect to Wifi network:
62+
Serial.print("Connecting Wifi: ");
63+
Serial.println(ssid);
64+
65+
// Set WiFi to station mode and disconnect from an AP if it was Previously
66+
// connected
67+
WiFi.mode(WIFI_STA);
68+
WiFi.begin(ssid, password);
69+
70+
while (WiFi.status() != WL_CONNECTED) {
71+
Serial.print(".");
72+
delay(500);
73+
}
74+
75+
Serial.println("");
76+
Serial.println("WiFi connected");
77+
Serial.print("IP address: ");
78+
Serial.println(WiFi.localIP());
79+
}
80+
81+
void loop() {
82+
if (millis() > Bot_lasttime + Bot_mtbs) {
83+
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
84+
85+
while (numNewMessages) {
86+
Serial.println("got response");
87+
handleNewMessages(numNewMessages);
88+
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
89+
}
90+
91+
Bot_lasttime = millis();
92+
}
93+
}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#Reply Keyboard Markup
2+
3+
This is an example of how to use reply keyboard markup on a ESP8266 based board.
4+
5+
![alt text](https://core.telegram.org/file/811140184/1/5YJxx-rostA/ad3f74094485fb97bd "Reply Keyboard example")
6+
7+
The application will turn on and off an LED based on commands received via telegram.
8+
9+
#Inline Keyboard Markup
10+
11+
This is an example of how to use reply keyboard markup on a ESP8266 based board.
12+
13+
14+
![alt text](https://core.telegram.org/file/811140999/1/2JSoUVlWKa0/4fad2e2743dc8eda04 "Inline Keyboard example")
15+
16+
Right now working only URL redirection button. Other features will be added later.
17+
18+
-----------------
19+
20+
NOTE: You will need to enter your SSID, password and bot Token for the example to work.
21+
22+
Application written by [Brian Lough](https://github.com/witnessmenow)
23+
24+
25+
26+
## License
27+
28+
You may copy, distribute and modify the software provided that modifications are described and licensed for free under [LGPL-3](http://www.gnu.org/licenses/lgpl-3.0.html). Derivatives works (including modifications or anything statically linked to the library) can only be redistributed under [LGPL-3](http://www.gnu.org/licenses/lgpl-3.0.html), but applications that use the library don't have to be.

0 commit comments

Comments
 (0)