You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README_EN.md
+98-72Lines changed: 98 additions & 72 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,12 +23,12 @@ Use the [CharDisplay] library(https://github.com/GyverLibs/CharDisplay) to displ
23
23
ESP8266 (SDK v2.6+), ESP32
24
24
25
25
## Documentation and projects
26
-
Detailed tutorials on working with the Telegram bot using this library can be found on the [GyverKIT Arduino website] (https://kit.alexgyver.ru/tutorials-category/telegram/)
26
+
Detailed tutorials on working with the Telegram bot using this library can be found on the [GyverKIT Arduino site] (https://kit.alexgyver.ru/tutorials-category/telegram/)
For comparison, we used a minimal example with sending a message to the chat and outputting incoming messages to the series:
31
+
For comparison, a minimal example was used with sending a message to the chat and outputting incoming messages to the series:
32
32
-**send** - send a message to the chat
33
33
-**update** - check incoming messages
34
34
-**free heap** - amount of free RAM while the program is running
@@ -39,8 +39,12 @@ For comparison, we used a minimal example with sending a message to the chat and
39
39
| fastbot | 393220 | 28036 | 70 | 70 | 37552 |
40
40
| diff | 6784 | 1812 | 1930 | 1830 | 1040 |
41
41
42
-
- FastBot is lighter by almost 7 kB of Flash and 2 kB of SRAM, but takes up 1 kB of SRAM more while the program is running. Total lighter by 2-1 = 1 kB of SRAM.
42
+
- FastBot is almost 7kB lighter than Flash and 2kB SRAM, but takes up 1kB more SRAM while the program is running. Total lighter by 2-1 = 1 kB of SRAM.
43
43
- FastBot processes chat and sends messages much faster (by 2 seconds) due to manual parsing of the server response and statically allocated HTTP clients
44
+
- The test was carried out in the normal mode of operation of FastBot. When `FB_DYNAMIC` is activated, the library will take 10kb less memory, but it will work slower:
45
+
- Free heap: 48000 kB
46
+
- Sending a message: 1 second
47
+
- Update request: 1 second
44
48
45
49
## Content
46
50
-[Install](#install)
@@ -68,17 +72,22 @@ For comparison, we used a minimal example with sending a message to the chat and
68
72
-[Bugs and feedback](#feedback)
69
73
70
74
<aid="install"></a>
71
-
## Installation
75
+
## Installedcranberry vka
72
76
- The library can be found by the name **FastBot** and installed through the library manager in:
73
77
- Arduino IDE
74
78
- Arduino IDE v2
75
79
- PlatformIO
76
80
-[Download library](https://github.com/GyverLibs/FastBot/archive/refs/heads/main.zip) .zip archive for manual installation:
77
81
- Unzip and put in *C:\Program Files (x86)\Arduino\libraries* (Windows x64)
78
-
-Unpack and putin*C:\Program Files\Arduino\libraries* (Windows x32)
82
+
-Unzip and put in*C:\Program Files\Arduino\libraries* (Windows x32)
79
83
- Unpack and put in *Documents/Arduino/libraries/*
80
84
- (Arduino IDE) automatic installation from .zip: *Sketch/Include library/Add .ZIP library…* and specify the downloaded archive
81
85
- Read more detailed instructions for installing libraries [here] (https://alexgyver.ru/arduino-first/#%D0%A3%D1%81%D1%82%D0%B0%D0%BD%D0%BE% D0%B2%D0%BA%D0%B0_%D0%B1%D0%B8%D0%B1%D0%BB%D0%B8%D0%BE%D1%82%D0%B5%D0%BA)
86
+
### Update
87
+
- I recommend always updating the library: new versions fix errors and bugs, as well as optimize and add new features
88
+
- Through the IDE library manager: find the library as during installation and click "Update"
89
+
- Manually: **delete the folder with the old version**, and then put the new one in its place. "Replacement" cannot be done: sometimes new versions delete files that remain after replacement and can lead to errors!
90
+
82
91
83
92
<aid="init"></a>
84
93
## Initialization
@@ -157,7 +166,7 @@ uint8_t closeMenu();
157
166
uint8_t closeMenu(String id);
158
167
159
168
160
-
// ======== REGULAR MENU WITH TEXTOM =========
169
+
// ======== REGULAR MENU WITH TEXT =========
161
170
// message (msg) + show menu (menu) in the chat/chats specified in setChatID OR pass the id of the chat/chats
@@ -290,6 +300,7 @@ String FB_64str(int64_t id); // transfer from int64_t to String
290
300
#define FB_NO_UNICODE // disable Unicode conversion for incoming messages (slightly speed up the program)
291
301
#define FB_NO_URLENCODE // disable urlencode conversion for outgoing messages (slightly speeds up the program)
292
302
#define FB_NO_OTA // disable support for OTA updates from chat
303
+
#define FB_DYNAMIC // enable dynamic mode: the library takes longer to execute the request, but takes up 10 kb less memory in SRAM
293
304
```
294
305
295
306
<aid="usage"></a>
@@ -318,64 +329,67 @@ bot.sendMessage("Hello!", "112233"); // will go to "112233"
318
329
Telegram sets the following limits on **sending** messages by the bot ([documentation](https://core.telegram.org/bots/faq#my-bot-is-hitting-limits-how-do-i-avoid-this))
319
330
- To chat: no more than once per second. *You can send more often, but the message may not reach*
320
331
- To a group: no more than 20 messages per minute
321
-
- Total limit: no more than 30 messages per second
332
+
- Total limit: no more than 30 messages per secondКлюква ду
322
333
323
-
The bot can also read messages that are less than 24 hours old.
334
+
Также бот может читать сообщения, с момента отправки которых прошло меньше 24 часов.
324
335
325
336
<aid="inbox"></a>
326
-
## Message parsing
327
-
Messages are automatically requested and read in `tick()`, when a new message arrives, the specified handler function is called:
328
-
- Create our own function in the sketch like `void function(FB_msg& message)`
329
-
- Call `attach(function)`
330
-
- This function will be automatically called on an incoming message if the chat ID matches or is not configured
331
-
- If the handler is not connected - messages will not be checked
332
-
- Inside this function, you can use the passed variable `message`, which has the type `FB_msg` (structure) and contains:
333
-
-`String userID` - user ID
334
-
-`String username` - user or channel name
335
-
-`String chatID` - chat ID
336
-
-`int32_t messageID` - message ID in the chat
337
-
-`String text` - message text or file caption
338
-
-`String data` - callback data from the menu (if any)- `bool query` - query
339
-
-`bool edited` - message has been edited
340
-
-`bool isBot` - message from bot
341
-
-`bool OTA` - request for OTA update (received .bin file)
342
-
-`uint32_t unix` - message time
343
-
-`String fileName` - file name
344
-
-`String toString()` - all information from the message, convenient for debugging (since 2.11)
345
-
346
-
**Notes:**
347
-
- Telegram splits the text into several messages if the text length exceeds ~4000 characters! These messages will have a different messageID in the chat.
348
-
- When replying to a message, the library parses the text of the original message, not the answer
349
-
350
-
### White list
351
-
The library implements a white list mechanism: you can specify in `setChatID()` the ID of a chat (or several, separated by commas), messages from which will be accepted.
352
-
Messages from other chats will be ignored.
337
+
## Парсинг сообщений
338
+
Сообщения автоматически запрашиваются и читаются в `tick()`, при поступлении нового сообщения вызывается указанная функция-обработчик:
339
+
- Создаём в скетче свою функцию вида `void функция(FB_msg& сообщение)`
340
+
- Вызываем `attach(функция)`
341
+
- Эта функция будет автоматически вызвана при входящем сообщении, если ID чата совпадает или не настроен
342
+
- Если обработчик не подключен - сообщения не будут проверяться
343
+
- Внутри этой функции можно пользоваться переданной переменной `сообщение`, которая имеет тип `FB_msg` (структура) и содержит в себе:
344
+
-`String userID` - ID пользователя
345
+
-`String username` - имя пользователя или канала
346
+
-`String chatID` - ID чата
347
+
-`int32_t messageID` - ID сообщения в чате
348
+
-`String text` - текст сообщения или попдпись к файлу
349
+
-`String replyText` - текст ответа, если он есть
350
+
-`String data` - callback данные из меню (если есть)
351
+
-`bool query` - запрос
352
+
-`bool edited` - сообщение отредактировано
353
+
-`bool isBot` - сообщение от бота
354
+
-`bool OTA` - запрос на OTA обновление (получен .bin файл)
355
+
-`uint32_t unix` - время сообщения
356
+
-`String fileName` - имя файла
357
+
358
+
А также `String toString()` - вся информация из сообщения, удобно для отладки (с версии 2.11)
359
+
360
+
**Примечания:**
361
+
- Телеграм разделяет текст на несколько сообщений, если длина текста превышает ~4000 символов! Эти сообщения будут иметь разный messageID в чате.
362
+
- При ответе на сообщение библиотека парсит текст исходного сообщения, а не ответа
363
+
364
+
### Белый список
365
+
В библиотеке реализован механизм белого списка: можно указать в `setChatID()` ID чата (или нескольких через запятую), сообщения из которого будут приниматься.
366
+
Сообщения из остальных чатов будут игнорироваться.
353
367
354
368
<aid="tick"></a>
355
-
## Ticker
356
-
To poll incoming messages, you need to connect a message handler and call `tick()`in the main loop of the program `loop()`, polling occurs according to the built-in timer.
357
-
By default, the polling period is set to 3600 milliseconds.
369
+
## Тикер
370
+
Для опроса входящих сообщений нужно подключить обработчик сообщений и вызывать `tick()`в главном цикле программы `loop()`, опрос происходит по встроенному таймеру.
371
+
По умолчанию период опроса установлен 3600 миллисекунд.
358
372
359
-
You can poll more often (change the period via `setPeriod()`), but personally, since ~ 2021, the Telegram server has not responded
360
-
sooner than ~3 seconds later. If you request updates more often than this period, the program hangs inside a `tick()` (inside a GET request)
361
-
waiting for the server response for the remainder of 3 seconds. With a period of ~3600 ms this does not happen, so I made it the default.
362
-
Maybe it depends on the provider or the country.
373
+
Можно опрашивать чаще (сменить период через `setPeriod()`), но лично у меня с ~2021 года сервер Телеграм стал отвечать не
374
+
раньше, чем через ~3 секунды. Если запрашивать обновления чаще этого периода, программа зависает внутри `tick()` (внутри GET запроса)
375
+
в ожидании ответа сервера на остаток от 3 секунд. При периоде ~3600 мс этого не происходит, поэтому я сделал его по умолчанию.
376
+
Возможно это зависит от провайдера или страны.
363
377
364
378
<aid="example"></a>
365
-
## Minimal example
379
+
## Минимальный пример
366
380
```cpp
367
381
voidsetup() {
368
-
// connect to WiFi
369
-
bot.attach(newMsg); // connect the message handler
0 commit comments