Skip to content

Commit 25c0c29

Browse files
committed
Changes for new RC
1 parent f8837fa commit 25c0c29

File tree

9 files changed

+350
-78
lines changed

9 files changed

+350
-78
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ env:
1818
- SCRIPT=platformioSingle EXAMPLE_NAME=PhotoFromSD EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP8266 BOARD=d1_mini
1919
- SCRIPT=platformioSingle EXAMPLE_NAME=PhotoFromURL EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP8266 BOARD=d1_mini
2020
- SCRIPT=platformioSingle EXAMPLE_NAME=PhotoFromFileID EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP8266 BOARD=d1_mini
21+
- SCRIPT=platformioSingle EXAMPLE_NAME=Location EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
22+
- SCRIPT=platformioSingle EXAMPLE_NAME=ChannelPost EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
2123

2224

2325
install:

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,13 @@ 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+
|*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)|
62+
|*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)|
5963

6064
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.
6165

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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 <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+
void setup() {
25+
Serial.begin(115200);
26+
27+
// Set WiFi to station mode and disconnect from an AP if it was Previously
28+
// connected
29+
WiFi.mode(WIFI_STA);
30+
WiFi.disconnect();
31+
delay(100);
32+
33+
// Attempt to connect to Wifi network:
34+
Serial.print("Connecting Wifi: ");
35+
Serial.println(ssid);
36+
WiFi.begin(ssid, password);
37+
38+
while (WiFi.status() != WL_CONNECTED) {
39+
Serial.print(".");
40+
delay(500);
41+
}
42+
43+
Serial.println("");
44+
Serial.println("WiFi connected");
45+
Serial.print("IP address: ");
46+
Serial.println(WiFi.localIP());
47+
}
48+
49+
void loop() {
50+
if (millis() > Bot_lasttime + Bot_mtbs) {
51+
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
52+
53+
while(numNewMessages) {
54+
Serial.println("got response");
55+
for (int i=0; i<numNewMessages; i++) {
56+
if(bot.messages[i].type == "channel_post") {
57+
bot.sendMessage(bot.messages[i].chat_id, bot.messages[i].chat_title + " " + bot.messages[i].text, "");
58+
} else {
59+
bot.sendMessage(bot.messages[i].chat_id, bot.messages[i].text, "");
60+
}
61+
}
62+
63+
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
64+
}
65+
66+
Bot_lasttime = millis();
67+
}
68+
}

examples/ESP8266/CustomKeyboard/InlineKeyboardMarkup/InlineKeyboardMarkup.ino

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*******************************************************************
2-
* An example of how to use a custom reply keyboard markup. *
3-
* *
4-
* *
5-
* written by Vadim Sinitski *
2+
An example of how to use a custom reply keyboard markup.
3+
4+
5+
written by Vadim Sinitski (modified by Brian Lough)
66
*******************************************************************/
77
#include <ESP8266WiFi.h>
88
#include <WiFiClientSecure.h>
@@ -22,27 +22,35 @@ int Bot_mtbs = 1000; //mean time between scan messages
2222
long Bot_lasttime; //last time messages' scan has been done
2323

2424
void handleNewMessages(int numNewMessages) {
25-
Serial.println("handleNewMessages");
26-
Serial.println(String(numNewMessages));
27-
28-
for (int i=0; i<numNewMessages; i++) {
29-
String chat_id = String(bot.messages[i].chat_id);
30-
String text = bot.messages[i].text;
31-
32-
String from_name = bot.messages[i].from_name;
33-
if (from_name == "") from_name = "Guest";
34-
35-
if (text == "/options") {
36-
String keyboardJson = "[[\{ \"text\" : \"Go to Google\", \"url\" : \"https://www.google.com\" \} ]]";
37-
bot.sendMessageWithInlineKeyboard(chat_id, "Choose from one of the following options", "", keyboardJson);
38-
}
39-
40-
if (text == "/start") {
41-
String welcome = "Welcome to Universal Arduino Telegram Bot library, " + from_name + ".\n";
42-
welcome += "This is Inline Keyboard Markup example.\n\n";
43-
welcome += "/options : returns the inline keyboard\n";
4425

45-
bot.sendMessage(chat_id, welcome, "Markdown");
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+
}
4654
}
4755
}
4856
}
@@ -75,7 +83,7 @@ void loop() {
7583
if (millis() > Bot_lasttime + Bot_mtbs) {
7684
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
7785

78-
while(numNewMessages) {
86+
while (numNewMessages) {
7987
Serial.println("got response");
8088
handleNewMessages(numNewMessages);
8189
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*******************************************************************
2+
* An example of recieving location Data
3+
*
4+
*
5+
* By Brian Lough
6+
*******************************************************************/
7+
#include <ESP8266WiFi.h>
8+
#include <WiFiClientSecure.h>
9+
#include <UniversalTelegramBot.h>
10+
11+
// Initialize Wifi connection to the router
12+
char ssid[] = "SSID"; // your network SSID (name)
13+
char password[] = "password"; // 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+
String chat_id = String(bot.messages[i].chat_id);
29+
String text = bot.messages[i].text;
30+
31+
String from_name = bot.messages[i].from_name;
32+
if (from_name == "") from_name = "Guest";
33+
34+
if (bot.messages[i].longitude != 0 || bot.messages[i].latitude != 0) {
35+
Serial.print("Long: ");
36+
Serial.println(String(bot.messages[i].longitude, 6));
37+
Serial.print("Lat: ");
38+
Serial.println(String(bot.messages[i].latitude, 6));
39+
40+
String message = "Long: " + String(bot.messages[i].longitude, 6) + "\n";
41+
message += "Lat: " + String(bot.messages[i].latitude, 6) + "\n";
42+
bot.sendMessage(chat_id, message, "Markdown");
43+
} else if (text == "/start") {
44+
String welcome = "Welcome to Universal Arduino Telegram Bot library, " + from_name + ".\n";
45+
welcome += "Share a location or a live location and the bot will respond with the co-ords\n";
46+
47+
bot.sendMessage(chat_id, welcome, "Markdown");
48+
}
49+
}
50+
}
51+
52+
void setup() {
53+
Serial.begin(115200);
54+
55+
// Set WiFi to station mode and disconnect from an AP if it was Previously connected
56+
WiFi.mode(WIFI_STA);
57+
WiFi.disconnect();
58+
delay(100);
59+
60+
// attempt to connect to Wifi network:
61+
Serial.print("Connecting Wifi: ");
62+
Serial.println(ssid);
63+
WiFi.begin(ssid, password);
64+
65+
while (WiFi.status() != WL_CONNECTED) {
66+
Serial.print(".");
67+
delay(500);
68+
}
69+
70+
Serial.println("");
71+
Serial.println("WiFi connected");
72+
Serial.print("IP address: ");
73+
Serial.println(WiFi.localIP());
74+
}
75+
76+
void loop() {
77+
if (millis() > Bot_lasttime + Bot_mtbs) {
78+
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
79+
80+
while (numNewMessages) {
81+
Serial.println("got response");
82+
handleNewMessages(numNewMessages);
83+
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
84+
}
85+
86+
Bot_lasttime = millis();
87+
}
88+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*******************************************************************
2+
* An example of setting a long poll, this will mean the request
3+
* for new messages will wait the specified amount of time before
4+
* returning with no messages
5+
*
6+
* This should reduce amount of data used by the bot
7+
*
8+
* written by Brian Lough
9+
*******************************************************************/
10+
#include <ESP8266WiFi.h>
11+
#include <WiFiClientSecure.h>
12+
#include <UniversalTelegramBot.h>
13+
14+
// Initialize Wifi connection to the router
15+
char ssid[] = "XXXXXX"; // your network SSID (name)
16+
char password[] = "YYYYYY"; // your network key
17+
18+
// Initialize Telegram BOT
19+
#define BOTtoken "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // your Bot Token (Get from Botfather)
20+
21+
WiFiClientSecure client;
22+
UniversalTelegramBot bot(BOTtoken, client);
23+
24+
int Bot_mtbs = 1000; //mean time between scan messages
25+
long Bot_lasttime; //last time messages' scan has been done
26+
27+
void setup() {
28+
Serial.begin(115200);
29+
30+
// Set WiFi to station mode and disconnect from an AP if it was Previously
31+
// connected
32+
WiFi.mode(WIFI_STA);
33+
WiFi.disconnect();
34+
delay(100);
35+
36+
// Attempt to connect to Wifi network:
37+
Serial.print("Connecting Wifi: ");
38+
Serial.println(ssid);
39+
WiFi.begin(ssid, password);
40+
41+
while (WiFi.status() != WL_CONNECTED) {
42+
Serial.print(".");
43+
delay(500);
44+
}
45+
46+
bot.longPoll = 60;
47+
48+
Serial.println("");
49+
Serial.println("WiFi connected");
50+
Serial.print("IP address: ");
51+
Serial.println(WiFi.localIP());
52+
}
53+
54+
void loop() {
55+
if (millis() > Bot_lasttime + Bot_mtbs) {
56+
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
57+
58+
while(numNewMessages) {
59+
Serial.println("got response");
60+
for (int i=0; i<numNewMessages; i++) {
61+
bot.sendMessage(bot.messages[i].chat_id, bot.messages[i].text, "");
62+
}
63+
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
64+
}
65+
Serial.println("I will happen much less often with a long poll");
66+
Bot_lasttime = millis();
67+
}
68+
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=UniversalTelegramBot
2-
version=1.0.0
2+
version=1.1.0
33
author=Brian Lough
44
maintainer=Brian Lough <[email protected]>
55
sentence=Arduino Telegram Bot library for multiple different architectures.

0 commit comments

Comments
 (0)