-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from witnessmenow/V1.1.0
V1.1.0
- Loading branch information
Showing
29 changed files
with
1,827 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/******************************************************************* | ||
* An example of bot that echos back any messages received, | ||
* including ones from channels | ||
* | ||
* written by Brian Lough | ||
*******************************************************************/ | ||
#include <WiFi.h> | ||
#include <WiFiClientSecure.h> | ||
#include <UniversalTelegramBot.h> | ||
|
||
// Initialize Wifi connection to the router | ||
char ssid[] = "XXXXXX"; // your network SSID (name) | ||
char password[] = "YYYYYY"; // your network key | ||
|
||
// Initialize Telegram BOT | ||
#define BOTtoken "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // your Bot Token (Get from Botfather) | ||
|
||
WiFiClientSecure client; | ||
UniversalTelegramBot bot(BOTtoken, client); | ||
|
||
int Bot_mtbs = 1000; //mean time between scan messages | ||
long Bot_lasttime; //last time messages' scan has been done | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
// Attempt to connect to Wifi network: | ||
Serial.print("Connecting Wifi: "); | ||
Serial.println(ssid); | ||
|
||
// Set WiFi to station mode and disconnect from an AP if it was Previously | ||
// connected | ||
WiFi.mode(WIFI_STA); | ||
WiFi.begin(ssid, password); | ||
|
||
while (WiFi.status() != WL_CONNECTED) { | ||
Serial.print("."); | ||
delay(500); | ||
} | ||
|
||
Serial.println(""); | ||
Serial.println("WiFi connected"); | ||
Serial.print("IP address: "); | ||
Serial.println(WiFi.localIP()); | ||
} | ||
|
||
void loop() { | ||
if (millis() > Bot_lasttime + Bot_mtbs) { | ||
int numNewMessages = bot.getUpdates(bot.last_message_received + 1); | ||
|
||
while(numNewMessages) { | ||
Serial.println("got response"); | ||
for (int i=0; i<numNewMessages; i++) { | ||
if(bot.messages[i].type == "channel_post") { | ||
bot.sendMessage(bot.messages[i].chat_id, bot.messages[i].chat_title + " " + bot.messages[i].text, ""); | ||
} else { | ||
bot.sendMessage(bot.messages[i].chat_id, bot.messages[i].text, ""); | ||
} | ||
} | ||
|
||
numNewMessages = bot.getUpdates(bot.last_message_received + 1); | ||
} | ||
|
||
Bot_lasttime = millis(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/******************************************************************* | ||
* An example of bot that show bot action message. * | ||
* * | ||
* * | ||
* * | ||
* written by Vadim Sinitski * | ||
*******************************************************************/ | ||
#include <WiFi.h> | ||
#include <WiFiClientSecure.h> | ||
#include <UniversalTelegramBot.h> | ||
|
||
// Initialize Wifi connection to the router | ||
char ssid[] = "XXXXXX"; // your network SSID (name) | ||
char password[] = "YYYYYY"; // your network key | ||
|
||
// Initialize Telegram BOT | ||
#define BOTtoken "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // your Bot Token (Get from Botfather) | ||
|
||
WiFiClientSecure client; | ||
UniversalTelegramBot bot(BOTtoken, client); | ||
|
||
int Bot_mtbs = 1000; //mean time between scan messages | ||
long Bot_lasttime; //last time messages' scan has been done | ||
bool Start = false; | ||
|
||
void handleNewMessages(int numNewMessages) { | ||
Serial.println("handleNewMessages"); | ||
Serial.println(String(numNewMessages)); | ||
|
||
for (int i=0; i<numNewMessages; i++) { | ||
String chat_id = String(bot.messages[i].chat_id); | ||
String text = bot.messages[i].text; | ||
|
||
String from_name = bot.messages[i].from_name; | ||
if (from_name == "") from_name = "Guest"; | ||
|
||
if (text == "/send_test_action") { | ||
bot.sendChatAction(chat_id, "typing"); | ||
delay(4000); | ||
bot.sendMessage(chat_id, "Did you see the action message?"); | ||
|
||
// You can't use own message, just choose from one of bellow | ||
|
||
//typing for text messages | ||
//upload_photo for photos | ||
//record_video or upload_video for videos | ||
//record_audio or upload_audio for audio files | ||
//upload_document for general files | ||
//find_location for location data | ||
|
||
//more info here - https://core.telegram.org/bots/api#sendchataction | ||
} | ||
|
||
if (text == "/start") { | ||
String welcome = "Welcome to Universal Arduino Telegram Bot library, " + from_name + ".\n"; | ||
welcome += "This is Chat Action Bot example.\n\n"; | ||
welcome += "/send_test_action : to send test chat action message\n"; | ||
bot.sendMessage(chat_id, welcome); | ||
} | ||
} | ||
} | ||
|
||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
// Attempt to connect to Wifi network: | ||
Serial.print("Connecting Wifi: "); | ||
Serial.println(ssid); | ||
|
||
// Set WiFi to station mode and disconnect from an AP if it was Previously | ||
// connected | ||
WiFi.mode(WIFI_STA); | ||
WiFi.begin(ssid, password); | ||
|
||
while (WiFi.status() != WL_CONNECTED) { | ||
Serial.print("."); | ||
delay(500); | ||
} | ||
|
||
Serial.println(""); | ||
Serial.println("WiFi connected"); | ||
Serial.print("IP address: "); | ||
Serial.println(WiFi.localIP()); | ||
} | ||
|
||
void loop() { | ||
if (millis() > Bot_lasttime + Bot_mtbs) { | ||
int numNewMessages = bot.getUpdates(bot.last_message_received + 1); | ||
|
||
while(numNewMessages) { | ||
Serial.println("got response"); | ||
handleNewMessages(numNewMessages); | ||
numNewMessages = bot.getUpdates(bot.last_message_received + 1); | ||
} | ||
|
||
Bot_lasttime = millis(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ESP8266 - Chat Action | ||
|
||
This is a basic example of how to use chat action using UniversalTelegramBot for ESP8266 based boards. | ||
|
||
Application originally written by [Giancarlo Bacchio]([email protected]) for [ESP8266-TelegramBot library](https://github.com/Gianbacchio/ESP8266-TelegramBot) | ||
|
||
Adapted by [Brian Lough](https://github.com/witnessmenow) | ||
|
||
NOTE: You will need to enter your SSID, password and bot Token for the example to work. | ||
|
||
## License | ||
|
||
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. |
93 changes: 93 additions & 0 deletions
93
examples/ESP32/CustomKeyboard/InlineKeyboardMarkup/InlineKeyboardMarkup.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/******************************************************************* | ||
An example of how to use a custom reply keyboard markup. | ||
written by Vadim Sinitski (modified by Brian Lough) | ||
*******************************************************************/ | ||
#include <WiFi.h> | ||
#include <WiFiClientSecure.h> | ||
#include <UniversalTelegramBot.h> | ||
|
||
// Initialize Wifi connection to the router | ||
char ssid[] = "XXXXXX"; // your network SSID (name) | ||
char password[] = "YYYYYY"; // your network key | ||
|
||
// Initialize Telegram BOT | ||
#define BOTtoken "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // your Bot Token (Get from Botfather) | ||
|
||
WiFiClientSecure client; | ||
UniversalTelegramBot bot(BOTtoken, client); | ||
|
||
int Bot_mtbs = 1000; //mean time between scan messages | ||
long Bot_lasttime; //last time messages' scan has been done | ||
|
||
void handleNewMessages(int numNewMessages) { | ||
|
||
for (int i = 0; i < numNewMessages; i++) { | ||
|
||
// Inline buttons with callbacks when pressed will raise a callback_query message | ||
if (bot.messages[i].type == "callback_query") { | ||
Serial.print("Call back button pressed by: "); | ||
Serial.println(bot.messages[i].from_id); | ||
Serial.print("Data on the button: "); | ||
Serial.println(bot.messages[i].text); | ||
bot.sendMessage(bot.messages[i].from_id, bot.messages[i].text, ""); | ||
} else { | ||
String chat_id = String(bot.messages[i].chat_id); | ||
String text = bot.messages[i].text; | ||
|
||
String from_name = bot.messages[i].from_name; | ||
if (from_name == "") from_name = "Guest"; | ||
|
||
if (text == "/options") { | ||
String keyboardJson = "[[{ \"text\" : \"Go to Google\", \"url\" : \"https://www.google.com\" }],[{ \"text\" : \"Send\", \"callback_data\" : \"This was sent by inline\" }]]"; | ||
bot.sendMessageWithInlineKeyboard(chat_id, "Choose from one of the following options", "", keyboardJson); | ||
} | ||
|
||
if (text == "/start") { | ||
String welcome = "Welcome to Universal Arduino Telegram Bot library, " + from_name + ".\n"; | ||
welcome += "This is Inline Keyboard Markup example.\n\n"; | ||
welcome += "/options : returns the inline keyboard\n"; | ||
|
||
bot.sendMessage(chat_id, welcome, "Markdown"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
// Attempt to connect to Wifi network: | ||
Serial.print("Connecting Wifi: "); | ||
Serial.println(ssid); | ||
|
||
// Set WiFi to station mode and disconnect from an AP if it was Previously | ||
// connected | ||
WiFi.mode(WIFI_STA); | ||
WiFi.begin(ssid, password); | ||
|
||
while (WiFi.status() != WL_CONNECTED) { | ||
Serial.print("."); | ||
delay(500); | ||
} | ||
|
||
Serial.println(""); | ||
Serial.println("WiFi connected"); | ||
Serial.print("IP address: "); | ||
Serial.println(WiFi.localIP()); | ||
} | ||
|
||
void loop() { | ||
if (millis() > Bot_lasttime + Bot_mtbs) { | ||
int numNewMessages = bot.getUpdates(bot.last_message_received + 1); | ||
|
||
while (numNewMessages) { | ||
Serial.println("got response"); | ||
handleNewMessages(numNewMessages); | ||
numNewMessages = bot.getUpdates(bot.last_message_received + 1); | ||
} | ||
|
||
Bot_lasttime = millis(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#Reply Keyboard Markup | ||
|
||
This is an example of how to use reply keyboard markup on a ESP8266 based board. | ||
|
||
![alt text](https://core.telegram.org/file/811140184/1/5YJxx-rostA/ad3f74094485fb97bd "Reply Keyboard example") | ||
|
||
The application will turn on and off an LED based on commands received via telegram. | ||
|
||
#Inline Keyboard Markup | ||
|
||
This is an example of how to use reply keyboard markup on a ESP8266 based board. | ||
|
||
|
||
![alt text](https://core.telegram.org/file/811140999/1/2JSoUVlWKa0/4fad2e2743dc8eda04 "Inline Keyboard example") | ||
|
||
Right now working only URL redirection button. Other features will be added later. | ||
|
||
----------------- | ||
|
||
NOTE: You will need to enter your SSID, password and bot Token for the example to work. | ||
|
||
Application written by [Brian Lough](https://github.com/witnessmenow) | ||
|
||
|
||
|
||
## License | ||
|
||
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. |
Oops, something went wrong.