Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ You also need to install the [ESP8266 Arduino Core and Library](https://github.c
Don't you know Telegram bots and how to setup one? Check [this](https://core.telegram.org/bots#6-botfather).

+ **_ESP8266 don't use anymore the fingerprint for Telegram certificate validation_**
+ **_Now ArduinoJson version 5 and 6 are supported!_**
+ **_Now ArduinoJson version 5, 6 and 7 are supported!_**
+ **_getNewMessage method now is more responsive!!_**

### _IMPORTANT - There are some incompatibilities with the ArduinoJson v 6.20.0. The last supported version is the 6.19.4_

### News
+ Arduino JSON v7.* support
+ ESP32 supported
+ ArduinoJson version 5 and 6 supported

Expand Down Expand Up @@ -45,13 +44,9 @@ A special thanks go to these people who helped me making this library
+ [michaelzs85](https://github.com/michaelzs85)
+ [Di-Strix](https://github.com/Di-Strix)
+ [ElVasquito](https://github.com/ElVasquito)

### Future work
+ [x] Add Telegram inline keyboards
+ [x] Add ESP32 support & testing
+ [x] ArduinoJSON 6 support


### Changelog
Fork (Drovosekov) for Arduino JSON v7 support testing
+ 2.1.13 ESP32 compile error
+ 2.1.12 No more fingerprint certificate validation for ESP8266
+ 2.1.11 Fixed an issue on group/chat ID in callback queries
Expand Down
33 changes: 21 additions & 12 deletions examples/chatGroupEchoBot/chatGroupEchoBot.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,48 @@
Name: chatGroupEchoBot.ino
Created: 14/06/2020
Author: Stefano Ledda <shurillu@tiscalinet.it>
Ported Arduino JSON v7: Alexander Drovosekov <alexander.drovosekov@gmail.com>
Description: an example that check for incoming messages
1) send a message to the sender some "message related" infos
2) if the message came from a group chat, reply the group chat
with the same message (like the echoBot example)
*/
#include <ESP8266WiFi.h>
#include "CTBot.h"
#include "Utilities.h" // for int64ToAscii() helper function

String ssid = "mySSID" ; // REPLACE mySSID WITH YOUR WIFI SSID
String pass = "myPassword"; // REPLACE myPassword YOUR WIFI PASSWORD, IF ANY
String token = "myToken" ; // REPLACE myToken WITH YOUR TELEGRAM BOT TOKEN
String ssid = "YOUR_SSID"; // REPLACE mySSID WITH YOUR WIFI SSID
String pass = "YOUR_WIFI_PASSWORD"; // REPLACE myPassword YOUR WIFI PASSWORD, IF ANY
String token = "TELEGRAM_TOKEN" ; // REPLACE myToken WITH YOUR TELEGRAM BOT TOKEN

CTBot myBot;




void setup() {
// initialize the Serial
Serial.begin(115200);
Serial.println("Starting TelegramBot...");

// connect the ESP8266 to the desired access point
myBot.wifiConnect(ssid, pass);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

// set the telegram bot token
myBot.setTelegramToken(token);

// check if all things are ok
if (myBot.testConnection())
Serial.println("\ntestConnection OK");
Serial.println("testConnection OK");
else
Serial.println("\ntestConnection NOK");
Serial.println("testConnection NOK");
}

void loop() {
Expand Down Expand Up @@ -63,7 +73,6 @@ void loop() {
}
}
}

// wait 500 milliseconds

delay(500);
}
55 changes: 34 additions & 21 deletions examples/echoBot/echoBot.ino
Original file line number Diff line number Diff line change
@@ -1,33 +1,46 @@
/*
Name: echoBot.ino
Created: 12/21/2017
Created: 20/09/2024
Author: Stefano Ledda <shurillu@tiscalinet.it>
Ported Arduino JSON v7: Alexander Drovosekov <alexander.drovosekov@gmail.com>
Description: a simple example that check for incoming messages
and reply the sender with the received message
*/
#include "CTBot.h"
CTBot myBot;
#include <ESP8266WiFi.h>
#include "CTBot.h"

String ssid = "mySSID" ; // REPLACE mySSID WITH YOUR WIFI SSID
String pass = "myPassword"; // REPLACE myPassword YOUR WIFI PASSWORD, IF ANY
String token = "myToken" ; // REPLACE myToken WITH YOUR TELEGRAM BOT TOKEN
String ssid = "YOUR_SSID"; // REPLACE mySSID WITH YOUR WIFI SSID
String pass = "YOUR_WIFI_PASSWORD"; // REPLACE myPassword YOUR WIFI PASSWORD, IF ANY
String token = "TELEGRAM_TOKEN" ; // REPLACE myToken WITH YOUR TELEGRAM BOT TOKEN

CTBot myBot;

void setup() {
// initialize the Serial
Serial.begin(115200);
Serial.println("Starting TelegramBot...");

// connect the ESP8266 to the desired access point
myBot.wifiConnect(ssid, pass);

// set the telegram bot token
myBot.setTelegramToken(token);

// check if all things are ok
if (myBot.testConnection())
Serial.println("\ntestConnection OK");
else
Serial.println("\ntestConnection NOK");
// initialize the Serial
Serial.begin(115200);
Serial.println("Starting TelegramBot...");

WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

// set the telegram bot token
myBot.setTelegramToken(token);

// check if all things are ok
if (myBot.testConnection())
Serial.println("testConnection OK");
else
Serial.println("testConnection NOK");
}

void loop() {
Expand Down
43 changes: 28 additions & 15 deletions examples/inlineKeyboard/inlineKeyboard.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
Name: inlineKeyboard.ino
Created: 29/05/2018
Created: 20/09/2024
Author: Stefano Ledda <shurillu@tiscalinet.it>
Ported Arduino JSON v7: Alexander Drovosekov <alexander.drovosekov@gmail.com>
Description: a simple example that do:
1) if a "show keyboard" text message is received, show the inline custom keyboard,
otherwise reply the sender with "Try 'show keyboard'" message
Expand All @@ -10,18 +11,20 @@ Description: a simple example that do:
4) if "see docs" inline keyboard button is pressed,
open a browser window with URL "https://github.com/shurillu/CTBot"
*/
#include "CTBot.h"
#include <ESP8266WiFi.h>
#include "CTBot.h"

String ssid = "YOUR_SSID"; // REPLACE mySSID WITH YOUR WIFI SSID
String pass = "YOUR_WIFI_PASSWORD"; // REPLACE myPassword YOUR WIFI PASSWORD, IF ANY
String token = "TELEGRAM_TOKEN" ; // REPLACE myToken WITH YOUR TELEGRAM BOT TOKEN

#define LIGHT_ON_CALLBACK "lightON" // callback data sent when "LIGHT ON" button is pressed
#define LIGHT_OFF_CALLBACK "lightOFF" // callback data sent when "LIGHT OFF" button is pressed

CTBot myBot;
CTBotInlineKeyboard myKbd; // custom inline keyboard object helper

String ssid = "mySSID"; // REPLACE mySSID WITH YOUR WIFI SSID
String pass = "myPassword"; // REPLACE myPassword YOUR WIFI PASSWORD, IF ANY
String token = "myToken"; // REPLACE myToken WITH YOUR TELEGRAM BOT TOKEN
uint8_t led = 2; // the onboard ESP8266 LED.

#define LED_PIN 2 // the onboard ESP8266 LED.
// If you have a NodeMCU you can use the BUILTIN_LED pin
// (replace 2 with BUILTIN_LED)
// ATTENTION: this led use inverted logic
Expand All @@ -31,21 +34,31 @@ void setup() {
Serial.begin(115200);
Serial.println("Starting TelegramBot...");

// connect the ESP8266 to the desired access point
myBot.wifiConnect(ssid, pass);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

// set the telegram bot token
myBot.setTelegramToken(token);

// check if all things are ok
if (myBot.testConnection())
Serial.println("\ntestConnection OK");
Serial.println("testConnection OK");
else
Serial.println("\ntestConnection NOK");
Serial.println("testConnection NOK");

// set the pin connected to the LED to act as output pin
pinMode(led, OUTPUT);
digitalWrite(led, HIGH); // turn off the led (inverted logic!)
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH); // turn off the led (inverted logic!)

// inline keyboard customization
// add a query button to the first row of the inline keyboard
Expand Down Expand Up @@ -79,12 +92,12 @@ void loop() {
// received a callback query message
if (msg.callbackQueryData.equals(LIGHT_ON_CALLBACK)) {
// pushed "LIGHT ON" button...
digitalWrite(led, LOW); // ...turn on the LED (inverted logic!)
digitalWrite(LED_PIN, LOW); // ...turn on the LED (inverted logic!)
// terminate the callback with an alert message
myBot.endQuery(msg.callbackQueryID, "Light on", true);
} else if (msg.callbackQueryData.equals(LIGHT_OFF_CALLBACK)) {
// pushed "LIGHT OFF" button...
digitalWrite(led, HIGH); // ...turn off the LED (inverted logic!)
digitalWrite(LED_PIN, HIGH); // ...turn off the LED (inverted logic!)
// terminate the callback with a popup message
myBot.endQuery(msg.callbackQueryID, "Light off");
}
Expand Down
42 changes: 27 additions & 15 deletions examples/lightBot/lightBot.ino
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
/*
Name: lightBot.ino
Created: 17/01/2018
Created: 20/09/2024
Author: Stefano Ledda <shurillu@tiscalinet.it>
Ported Arduino JSON v7: Alexander Drovosekov <alexander.drovosekov@gmail.com>
Description: a simple example that do:
1) parse incoming messages
2) if "LIGHT ON" message is received, turn on the onboard LED
3) if "LIGHT OFF" message is received, turn off the onboard LED
4) otherwise, reply to sender with a welcome message

*/
#include <ESP8266WiFi.h>
#include "CTBot.h"
CTBot myBot;

String ssid = "mySSID"; // REPLACE mySSID WITH YOUR WIFI SSID
String pass = "myPassword"; // REPLACE myPassword YOUR WIFI PASSWORD, IF ANY
String token = "myToken"; // REPLACE myToken WITH YOUR TELEGRAM BOT TOKEN
uint8_t led = 2; // the onboard ESP8266 LED.
String ssid = "YOUR_SSID"; // REPLACE mySSID WITH YOUR WIFI SSID
String pass = "YOUR_WIFI_PASSWORD"; // REPLACE myPassword YOUR WIFI PASSWORD, IF ANY
String token = "TELEGRAM_TOKEN" ; // REPLACE myToken WITH YOUR TELEGRAM BOT TOKEN

#define LED_PIN 2 // the onboard ESP8266 LED.
// If you have a NodeMCU you can use the BUILTIN_LED pin
// (replace 2 with BUILTIN_LED)

Expand All @@ -24,21 +26,31 @@ void setup() {
Serial.begin(115200);
Serial.println("Starting TelegramBot...");

// connect the ESP8266 to the desired access point
myBot.wifiConnect(ssid, pass);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

// set the telegram bot token
myBot.setTelegramToken(token);

// check if all things are ok
if (myBot.testConnection())
Serial.println("\ntestConnection OK");
Serial.println("testConnection OK");
else
Serial.println("\ntestConnection NOK");
Serial.println("testConnection NOK");

// set the pin connected to the LED to act as output pin
pinMode(led, OUTPUT);
digitalWrite(led, HIGH); // turn off the led (inverted logic!)
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH); // turn off the led (inverted logic!)

}

Expand All @@ -50,17 +62,17 @@ void loop() {
if (CTBotMessageText == myBot.getNewMessage(msg)) {

if (msg.text.equalsIgnoreCase("LIGHT ON")) { // if the received message is "LIGHT ON"...
digitalWrite(led, LOW); // turn on the LED (inverted logic!)
digitalWrite(LED_PIN, LOW); // turn on the LED (inverted logic!)
myBot.sendMessage(msg.sender.id, "Light is now ON"); // notify the sender
}
else if (msg.text.equalsIgnoreCase("LIGHT OFF")) { // if the received message is "LIGHT OFF"...
digitalWrite(led, HIGH); // turn off the led (inverted logic!)
digitalWrite(LED_PIN, HIGH); // turn off the led (inverted logic!)
myBot.sendMessage(msg.sender.id, "Light is now OFF"); // notify the sender
}
else { // otherwise...
// generate the message for the sender
String reply;
reply = (String)"Welcome " + msg.sender.username + (String)". Try LIGHT ON or LIGHT OFF.";
reply = "Welcome " + msg.sender.username + ". Try LIGHT ON or LIGHT OFF.";
myBot.sendMessage(msg.sender.id, reply); // and send it
}
}
Expand Down
27 changes: 19 additions & 8 deletions examples/replyKeyboard/replyKeyboard.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
Name: replyKeyboard.ino
Created: 07/10/2019
Created: 20/09/2024
Author: Stefano Ledda <shurillu@tiscalinet.it>
Ported Arduino JSON v7: Alexander Drovosekov <alexander.drovosekov@gmail.com>
Description: a simple example that do:
1) if a "show keyboard" text message is received, show the reply keyboard,
otherwise reply the sender with "Try 'show keyboard'" message
Expand All @@ -17,26 +18,36 @@ CTBot myBot;
CTBotReplyKeyboard myKbd; // reply keyboard object helper
bool isKeyboardActive; // store if the reply keyboard is shown

String ssid = "mySSID"; // REPLACE mySSID WITH YOUR WIFI SSID
String pass = "myPassword"; // REPLACE myPassword YOUR WIFI PASSWORD, IF ANY
String token = "myToken"; // REPLACE myToken WITH YOUR TELEGRAM BOT TOKEN
String ssid = "YOUR_SSID"; // REPLACE mySSID WITH YOUR WIFI SSID
String pass = "YOUR_WIFI_PASSWORD"; // REPLACE myPassword YOUR WIFI PASSWORD, IF ANY
String token = "TELEGRAM_TOKEN" ; // REPLACE myToken WITH YOUR TELEGRAM BOT TOKEN

void setup() {
// initialize the Serial
Serial.begin(115200);
Serial.println("Starting TelegramBot...");

// connect the ESP8266 to the desired access point
myBot.wifiConnect(ssid, pass);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

// set the telegram bot token
myBot.setTelegramToken(token);

// check if all things are ok
if (myBot.testConnection())
Serial.println("\ntestConnection OK");
Serial.println("testConnection OK");
else
Serial.println("\ntestConnection NOK");
Serial.println("testConnection NOK");

// reply keyboard customization
// add a button that send a message with "Simple button" text
Expand Down
Loading