### FastBot Minimum Example Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md A basic example demonstrating the setup and loop structure for using the FastBot library. It includes connecting to Wi-Fi, attaching a message processor, and calling the `tick()` function. ```cpp VOID setup () { // Connect to Wi-Fi (implementation not shown) // ... BOT.ATTACH (NewMSG); // Attach the message processor } VOID NewMSG (FB_MSG & MSG) { Serial.println (msg.tostring ()); } VOID loop () { BOT.Tick (); // Poll for incoming messages } ``` -------------------------------- ### Send File Example (Buffer) Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Example of sending a text file or a photo from a camera buffer using the Sendfile function. ```cpp Char Buf [] = "Hello, World!"; BOT.SENDFILE ((Byte*) BUF, Strlen (BUF), FB_DOC, "TEST.TXT", Chat_ID); Frame = ESP_camera_FB_GET (); BOT.SENDFILE ((byte*) frame-> buf, frame-> len, fb_photo, "Photo.jpg", Chat_id); ``` -------------------------------- ### Basic Fastbot Setup and Message Handling Source: https://github.com/gyverlibs/fastbot/blob/main/README.md This snippet demonstrates the minimal setup for a Fastbot application. It includes connecting to WiFi, attaching a message handler, and processing incoming messages. The `newMsg` function shows how to access message details like username and text, and how to print the entire message object using `toString()`. ```cpp void setup() { // подключаемся к WiFi bot.attach(newMsg); // подключаем обработчик сообщений } void newMsg(FB_msg& msg) { // выводим имя юзера и текст сообщения //Serial.print(msg.username); //Serial.print(", "); //Serial.println(msg.text); // выводим всю информацию о сообщении Serial.println(msg.toString()); } void loop() { bot.tick(); } ``` -------------------------------- ### Send File Example (Memory) Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Example of sending a PNG image from memory using the Sendfile function with a File object. ```cpp File File = Littlefs.open ("/Test.png", "R"); BOT.SENDFILE (FILE, FB_PHOTO, "TEST.PNG", Chat_id); file.close (); ``` -------------------------------- ### Fastbot Telegram Bot Setup Notes Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Provides essential setup instructions for using Fastbot with Telegram, including webhook mode, group privacy settings, and bot administrator privileges. ```c++ // If you already have a bot, make sure that it * is not in Webhook mode * // In order for the bot to read all the messages in the group (and not just /commands), you need to turn off the * group privacy * parameter // For full work in the group (supergroup), the bot must be done by the administrator! ``` -------------------------------- ### Sending Text File Example Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Example demonstrating how to send a text file using the sendFile function with a character buffer. ```cpp char buf[] = "Hello, World!"; bot.sendFile((byte*)buf, strlen(buf), FB_DOC, "test.txt", CHAT_ID); ``` -------------------------------- ### Sending Camera Photo Example Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Example showing how to send a photo captured from a camera using the sendFile function with the camera frame buffer. ```cpp frame = esp_camera_fb_get(); bot.sendFile((byte*)frame->buf, frame->len, FB_PHOTO, "photo.jpg", CHAT_ID); ``` -------------------------------- ### Time Initialization Example Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Demonstrates how to initialize the fb_time object using the current Unix timestamp and a GMT offset. ```cpp Fb_time t = Bot.gettime (3); // or Fb_time t (Bot.getunix (), 3); ``` -------------------------------- ### Sending Image from Memory Example Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Example of sending an image stored in memory using the sendFile function with a File object. ```cpp File file = LittleFS.open("/test.png", "r"); bot.sendFile(file, FB_PHOTO, "test.png", CHAT_ID); file.close(); ``` -------------------------------- ### Downloading Files Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Starting from v2.20, files can be downloaded using the downloadFile function. This requires a File object opened for writing and the file's URL from the incoming message. ```cpp void newMsg(FB_msg& msg) { if (msg.isFile) { // это файл Serial.print("Downloading "); Serial.println(msg.fileName); String path = '/' + msg.fileName; // путь вида /filename.xxx File f = LittleFS.open(path, "w"); // открываем для записи bool status = bot.downloadFile(f, msg.fileUrl); // загружаем Serial.println(status ? "OK" : "Error"); // статус } } ``` -------------------------------- ### Time and Date Functions Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Functions to get current time, synchronize time, and retrieve Unix timestamps. Includes the `fb_time` structure definition. ```c++ // structure fb_time uint8_t second;// seconds uint8_t minute;// minutes Uint8_t Hour;// watch uint8_t day;// Day of the month uint8_t months;// month uint8_t dayweek;// Day of the week (Mon.. SS 1..7) uint16_t year;// year String Timestring();// line of time of the format of hhh: mm: ss String Datestring();// line of dates of the format DD.MM.YYYY // ==================================================================== Fb_time gettime(int16_t GMT);// get the current time, indicate the time zone (for example, Moscow 3) in hours or minutes Bool TimeSynced();// Check, whether time is synchronized uint32_t getunix();// Get current unix time ``` -------------------------------- ### Menu Formatting Source: https://github.com/gyverlibs/fastbot/blob/main/README.md This explains the formatting rules for creating menus in Fastbot. Special characters `\t` (tab) and `\n` (newline) are used for horizontal and vertical button separation, respectively. Extra spaces are automatically trimmed. The example shows a 3x1 menu layout. ```cpp // Menu formatting uses '\t' for horizontal separation and '\n' for vertical separation. // Example menu string: "Menu1 \t Menu2 \t Menu3 \n Menu4" // Note: URL encoding is not performed for menu options. Avoid '#' and '&' or use pre-encoded URLs. ``` -------------------------------- ### Time Utilities Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Functions for retrieving and checking the bot's time status. Includes getting current time with GMT offset and checking if the time is synchronized. ```cpp FB_Time getTime(int16_t gmt); bool timeSynced(); uint32_t getUnix(); // FB_Time structure uint8_t second; uint8_t minute; uint8_t hour; uint8_t day; uint8_t month; uint8_t dayWeek; uint16_t year; String timeString(); String dateString(); ``` -------------------------------- ### Real-Time Watch Functions Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Provides functions to get the current Unix time and check if the time synchronization is active. It also allows retrieving time in a custom format. ```cpp uint32_t getunix (); // Returns the current time in Unix format or 0 if time is not synchronized. Bool Timesynced (); // Returns true if the clock is synchronized. fb_time gettime (GMT); // Retrieves the current time based on the provided GMT offset. ``` -------------------------------- ### Fastbot Initialization Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Demonstrates how to initialize the Fastbot library. You can create a Fastbot object or initialize it with a specific token. ```cpp Fastbot Bot; FASTBOT BOT (token); ``` -------------------------------- ### FastBot Initialization Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Demonstrates how to initialize the FastBot library, either with a default constructor or by providing the bot token directly. ```cpp FastBot bot; FastBot bot(токен); // с указанием токена ``` -------------------------------- ### Restarting ESP by Command Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Demonstrates how to restart the ESP microcontroller via a bot command. It includes a method to ensure the message is marked as read before restarting to prevent boot loops. ```cpp bool res = 0; void message(FB_msg &msg) { if (msg.text == "restart") res = 1; } void loop() { bot.tick(); if (res) { bot.tickManual(); // Чтобы отметить сообщение прочитанным ESP.restart(); } } ``` -------------------------------- ### Creating and Sending Menus Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Explains how to format and send different types of menus. Includes conventional menus, inline menus, and inline menus with callbacks. Special characters like '\t' for horizontal and '\n' for vertical separation are used. ```CPP ShowMenu("menu1 \t menu2 \t menu3 \n menu4"); ``` ```CPP Inlinemenu("Mymenu", "Menu1 \t Menu2 \t Menu3 \n Menu4"); ``` ```CPP String menu1 = f("menu 1 \t menu 2 \t menu 3 \n back"); String CBACK1 = F("Action1, Action2, Action3, Back"); Bot.inlineMenucallback("Menu 1", menu1, CBACK1); ``` -------------------------------- ### Fastbot Configuration Functions Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Functions to configure the Fastbot, including setting the bot token, chat IDs, polling period, message limits, buffer sizes, and skipping updates. ```CPP VOID SetToken (String Token); VOID SetChatid (String Chatid); VOID SetChatid (Int64_T ID); VOID setperiod (intration); VOID SetLimit (int limit); VOID SetBuffersizes (Uint16_T RX, UINT16_T TX); VOID Skipupdates (); VOID settextmode (Uint8_t Mode); VOID Notify (Bool Mode); VOID CLEARSERVICEMESSAGES (BOOL STATE); ``` -------------------------------- ### Text Formatting with Markdown Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Demonstrates how to set the text mode to Markdown v2 and send formatted messages including bold, strikethrough, code, and links. ```cpp Bot.Settextmode (fb_markdown); BOT.SENDMESSAGE ("*Bold*, ~ Strike ~,` Code`, [Alexgyver.ru] (https://alexgyver.ru/)"); ``` -------------------------------- ### Real-Time Clock Functions Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Provides functions to get the current Unix time and check if the time is synchronized. It also allows retrieving the current time based on a provided timezone offset. ```cpp uint32_t getUnix(); bool timeSynced(); FB_Time getTime(int gmt); // Example usage: FB_Time t = bot.getTime(3); FB_Time t(bot.getUnix(), 3); ``` -------------------------------- ### Processing Message Timestamp Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Demonstrates how to use the `unix` field from the `FB_msg` structure to get the message's timestamp. This Unix timestamp is then used to create an `FB_Time` object, allowing for formatted time and date output. ```cpp void newMsg(FB_msg& msg) { FB_Time t(msg.unix, 3); // Initialize with message's unix time and timezone (e.g., UTC+3) Serial.print(t.timeString()); Serial.print(' '); Serial.println(t.dateString()); } ``` -------------------------------- ### Formatted Time and Date Output Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Shows how to get formatted time and date strings from an `FB_Time` object. The `timeString()` method returns the time in HH:MM:SS format, and `dateString()` returns the date in DD.MM.YYYY format. ```cpp // Assuming 't' is an FB_Time object: // Serial.print(t.timeString()); // Outputs time like HH:MM:SS // Serial.print(' '); // Serial.println(t.dateString()); // Outputs date like DD.MM.YYYY ``` -------------------------------- ### FastBot Methods and Functions Source: https://github.com/gyverlibs/fastbot/blob/main/keywords.txt Lists the available methods and functions for interacting with the FastBot, including chat management, message sending, editing, and time synchronization. ```APIDOC Methods and Functions: setChatID setPeriod setLimit skipUpdates attach detach tickManual tick sendMessage sendSticker deleteMessage editMessage editMenu editMenuCallback showMenu showMenuText closeMenu closeMenuText inlineMenu inlineMenuCallback sendRequest autoIncrement incrementID chatIDs setToken setBufferSizes answer lastBotMsg lastUsrMsg setTextMode replyMessage notify sendCommand setChatTitle setChatDescription clearServiceMessages pinMessage unpinMessage unpinAll update updateFS sendFile editFile downloadFile timeSynced getTime getUnix messageID userID username chatID text replyText data query edited isBot OTA unix isFile fileName fileUrl toString second minute hour day month dayWeek year timeString dateString FB_unicode FB_urlencode FB_str64 FB_64str ``` -------------------------------- ### Responding to Callbacks Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Details how to respond to inline button presses using the ANSWER() function. Supports pop-up notifications and warning windows. Responses must be within the message processor. ```CPP VOID NewMSG (FB_MSG & MSG) { if (msg.query) Bot.answer ("Hello!", True); } ``` -------------------------------- ### Gzip Binary Compression for OTA Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Allows compressing firmware files using gzip for smaller upload sizes. The compressed file should have a '.bin.gz' extension. The ATOMIC_FS_UPDATE macro must be defined in the firmware before including libraries. ```cpp #define ATOMIC_FS_UPDATE // Send file with .bin.gz extension ``` -------------------------------- ### OTA Firmware Update Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Enables Over-The-Air (OTA) firmware updates via chat by sending a binary file (.bin). The library handles the update process and reports the status. ```cpp // Update if you just sent a bin file if (msg.ota) BOT.UPDATE (); // Update if the file has the desired signature if (msg.ota && msg.text == "update") BOT.UPDATE (); // Update if the file has the right name if (msg.ota && msg.filename == "update.bin") Bot.update (); // Update if a famous person has sent (admin) if (msg.ota && msg.chatid == "123456") BOT.UPDATE (); ``` -------------------------------- ### Download File Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Downloads a file from a URL provided in an incoming message. Requires a file system library and writes the file to internal memory. ```cpp VOID NewMSG (FB_MSG & MSG) { if (msg.ismfile) {// This is a file Serial.print ("downloading"); Serial.println (msg.filename); String Path = '/' + MSG.FileName;// Path of the species /Filename.xxx File F = Littlefs.open (Path, "W");// Open for recording Bool Status = Bot.DownLoadfile (F, MSG.Fileurl);// Download Serial.println (status? "OK": "error");// Status } } ``` -------------------------------- ### Firmware Update Functions Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Functions to initiate Over-The-Air (OTA) updates for the firmware and the SPIFFS filesystem. ```c++ // ================ Main ========================ward uint8_t update();// Ota update of the firmware, call a message from the OTA flag inside the processor uint8_t updatefs();// Ota update SPIFFS, call a message from the OTA flag inside the processor ``` -------------------------------- ### Fastbot Performance Comparison Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Compares the performance and memory usage of Fastbot against the Universal-Arduino-Telegram-Bot library, highlighting differences in Flash, SRAM, message sending, and update times. ```c++ |Library |Flash, b |Sram, b|SEND, MS |update, ms |free heap, b | | ----------- | ---------- | --------- | ----------- | ---------------- | ------------- | |Univ..bot |400004 |29848 |2000 |1900 |38592 | |Fastbot |393220 |28036 |70 |70 |37552 | |Diff |6784 |1812 |1930 |1830 |1040 | // Fastbot processes the chat much faster and sends messages (for 2 seconds) due to manual parsing of the server response and statically allocated http customers // When activating `fb_dynamic`, the library will occupy 10 kb less memory, but it will work more slowly: // - Free Heap: 48000 Kb // - Sending message: 1 second // - Refresh Request: 1 second ``` -------------------------------- ### Standard Menu Implementation Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Demonstrates how to display a standard menu at the bottom of the chat window. When a button is pressed, the text on the button is sent as the message text. ```cpp showMenu("Menu1 \t Menu2 \t Menu3 \n Menu4"); // Pressing a button sends the button text as the message text (msg.text). ``` -------------------------------- ### Callback Handling Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Function signature for handling callback queries from inline keyboards. ```cpp uint8_t editMenuCallback(int32_t msgid, String menu, String cback); uint8_t editMenuCallback(int32_t msgid, String menu, String cback, String id); ``` -------------------------------- ### Time Module Usage Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Illustrates the usage of the fb_time data type for handling time. Shows how to create a fb_time object from a Unix timestamp and timezone, and how to format time and date strings. ```CPP Fb_time t (1651694501, 3); Serial.print (T.Hour); Serial.print (':'); Serial.print (T.Minute); Serial.print (':'); Serial.print (T.Second); Serial.print (''); Serial.print (t.day); Serial.print (':'); Serial.print (T.MONTH); Serial.print (':'); Serial.println (t.year); ``` ```CPP Serial.print (t.timestring ()); Serial.print (''); Serial.println (T.Datestestring ()); ``` -------------------------------- ### Sending Stickers Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Demonstrates how to send stickers using the SENSTICKER() function. Requires obtaining the sticker ID from a dedicated bot. ```CPP SENSTICKER(sticker_id); ``` -------------------------------- ### Inline Menu with Callback Data Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Explains how to create an inline menu where each button can have unique callback data. This data is sent along with the menu name when the button is pressed. If the callback data is an HTTP/HTTPS URL, the button becomes a link. ```cpp String menu1 = F("Menu 1 \t Menu 2 \t Menu 3 \n Back"); String cback1 = F("action1,action2,action3,back"); bot.inlineMenuCallback("Menu 1", menu1, cback1); // Pressing a button sends the menu name (msg.text) and the specified callback data (msg.data). // If callback data is a URL (http/https), the button becomes a link. ``` -------------------------------- ### Fastbot Ordinary Menu with Text Functions Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Functions to display a message along with an ordinary menu, with options for single or multiple chats, and for menus that close upon selection. ```CPP uint8_t showmenutext (String MSG, String Menu); uint8_t showmenutext (String MSG, String Menu, String ID); uint8_t showmenutext (String MSG, String Menu, True); uint8_t showmenutext (String MSG, String Menu, String ID, True); Uint8_T Closemenutext (String MSG); uint8_t Closemenutext (String MSG, String ID); ``` -------------------------------- ### Configuration Defines Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Defines to configure library behavior, such as disabling Unicode conversion, URL encoding, or OTA updates, and enabling dynamic memory mode or location features. These should be declared before including the library. ```cpp #define FB_NO_UNICODE #define FB_NO_URLENCODE #define FB_NO_OTA #define FB_DYNAMIC #define FB_WITH_LOCATION ``` -------------------------------- ### FastBot Configuration Defines Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Allows customization of FastBot library features via preprocessor directives. Options include disabling Unicode, URL encoding, OTA updates, and enabling dynamic memory mode or location fields. ```cpp #define FB_NO_UNICODE // disable Unicode conversion for incoming messages #define FB_NO_URLENCODE // disable urlencode conversion for outgoing messages #define FB_NO_OTA // disable support for OTA updates from chat #define FB_DYNAMIC // enable dynamic mode: reduces SRAM usage at the cost of execution time #define FB_WITH_LOCATION // enable location fields in message (FB_msg) ``` -------------------------------- ### Fastbot API Documentation Source: https://github.com/gyverlibs/fastbot/blob/main/README.md API reference for the Fastbot library, detailing functions for time management, OTA updates, text formatting, and file operations. ```APIDOC Fastbot Library API: Time Functions: uint32_t getUnix() - Returns the current time in Unix format. - Returns 0 if time is not synchronized. bool timeSynced() - Returns true if the time is synchronized, false otherwise. FB_Time getTime(int gmt) - Returns the current time structure based on the provided GMT offset. - Parameters: - gmt: Timezone offset from GMT. - Returns: FB_Time structure containing year, month, day, hour, minute, second. FB_Time(uint32_t unixTime, int gmt) - Constructor for FB_Time using Unix timestamp and GMT offset. OTA Update Functions: void update() - Initiates an Over-The-Air firmware update. - Triggered when a .bin file is received and msg.OTA is true. void updateFS() - Initiates an Over-The-Air SPIFFS update. - Triggered when a file with 'spiffs' in its name is received and msg.OTA is true. Text Formatting: void setTextMode(int mode) - Sets the text formatting mode for messages. - Parameters: - mode: FB_TEXT (plain), FB_MARKDOWN (Markdown v2), FB_HTML (HTML). - Note: Markdown v2 has limitations with characters !, +, #. File Sending: void sendMessage(const char* message, ...) - Sends a message to the chat. Formatting depends on the current text mode. void sendMessage(const String &message, ...) - Overloaded version for sending String objects. void sendFile(const String &fileName, const String &filePath, int type) - Sends a file from SPIFFS. - Parameters: - fileName: The name of the file as it should appear in Telegram. - filePath: The path to the file in SPIFFS. - type: The type of file (e.g., FB_PHOTO, FB_DOC, FB_AUDIO, FB_VIDEO, FB_GIF, FB_VOICE). void sendFile(const String &fileName, const uint8_t* buffer, size_t bufferSize, int type) - Sends a file from a memory buffer. - Parameters: - fileName: The name of the file as it should appear in Telegram. - buffer: Pointer to the file data in memory. - bufferSize: Size of the file data in bytes. - type: The type of file (e.g., FB_PHOTO, FB_DOC, FB_AUDIO, FB_VIDEO, FB_GIF, FB_VOICE). File Type Constants: FB_PHOTO FB_AUDIO FB_DOC FB_VIDEO FB_GIF FB_VOICE Message Object Properties (used in update triggers): bool OTA - True if the received message contains a .bin file. String text - Text content of the message, can include signatures for updates. String fileName - Name of the attached file. String chatID - ID of the chat where the message originated. ``` -------------------------------- ### Inline Menu Implementation Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Shows how to create an inline menu that appears within a message. This requires specifying a menu name, which is sent as the message text when a button is pressed. ```cpp inlineMenu("MyMenu", "Menu1 \t Menu2 \t Menu3 \n Menu4"); // Pressing a button sends the menu name (msg.text) and the button text (msg.data). ``` -------------------------------- ### Fastbot Inline Menu with Callback Functions Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Functions to display and edit inline menus with callback data, allowing for interactive elements. ```CPP Uint8_T Inlinemenucallback (String MSG, String Menu, String CBCK); Uint8_T Inlinemenucallback (String MSG, String Menu, String CBCK, String ID); uint8_t edItmenucallback (Int32_T MSGID, String Menu, String CBACK); uint8_t editMenucallback (Int32_T MSGID, String Menu, String CBACK, String ID); ``` -------------------------------- ### Fastbot Library Features Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md This snippet outlines the core functionalities of the Fastbot library, including message management, chat interactions, formatting options, and real-time features. ```c++ // Optional "White List" ID Chats // Checking updates manually or by timer // Sending/Removing/editing/response to messages // Reading and sending in chats, groups, channels // Changing the name and description of the chat // Consolidation/reinforcement of messages // Sending stickers // Markdown/html formatting messages // Conclusion of a conventional menu // Conclusion Inline menu with support for buttons-lits // Support Unicode (other languages + emoji) for incoming messages // Built-in Urlencode for outgoing messages // Built-in hours of real time with synchronization from the Telegram server // The possibility of OTA updating the firmware .bin with a Telegram chat file (Firmware and Spiffs) // Sending files from memory to chat (+ editing) ``` -------------------------------- ### Fastbot Text with Standard Menus Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Combines sending text messages with standard menus. This includes showing menus with text, one-time menus with text, and closing menus with associated text. ```cpp // ======== ОБЫЧНОЕ МЕНЮ С ТЕКСТОМ ========= // сообщение (msg) + показать меню (menu) в указанном в setChatID чате/чатах ИЛИ передать id чата/чатов uint8_t showMenuText(String msg, String menu); uint8_t showMenuText(String msg, String menu, String id); // единоразовое меню (закроется при выборе) uint8_t showMenuText(String msg, String menu, true); uint8_t showMenuText(String msg, String menu, String id, true); // сообщение (msg) + скрыть меню в указанном в setChatID чате/чатах ИЛИ передать id чата/чатов uint8_t closeMenuText(String msg); uint8_t closeMenuText(String msg, String id); ``` -------------------------------- ### Bug Reporting and Feedback Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Guidelines for reporting bugs and providing feedback for the Fastbot library. This includes creating issues, contacting the developer, and providing necessary information for effective bug resolution. ```en To report bugs or provide feedback: 1. **Create an Issue**: When you find bugs, please create an issue on the project's repository. 2. **Direct Contact**: For immediate assistance or detailed feedback, you can reach out via email at [alex@alexgyver.ru](mailto:alex@alexgyver.ru). 3. **Pull Requests**: The library welcomes contributions and refinements through pull requests. When reporting bugs or incorrect behavior, please include the following information: * **Library Version**: Specify the exact version of the Fastbot library you are using. * **Microcontroller**: Indicate the microcontroller (MK) being used. * **SDK Version**: For ESP microcontrollers, provide the SDK version. * **Arduino IDE Version**: State the version of the Arduino IDE. * **Example Functionality**: Confirm whether the built-in examples work correctly. If not, specify which ones and how they are used in your code. * **Expected vs. Actual Behavior**: Describe what you expected the code to do and what actually happened. * **Minimal Reproducible Code**: Provide a minimal code snippet that demonstrates the bug. Avoid submitting large, complex codebases; focus on the essential parts that trigger the issue. ``` -------------------------------- ### Fastbot Ordinary Menu Functions Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Functions to display and hide ordinary menus, with options for single or multiple chats, and for menus that close upon selection. ```CPP uint8_t showmenu (string menu); uint8_t showmenu (String Menu, String ID); uint8_t showmenu (string menu, true); uint8_t showmenu (string menu, string id, true); uint8_t closemenu (); Uint8_t Closemenu (String ID); ``` -------------------------------- ### Sending Files from Memory Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Enables sending files directly from memory using a File object. Requires including a file system library like SPIFFS.h or LittleFS.h before FastBot. ```cpp uint8_t sendFile(File &file, FB_FileType type, const String& name, const String& id); uint8_t editFile(File &file, FB_FileType type, const String& name, int32_t msgid, const String& id); ``` -------------------------------- ### File Download and Sending Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Functions for downloading files via URL and sending files from a buffer or a File object. Supports specifying file type and name, with overloads for chat ID. ```c++ // Download Chat file Bool DownloadFile(File &F, Const String &URL); // Send a file from the Buf byt Bufer Length, such as Type and the name of the NAME file in the SetChatid chat or transfer ID chat Uint8_t Sendfile(Uint8_t* Buf, Uint32_t Length, FB_FileType Type, Constation String &Name); Uint8_t Sendfile(Uint8_t* Buf, Uint32_t Length, FB_FileType Type, Constation String &Name, Constance String &ID); // Send a file file, such as Type and the name of the NAME file in the SetChatid chat or transfer ID chat Uint8_t Sendfile(File &File, FB_FileTYPE TYPE, COST String &NAME); Uint8_t Sendfile(File &File, FB_FileTYPE TYPE, COST String &NAME, COST String &ID); ``` -------------------------------- ### FastBot Core Functions Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Provides core functionalities for string manipulation and translation within the FastBot library. Includes Unicode translation, URL encoding, and integer/string conversions. ```cpp VOID FB_UNICODE (String & S); VOID fb_urlencode (String & S, String & Dest); Int64_T FB_STR64 (COST String & S); String fb_64str (int64_t ID); ``` -------------------------------- ### Parsing Incoming Messages with FastBot Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Explains how to process incoming messages using a callback function. The `Attach()` function registers a handler for messages, and the `fb_msg` structure contains details about the received message. ```cpp // Define a message processor function VOID NewMSG (FB_MSG & MSG) { // Process the message, e.g., print user ID and text //Serial.Print(MSG.USERNAME); //Serial.print (","); //Serial.println(MSG.TEXT); // Print all message information for debugging Serial.println (msg.tostring ()); } // In setup(): BOT.ATTACH (NewMSG); // Register the message processor ``` -------------------------------- ### Fastbot Library Version History Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md This section outlines the changes and improvements made in each version of the Fastbot library, from V1.0 to V2.26. It details new functionalities, optimizations, bug fixes, and specific platform support. ```en V1.0: Initial release V1.1: Optimization V1.2: Support for multiple Chat IDs and targeted sending V1.3: Added text customization for menu open/close V1.3.1: Fixed errors from V1.3 V1.4: Added message deletion functionality V1.5: Optimization, token change capability, new message parsing (ID, name, text) V1.5.1: Message ID retrieval added V1.6: Added FB_DYMIC_HTTP mode, user name reading V1.7: - Removed dynamic mode fb_dynamic_http due to slow performance - Corrected warnings - Fixed bot operation in 'Group' mode (negative chat ID) - Memory optimization - Performance acceleration - Fixed bot operation in 'Echo' script V2.0: - Removed 3200 ms delay - Added processing for Unicode (Russian, emoji) - Thanks to Gleb Zhukov! - Menu spacing improved for easier use - ESP32 support added - Significant optimization - Added collections to Inlinemenu - User ID added - Editing capabilities and more added V2.1: - Further optimization - Added text formatting (Markdown, HTML) - Added message reply functionality V2.2: - Major memory and performance optimization - Added notify() for bot message notifications - Added one-time keyboard display V2.3: Minor optimization V2.4: Added URL Encode for message text V2.5: Added flags to fb_MSG: message edited status and bot-sent message status. Improved text parsing. V2.6: Added built-in real-time clock V2.7: Added sticker sending V2.8: Removed extra conclusion to series, GMT can be in minutes V2.9: Fixed parsing bug, accelerated parsing, added formatted time output, added surname and message time V2.10: Added functions to change chat name and description, message consolidation and reinforcement. Removed EDIT/DeleteMessageid, EDIDITMENUID V2.11: - Optimization, bug correction - Callback Data parsed separately in Data - Callback work refactored - Added toostring() for fb_msg for debugging - Callback added to URL address processing - Removed FIRST_NAME and LAST_NAME (with legacy preservation) - Usrid and ID renamed to userid and Messageid (with legacy preservation) - Old incoming message handler removed V2.12: Examples adjusted, ISBOT parsing fixed, protection mechanism against long messages redone, initialization redone. V2.13: Memory optimization. Added OTA update. V2.14: Improved lines with IDs, added OTA shutdown, added parsing of group/channel name in username. v2.15: Patch for ESP32 library curve. V2.16: Added Filename output, indispensable messages in MarkDown are filmed. v2.17: Output of message text to which user responded + correct work with Menu in groups. v2.17.1: Small fix https://github.com/gyverlibs/fastbot/issues/12 V2.18: Added FB_dynamic mode: library executes requests longer but uses 10 KB less SRAM. V2.19: OTA support with GZIP compression. V2.20: - Added OTA SPIFFS + Example - Added output of file URL for downloading from chat + example - Added ability to download files from chat - Added ability to send files (from spiffs or buffer) + example - Added ability to edit files (from spiffs or buffer) - Added example of sending a photo from ESP32-CAM camera V2.21: Accelerated file sending to chat. V2.22: Minor optimization, corrected compilation error at define fb_no_ota. V2.23: Completed real-time source for EditMessage. V2.24: Fix for sending large files https://github.com/gyverlibs/fastbot/pull/17 V2.25: Added Skipupdates - passing unread messages. V2.26: Fix for incorrect display of numbers after Russian letters https://github.com/gyverlibs/fastbot/pull/37 ``` -------------------------------- ### Bug Reporting and Feedback Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Guidelines for reporting bugs and providing feedback for the FastBot library, including necessary information and preferred methods of contact. ```APIDOC Bug Reporting and Feedback: - Report bugs by creating an 'Issue' on GitHub or by emailing alex@alexgyver.ru. - The library is open for contributions and Pull Requests. When reporting bugs, please include: - Library version - Microcontroller used - SDK version (for ESP) - Arduino IDE version - Whether built-in examples work correctly with the functions causing the bug. - The code used, the expected behavior, and the actual behavior. - Ideally, provide minimal reproducible code. ``` -------------------------------- ### Fastbot Compatibility Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Specifies the hardware compatibility for the Fastbot library, indicating the required SDK versions for ESP8266 and ESP32. ```c++ // ESP8266 (SDK V2.6+), ESP32 ``` -------------------------------- ### Answering Callbacks Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Details how to respond to inline menu button presses. A callback triggers the `query` flag in the message handler. You can send a notification or an alert message using `answer()`. It's crucial to respond within the message handler. ```cpp void newMsg(FB_msg& msg) { if (msg.query) bot.answer("Hello!", true); // true for notification // Alternatively, for an alert: // if (msg.query) bot.answer("Warning!", false); // false for alert } // If no answer is provided, the library sends an empty response. ``` -------------------------------- ### Fastbot Configuration Settings Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Configures the Fastbot instance, including setting API tokens, chat IDs, polling periods, message limits, buffer sizes, and text modes. It also allows skipping updates and controlling bot notifications. ```cpp // ============== НАСТРОЙКИ ============== void setToken(String token); // изменить/задать токен бота void setChatID(String chatID); // установка ID чата (белый список), необязательно. Можно несколько через запятую ("id1,id2,id3") void setChatID(int64_t id); // то же самое, но в int64_t. Передай 0, чтобы отключить void setPeriod(int period); // период опроса в мс (по умолч. 3500) void setLimit(int limit); // кол-во сообщений, которое обрабатывается за один запрос, 1..100. (по умолч. 10) void setBufferSizes(uint16_t rx, uint16_t tx); // установить размеры буфера на приём и отправку, по умолч. 512 и 512 байт (только для esp8266) void skipUpdates(); // пропустить непрочитанные сообщения void setTextMode(uint8_t mode); // режим текста "для отправки": FB_TEXT, FB_MARKDOWN, FB_HTML (см. пример textMode) void notify(bool mode); // true/false вкл/выкл уведомления от сообщений бота (по умолч. вкл) void clearServiceMessages(bool state); // удалять из чата сервисные сообщения о смене названия и закреплении сообщений (умолч. false) ``` -------------------------------- ### Utility Functions Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Utility functions for string manipulation, including Unicode conversion, URL encoding, and string-to-integer conversions. ```cpp void FB_unicode(String &s); void FB_urlencode(String& s, String& dest); int64_t FB_str64(const String &s); String FB_64str(int64_t id); ``` -------------------------------- ### Processing Incoming Message Time Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Demonstrates how to process the Unix timestamp from an incoming message using the fb_time structure to display a formatted time and date. ```CPP VOID NewMSG (FB_MSG & MSG) { Fb_time t (msg.unix, 3); Serial.print (t.timestring ()); Serial.print (''); Serial.println (T.Datestestring ()); } ``` -------------------------------- ### Sending Messages with FastBot Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Demonstrates how to send messages using the FastBot library. Messages can be sent to single or multiple chat IDs, either directly in the send function or by setting a default chat ID using `setChatid()`. ```cpp // Sending to one chat BOT.SENDMESSAGE ("Hello!", "123456"); // Sending to multiple chats BOT.SENDMESSAGE ("Hello!", "123456,7891011"); // Setting default chat ID BOT.SETChatid ("123456"); BOT.SENDMESSAGE ("HELLO!"); // Will go to "123456" BOT.SENDMESSAGE ("Hello!", "112233"); // Will go to "112233" ``` -------------------------------- ### Fastbot Inline Menus with Callback Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Allows sending inline menus with associated callback data and editing them. This is used for interactive elements where user actions trigger specific responses. ```cpp // ======= ИНЛАЙН МЕНЮ С КОЛЛБЭКОМ ======= // сообщение (msg) с инлайн меню (menu) и коллбэком (cbck) в указанном в setChatID чате/чатах ИЛИ передать id чата/чатов uint8_t inlineMenuCallback(String msg, String menu, String cbck); uint8_t inlineMenuCallback(String msg, String menu, String cbck, String id); // редактировать меню (msgid) текстом (menu) и коллбэком (cback) в указанном в setChatID чате ИЛИ передать id чата ``` -------------------------------- ### OTA Firmware Update Source: https://github.com/gyverlibs/fastbot/blob/main/README.md Enables Over-The-Air (OTA) firmware updates via chat messages. Supports updating the main firmware and SPIFFS. Requires the firmware to be compiled into a .bin file and sent to the bot. The update process can be triggered based on various conditions like file name, text signature, or sender ID. ```cpp // Update firmware if a .bin file is received if (msg.OTA) bot.update(); // Update firmware if the file has a specific signature if (msg.OTA && msg.text == "update") bot.update(); // Update firmware if the file has a specific name if (msg.OTA && msg.fileName == "update.bin") bot.update(); // Update firmware if sent by an authorized user if (msg.OTA && msg.chatID == "123456") bot.update(); // Update SPIFFS if the filename contains 'spiffs' if (msg.OTA && msg.fileName.indexOf("spiffs") > 0) bot.updateFS(); ``` -------------------------------- ### Send File from Buffer Source: https://github.com/gyverlibs/fastbot/blob/main/README_EN.md Sends a file from a buffer. Requires buffer, size, file type, name, and chat ID. For editing, a message ID is also needed. ```cpp Uint8_t Sendfile (Uint8_t* Buf, Uint32_t Length, FB_FileType Type, Constation String & Name, Constance String & ID); Uint8_t Editfile (Uint8_t* Buf, Uint32_T Length, FB_FileType Type, Constation String & Name, Int32_T MSGID, COST String & ID); ```