Skip to content

Commit 63166ee

Browse files
committed
Tidying up branch
1 parent 444d813 commit 63166ee

File tree

19 files changed

+781
-2
lines changed

19 files changed

+781
-2
lines changed

.travis.yml

Lines changed: 12 additions & 1 deletion
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
@@ -20,7 +21,17 @@ env:
2021
- SCRIPT=platformioSingle EXAMPLE_NAME=PhotoFromFileID EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP8266 BOARD=d1_mini
2122
- SCRIPT=platformioSingle EXAMPLE_NAME=Location EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
2223
- SCRIPT=platformioSingle EXAMPLE_NAME=ChannelPost EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
23-
- SCRIPT=platformio PLATFORMIO_CI_SRC=src EXAMPLE_NAME=AdvancedLED_platformio EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=esp32dev
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=/ BOARDTYPE=ESP32 BOARD=esp32dev
29+
- SCRIPT=platformioSingle EXAMPLE_NAME=InlineKeyboardMarkup EXAMPLE_FOLDER=/ 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
2435

2536

2637
install:
Lines changed: 66 additions & 0 deletions
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+
}
Lines changed: 99 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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]([email protected]) 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.
Lines changed: 93 additions & 0 deletions
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+
}
Lines changed: 28 additions & 0 deletions
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)