-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathUniversalTelegramBotRZO.h
121 lines (102 loc) · 4.31 KB
/
UniversalTelegramBotRZO.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
Copyright (c) 2018 Brian Lough. All right reserved.
UniversalTelegramBot - Library to create your own Telegram Bot using
ESP8266 or ESP32 on Arduino IDE.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef UniversalTelegramBotRZO_h
#define UniversalTelegramBotRZO_h
#define ARDUINOJSON_DECODE_UNICODE 1
#define ARDUINOJSON_USE_LONG_LONG 1
#include <Arduino.h>
#include <ArduinoJson.h>
#include <Client.h>
#include <core_version.h>
#define HOST "api.telegram.org"
#define SSL_PORT 443
#define HANDLE_MESSAGES 1
//unmark following line to enable debug mode
#define _debug
typedef bool (*MoreDataAvailable)();
typedef byte (*GetNextByte)();
typedef byte* (*GetNextBuffer)();
typedef int (GetNextBufferLen)();
struct telegramMessage {
String inline_query;
String inline_query_id;
String sticker_id;
String sticker_uid;
int sticker_width;
int sticker_height;
bool sticker_animated;
String text;
String chat_id;
String chat_title;
String from_id;
String from_name;
String date;
String type;
float longitude;
float latitude;
int update_id;
};
class UniversalTelegramBot {
public:
UniversalTelegramBot(String token, Client &client);
String sendGetToTelegram(String command);
String sendPostToTelegram(String command, JsonObject payload);
String
sendMultipartFormDataToTelegram(String command, String binaryProperyName,
String fileName, String contentType,
String chat_id, int fileSize,
MoreDataAvailable moreDataAvailableCallback,
GetNextByte getNextByteCallback,
GetNextBuffer getNextBufferCallback,
GetNextBufferLen getNextBufferLenCallback);
bool getMe();
bool sendSimpleMessage(String chat_id, String text, String parse_mode);
bool sendMessage(String chat_id, String text, String parse_mode = "");
bool sendMessageWithReplyKeyboard(String chat_id, String text,
String parse_mode, String keyboard,
bool resize = false, bool oneTime = false,
bool selective = false);
bool sendMessageWithInlineKeyboard(String chat_id, String text,
String parse_mode, String keyboard);
bool sendChatAction(String chat_id, String text);
bool sendPostMessage(JsonObject payload);
String sendPostPhoto(JsonObject payload);
String sendPhotoByBinary(String chat_id, String contentType, int fileSize,
MoreDataAvailable moreDataAvailableCallback,
GetNextByte getNextByteCallback,
GetNextBuffer getNextBufferCallback,
GetNextBufferLen getNextBufferLenCallback);
String sendPhoto(String chat_id, String photo, String caption = "",
bool disable_notification = false,
int reply_to_message_id = 0, String keyboard = "");
int getUpdates(long offset);
bool checkForOkResponse(String response);
telegramMessage messages[HANDLE_MESSAGES];
long last_message_received;
String name;
String userName;
int longPoll = 0;
int waitForResponse = 1500;
private:
// JsonObject * parseUpdates(String response);
String _token;
Client *client;
void closeClient();
const int maxMessageLength = 1500;
bool processResult(JsonObject result, int messageIndex);
};
#endif