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
16 changes: 10 additions & 6 deletions src/TelegramBot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@

#include "TelegramBot.h"

TelegramBot::TelegramBot(const char* token, Client &client) {
TelegramBot::TelegramBot(const char* token, WiFiClientSecure &client) {
this->client = &client;
this->token=token;
}


void TelegramBot::begin() {
void TelegramBot::begin() {
if(!client->connected()){
client->connect(HOST, SSL_PORT);
client->setInsecure();

if(!client->connect(HOST, SSL_PORT)){
Serial.println("Connection failed.");
}
else{
Serial.println("Connected");
}
}
}

Expand All @@ -39,8 +45,6 @@ message TelegramBot::getUpdates() {
StaticJsonBuffer<JSON_BUFF_SIZE> jsonBuffer;
JsonObject & root = jsonBuffer.parseObject(payload);



if(root.success()){

int update_id = root["result"][0]["update_id"];
Expand Down
6 changes: 3 additions & 3 deletions src/TelegramBot.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <Arduino.h>
#include <ArduinoJson.h>
#include <Client.h>
#include <WiFiClientSecure.h>
#include <TelegramKeyboard.h>

#define HOST "api.telegram.org"
Expand All @@ -33,7 +33,7 @@ struct message{
class TelegramBot
{
public:
TelegramBot(const char* token, Client &client);
TelegramBot(const char* token, WiFiClientSecure &client);
void begin();
String sendMessage(String chat_id, String text);
String sendMessage(String chat_id, String text, TelegramKeyboard &keyboard_markup, bool one_time_keyboard = true, bool resize_keyboard = true);
Expand All @@ -45,7 +45,7 @@ class TelegramBot
const char* token;
int last_message_recived;

Client *client;
WiFiClientSecure *client;
};

#endif
1 change: 0 additions & 1 deletion src/TelegramKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// TelegramBot library
// https://github.com/CasaJasmina/TelegramBot-Library


#ifndef TelegramKeyboard_h
#define TelegramKeyboard_h
#include <Arduino.h>
Expand Down