Skip to content

Commit a27ef38

Browse files
authored
Merge pull request #201 from Bolukan/examples
Examples
2 parents 8e39adf + 92fa5f4 commit a27ef38

File tree

71 files changed

+3625
-2885
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+3625
-2885
lines changed

.travis.yml

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: python
22
python:
3-
- "2.7"
3+
- "3.7"
44

55
# Cache PlatformIO packages using Travis CI container-based infrastructure
66
sudo: false
@@ -10,40 +10,48 @@ cache:
1010

1111
env:
1212
# ESP8266
13+
- SCRIPT=platformioSingle EXAMPLE_NAME=BulkMessages EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
14+
- SCRIPT=platformioSingle EXAMPLE_NAME=ChannelPost EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
15+
- SCRIPT=platformioSingle EXAMPLE_NAME=ChatAction EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
16+
- SCRIPT=platformioSingle EXAMPLE_NAME=InlineKeyboardMarkup EXAMPLE_FOLDER=/CustomKeyboard/ BOARDTYPE=ESP8266 BOARD=d1_mini
17+
- SCRIPT=platformioSingle EXAMPLE_NAME=ReplyKeyboardMarkup EXAMPLE_FOLDER=/CustomKeyboard/ BOARDTYPE=ESP8266 BOARD=d1_mini
1318
- SCRIPT=platformioSingle EXAMPLE_NAME=EchoBot EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
14-
#- SCRIPT=platformioSingle EXAMPLE_NAME=ReplyKeyboardMarkup EXAMPLE_FOLDER=/CustomKeyboard/ BOARDTYPE=ESP8266 BOARD=d1_mini
15-
#- SCRIPT=platformioSingle EXAMPLE_NAME=InlineKeyboardMarkup EXAMPLE_FOLDER=/CustomKeyboard/ BOARDTYPE=ESP8266 BOARD=d1_mini
1619
- SCRIPT=platformioSingle EXAMPLE_NAME=FlashLED EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
20+
- SCRIPT=platformioSingle EXAMPLE_NAME=Location EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
21+
- SCRIPT=platformioSingle EXAMPLE_NAME=LongPoll EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
22+
- SCRIPT=platformioSingle EXAMPLE_NAME=PhotoFromFileID EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP8266 BOARD=d1_mini
23+
- SCRIPT=platformioSingle EXAMPLE_NAME=PhotoFromSD EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP8266 BOARD=d1_mini
24+
- SCRIPT=platformioSingle EXAMPLE_NAME=PhotoFromSerial EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP8266 BOARD=d1_mini
25+
- SCRIPT=platformioSingle EXAMPLE_NAME=PhotoFromURL EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP8266 BOARD=d1_mini
26+
- SCRIPT=platformioSingle EXAMPLE_NAME=SetMyCommands EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
1727
#- SCRIPT=platformioSingle EXAMPLE_NAME=UsingWiFiManager EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
18-
#- SCRIPT=platformioSingle EXAMPLE_NAME=BulkMessages EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
19-
#- SCRIPT=platformioSingle EXAMPLE_NAME=PhotoFromSD EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP8266 BOARD=d1_mini
20-
#- SCRIPT=platformioSingle EXAMPLE_NAME=PhotoFromURL EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP8266 BOARD=d1_mini
21-
#- 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-
- SCRIPT=platformioSingle EXAMPLE_NAME=SetMyCommand EXAMPLE_FOLDER=/ BOARDTYPE=ESP8266 BOARD=d1_mini
2728

2829
# ESP32
30+
- SCRIPT=platformioSingle EXAMPLE_NAME=ChannelPost EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=esp32dev
31+
- SCRIPT=platformioSingle EXAMPLE_NAME=ChatAction EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=esp32dev
32+
- SCRIPT=platformioSingle EXAMPLE_NAME=InlineKeyboardMarkup EXAMPLE_FOLDER=/CustomKeyboard/ BOARDTYPE=ESP32 BOARD=esp32dev
33+
- SCRIPT=platformioSingle EXAMPLE_NAME=ReplyKeyboardMarkup EXAMPLE_FOLDER=/CustomKeyboard/ BOARDTYPE=ESP32 BOARD=esp32doit-devkit-v1
2934
- SCRIPT=platformioSingle EXAMPLE_NAME=EchoBot EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=esp32dev
35+
- SCRIPT=platformioSingle EXAMPLE_NAME=FlashLED EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=esp32doit-devkit-v1
36+
- SCRIPT=platformioSingle EXAMPLE_NAME=Location EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=esp32dev
37+
- SCRIPT=platformioSingle EXAMPLE_NAME=LongPoll EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=esp32dev
3038
- SCRIPT=platformioSingle EXAMPLE_NAME=SendMessageFromEvent EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=esp32dev
31-
#- SCRIPT=platformioSingle EXAMPLE_NAME=ReplyKeyboardMarkup EXAMPLE_FOLDER=/CustomKeyboard/ BOARDTYPE=ESP32 BOARD=esp32dev
32-
#- SCRIPT=platformioSingle EXAMPLE_NAME=InlineKeyboardMarkup EXAMPLE_FOLDER=/CustomKeyboard/ BOARDTYPE=ESP32 BOARD=esp32dev
33-
#- SCRIPT=platformioSingle EXAMPLE_NAME=FlashLED EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=esp32dev
34-
#- SCRIPT=platformioSingle EXAMPLE_NAME=Location EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=esp32dev
35-
#- SCRIPT=platformioSingle EXAMPLE_NAME=ChannelPost EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=esp32dev
36-
#- SCRIPT=platformioSingle EXAMPLE_NAME=ChatAction EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=esp32dev
37-
#- SCRIPT=platformioSingle EXAMPLE_NAME=LongPoll EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=esp32dev
38-
39+
#- SCRIPT=platformioSingle EXAMPLE_NAME=ESP32-Cam EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP32 BOARD=esp32dev
40+
- SCRIPT=platformioSingle EXAMPLE_NAME=PhotoFromFileID EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP32 BOARD=esp32dev
41+
- SCRIPT=platformioSingle EXAMPLE_NAME=PhotoFromSD EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP32 BOARD=esp32dev
42+
- SCRIPT=platformioSingle EXAMPLE_NAME=PhotoFromSerial EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP32 BOARD=esp32dev
43+
- SCRIPT=platformioSingle EXAMPLE_NAME=PhotoFromURL EXAMPLE_FOLDER=/SendPhoto/ BOARDTYPE=ESP32 BOARD=esp32dev
44+
- SCRIPT=platformioSingle EXAMPLE_NAME=SetMyCommands EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=esp32dev
45+
#- SCRIPT=platformioSingle EXAMPLE_NAME=telegramOTA EXAMPLE_FOLDER=/ BOARDTYPE=ESP32 BOARD=esp32dev
3946

4047
install:
4148
- pip install -U platformio
49+
- platformio update
4250
#
4351
# Libraries from PlatformIO Library Registry:
4452
#
4553
# http://platformio.org/lib/show/64/ArduinoJson
4654
- platformio lib -g install 64
47-
# http://platformio.org/lib/show/567/WifiManager
48-
- platformio lib -g install 567
49-
script: scripts/travis/$SCRIPT.sh
55+
56+
script:
57+
- scripts/travis/$SCRIPT.sh
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*******************************************************************
2+
An example of bot that echos back any messages received,
3+
including ones from channels
4+
5+
Parts:
6+
ESP32 D1 Mini stlye Dev board* - http://s.click.aliexpress.com/e/C6ds4my
7+
(or any ESP32 board)
8+
9+
= Affilate
10+
11+
If you find what I do useful and would like to support me,
12+
please consider becoming a sponsor on Github
13+
https://github.com/sponsors/witnessmenow/
14+
15+
16+
Written by Brian Lough
17+
YouTube: https://www.youtube.com/brianlough
18+
Tindie: https://www.tindie.com/stores/brianlough/
19+
Twitter: https://twitter.com/witnessmenow
20+
*******************************************************************/
21+
/*******************************************************************
22+
* An example of bot that echos back any messages received,
23+
* including ones from channels
24+
*
25+
* written by Brian Lough
26+
*******************************************************************/
27+
#include <WiFi.h>
28+
#include <WiFiClientSecure.h>
29+
#include <UniversalTelegramBot.h>
30+
31+
// Wifi network station credentials
32+
#define WIFI_SSID "YOUR_SSID"
33+
#define WIFI_PASSWORD "YOUR_PASSWORD"
34+
// Telegram BOT Token (Get from Botfather)
35+
#define BOT_TOKEN "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
36+
37+
const unsigned long BOT_MTBS = 1000; // mean time between scan messages
38+
39+
WiFiClientSecure secured_client;
40+
UniversalTelegramBot bot(BOT_TOKEN, secured_client);
41+
unsigned long bot_lasttime; // last time messages' scan has been done
42+
43+
void handleNewMessages(int numNewMessages)
44+
{
45+
for (int i = 0; i < numNewMessages; i++)
46+
{
47+
if (bot.messages[i].type == "channel_post")
48+
{
49+
bot.sendMessage(bot.messages[i].chat_id, bot.messages[i].chat_title + " " + bot.messages[i].text, "");
50+
}
51+
else
52+
{
53+
bot.sendMessage(bot.messages[i].chat_id, bot.messages[i].text, "");
54+
}
55+
}
56+
}
57+
58+
void setup()
59+
{
60+
Serial.begin(115200);
61+
Serial.println();
62+
63+
// attempt to connect to Wifi network:
64+
Serial.print("Connecting to Wifi SSID ");
65+
Serial.print(WIFI_SSID);
66+
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
67+
secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT); // Add root certificate for api.telegram.org
68+
while (WiFi.status() != WL_CONNECTED)
69+
{
70+
Serial.print(".");
71+
delay(500);
72+
}
73+
Serial.print("\nWiFi connected. IP address: ");
74+
Serial.println(WiFi.localIP());
75+
76+
Serial.print("Retrieving time: ");
77+
configTime(0, 0, "pool.ntp.org"); // get UTC time via NTP
78+
time_t now = time(nullptr);
79+
while (now < 24 * 3600)
80+
{
81+
Serial.print(".");
82+
delay(100);
83+
now = time(nullptr);
84+
}
85+
Serial.println(now);
86+
}
87+
88+
void loop()
89+
{
90+
if (millis() - bot_lasttime > BOT_MTBS)
91+
{
92+
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
93+
94+
while (numNewMessages)
95+
{
96+
Serial.println("got response");
97+
handleNewMessages(numNewMessages);
98+
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
99+
}
100+
101+
bot_lasttime = millis();
102+
}
103+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*******************************************************************
2+
A telegram bot for your ESP32 that demonstrates a bot
3+
that show bot action message
4+
5+
Parts:
6+
ESP32 D1 Mini stlye Dev board* - http://s.click.aliexpress.com/e/C6ds4my
7+
(or any ESP32 board)
8+
9+
= Affilate
10+
11+
If you find what I do useful and would like to support me,
12+
please consider becoming a sponsor on Github
13+
https://github.com/sponsors/witnessmenow/
14+
15+
Example originally written by Vadim Sinitski
16+
17+
Library written by Brian Lough
18+
YouTube: https://www.youtube.com/brianlough
19+
Tindie: https://www.tindie.com/stores/brianlough/
20+
Twitter: https://twitter.com/witnessmenow
21+
*******************************************************************/
22+
#include <WiFi.h>
23+
#include <WiFiClientSecure.h>
24+
#include <UniversalTelegramBot.h>
25+
26+
// Wifi network station credentials
27+
#define WIFI_SSID "YOUR_SSID"
28+
#define WIFI_PASSWORD "YOUR_PASSWORD"
29+
// Telegram BOT Token (Get from Botfather)
30+
#define BOT_TOKEN "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
31+
32+
const unsigned long BOT_MTBS = 1000; // mean time between scan messages
33+
34+
WiFiClientSecure secured_client;
35+
UniversalTelegramBot bot(BOT_TOKEN, secured_client);
36+
unsigned long bot_lasttime; // last time messages' scan has been done
37+
bool Start = false;
38+
39+
void handleNewMessages(int numNewMessages)
40+
{
41+
Serial.println("handleNewMessages");
42+
Serial.println(String(numNewMessages));
43+
44+
for (int i = 0; i < numNewMessages; i++)
45+
{
46+
String chat_id = bot.messages[i].chat_id;
47+
String text = bot.messages[i].text;
48+
49+
String from_name = bot.messages[i].from_name;
50+
if (from_name == "")
51+
from_name = "Guest";
52+
53+
if (text == "/send_test_action")
54+
{
55+
bot.sendChatAction(chat_id, "typing");
56+
delay(4000);
57+
bot.sendMessage(chat_id, "Did you see the action message?");
58+
59+
// You can't use own message, just choose from one of bellow
60+
61+
//typing for text messages
62+
//upload_photo for photos
63+
//record_video or upload_video for videos
64+
//record_audio or upload_audio for audio files
65+
//upload_document for general files
66+
//find_location for location data
67+
68+
//more info here - https://core.telegram.org/bots/api#sendchataction
69+
}
70+
71+
if (text == "/start")
72+
{
73+
String welcome = "Welcome to Universal Arduino Telegram Bot library, " + from_name + ".\n";
74+
welcome += "This is Chat Action Bot example.\n\n";
75+
welcome += "/send_test_action : to send test chat action message\n";
76+
bot.sendMessage(chat_id, welcome);
77+
}
78+
}
79+
}
80+
81+
void setup()
82+
{
83+
Serial.begin(115200);
84+
Serial.println();
85+
86+
// attempt to connect to Wifi network:
87+
Serial.print("Connecting to Wifi SSID ");
88+
Serial.print(WIFI_SSID);
89+
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
90+
secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT); // Add root certificate for api.telegram.org
91+
while (WiFi.status() != WL_CONNECTED)
92+
{
93+
Serial.print(".");
94+
delay(500);
95+
}
96+
Serial.print("\nWiFi connected. IP address: ");
97+
Serial.println(WiFi.localIP());
98+
99+
Serial.print("Retrieving time: ");
100+
configTime(0, 0, "pool.ntp.org"); // get UTC time via NTP
101+
time_t now = time(nullptr);
102+
while (now < 24 * 3600)
103+
{
104+
Serial.print(".");
105+
delay(100);
106+
now = time(nullptr);
107+
}
108+
Serial.println(now);
109+
}
110+
111+
void loop()
112+
{
113+
if (millis() - bot_lasttime > BOT_MTBS)
114+
{
115+
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
116+
117+
while (numNewMessages)
118+
{
119+
Serial.println("got response");
120+
handleNewMessages(numNewMessages);
121+
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
122+
}
123+
124+
bot_lasttime = millis();
125+
}
126+
}

examples/ESP32/ChatAction/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ESP32 - Chat Action
2+
3+
This is a basic example of how to use chat action using UniversalTelegramBot for ESP32 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+
![License](https://img.shields.io/github/license/witnessmenow/Universal-Arduino-Telegram-Bot)
14+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
15+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

0 commit comments

Comments
 (0)