### Install Java Runtime Environment Source: https://core.telegram.org/bots/tutorial Install the OpenJDK 17 JRE on your server to run Java applications. Verify the installation by checking the Java version. ```bash $ apt install openjdk-17-jre $ java -version ``` -------------------------------- ### Example Bot Management Link Source: https://core.telegram.org/bots/features An example of a bot management link, demonstrating how to pre-fill the username and display name for a new bot. ```text https://t.me/newbot/ManagerBot/CoolAIAgentBot?name=Cool+AI+Agent ``` -------------------------------- ### Windows Certificate Template Example Source: https://core.telegram.org/bots/webhooks An example configuration file for the Windows certreq utility to generate a new certificate request. ```ini [NewRequest] Subject = "CN=DOMAIN.EXAMPLE" KeyLength = 2048 KeyAlgorithm = RSA HashAlgorithm = sha256 ;MachineKeySet = true RequestType = Cert UseExistingKeySet=false ;generates a new private key (for export) Exportable = true ;makes the private key exportable with the PFX ``` -------------------------------- ### Example User-Agent String Source: https://core.telegram.org/bots/webapps An example of the User-Agent string format used on Android, including specific values for app version, device model, OS version, SDK, and performance class. ```text Mozilla/5.0 (Linux; Android 14; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.5672.136 Mobile Safari/537.36 Telegram-Android/11.3.3 (Google sdk_gphone64_arm64; Android 14; SDK 34; LOW) ``` -------------------------------- ### DeviceOrientationStartParams Source: https://core.telegram.org/bots/webapps Parameters for starting device orientation tracking. ```APIDOC ## DeviceOrientationStartParams ### Description This object defines the parameters for starting device orientation tracking. ### Parameters - **refresh_rate** (Integer) - _Optional._ The refresh rate in milliseconds, with acceptable values ranging from 20 to 1000. Set to _1000_ by default. Note that _refresh_rate_ may not be supported on all platforms, so the actual tracking frequency may differ from the specified value. - **need_absolute** (Boolean) - _Optional._ Pass _true_ to receive absolute orientation data, allowing you to determine the device's attitude relative to magnetic north. Use this option if implementing features like a compass in your app. If relative data is sufficient, pass _false_. Set to _false_ by default. **Note:** Keep in mind that some devices may not support absolute orientation data. In such cases, you will receive relative data even if _need_absolute=true_ is passed. Check the _DeviceOrientation.absolute_ parameter to determine whether the data provided is absolute or relative. ``` -------------------------------- ### Example API Request URL Source: https://core.telegram.org/bots/api This is an example of a GET request URL to the Telegram Bot API for the getMe method. Replace '' with your actual bot token. ```http https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/getMe ``` -------------------------------- ### GyroscopeStartParams Source: https://core.telegram.org/bots/webapps Parameters for starting gyroscope tracking. ```APIDOC ## GyroscopeStartParams ### Description This object defines the parameters for starting gyroscope tracking. ### Parameters - **refresh_rate** (Integer) - _Optional._ The refresh rate in milliseconds, with acceptable values ranging from 20 to 1000. Set to _1000_ by default. Note that _refresh_rate_ may not be supported on all platforms, so the actual tracking frequency may differ from the specified value. ``` -------------------------------- ### Windows Certificate Request Template Source: https://core.telegram.org/bots/self-signed Example configuration for a certificate request using Windows certreq. ```ini [NewRequest] ; At least one value must be set in this section Subject = "CN=DOMAIN.EXAMPLE" KeyLength = 2048 KeyAlgorithm = RSA HashAlgorithm = sha256 ;MachineKeySet = true RequestType = Cert UseExistingKeySet=false ;generates a new private key (for export) Exportable = true ;makes the private key exportable with the PFX ``` -------------------------------- ### AccelerometerStartParams Source: https://core.telegram.org/bots/webapps Defines the parameters for starting accelerometer tracking. ```APIDOC ## AccelerometerStartParams This object defines the parameters for starting accelerometer tracking. ### Fields - **refresh_rate** (Integer): _Optional._ The refresh rate in milliseconds, with acceptable values ranging from 20 to 1000. Set to `_1000_` by default. Note that `_refresh_rate_` may not be supported on all platforms, so the actual tracking frequency may differ from the specified value. ``` -------------------------------- ### getMyShortDescription Source: https://core.telegram.org/bots/api Gets the current bot short description for the given user language. Returns BotShortDescription on success. ```APIDOC ## getMyShortDescription ### Description Use this method to get the current bot short description for the given user language. Returns BotShortDescription on success. ### Method GET ### Endpoint /getMyShortDescription ### Parameters #### Query Parameters - **language_code** (String) - Optional - A two-letter ISO 639-1 language code or an empty string. ### Response #### Success Response (200) - **short_description** (BotShortDescription) - The current bot short description for the specified language. ``` -------------------------------- ### BusinessIntro Object Source: https://core.telegram.org/bots/api Contains information about the start page settings for a Telegram Business account, including title, message, and sticker. ```APIDOC ## BusinessIntro Object ### Description Contains information about the start page settings of a Telegram Business account. ### Fields - **title** (String) - Optional. Title text of the business intro. - **message** (String) - Optional. Message text of the business intro. - **sticker** (Sticker) - Optional. Sticker of the business intro. ``` -------------------------------- ### Run Telegram Bot Application Source: https://core.telegram.org/bots/tutorial Navigate to the bot's directory on the server and execute the JAR file using the `java -jar` command to start your Telegram bot. ```bash $ cd /bots/TBotRemote/ $ java -jar TutorialBot.jar ``` -------------------------------- ### Deep Linking to a Bot with a Start Parameter Source: https://core.telegram.org/bots/features Use this URL format to initiate a private chat with a bot and pass a custom parameter. The bot will receive this parameter as part of the /start command. ```url https://t.me/your_bot?start=airplane ``` -------------------------------- ### Implement Command Logic for State Change Source: https://core.telegram.org/bots/tutorial Process incoming commands to change the bot's state. This example shows how to toggle 'screaming' mode on or off using '/scream' and '/whisper' commands. ```java if(msg.isCommand()){ if(msg.getText().equals("/scream")) //If the command was /scream, we switch gears screaming = true; else if (msg.getText().equals("/whisper")) //Otherwise, we return to normal screaming = false; return; //We don't want to echo commands, so we exit } ``` -------------------------------- ### Bot Receives Start Parameter in Private Chat Source: https://core.telegram.org/bots/features When a user opens a deep link with a start parameter, the bot receives the command and the parameter in the following format. ```text /start airplane ``` -------------------------------- ### Loading Screen Customization Source: https://core.telegram.org/bots/webapps Instructions on how to customize the Mini App loading screen via @BotFather. ```APIDOC ## Loading Screen Customization ### Description Mini Apps can customize their loading screen with their own icon and specific colors for light and dark themes. ### Configuration Access these customization settings in @BotFather via the following path: _/mybots > Select Bot > Bot Settings > Configure Mini App > Enable Mini App_ ``` -------------------------------- ### Configure Bot Methods Source: https://core.telegram.org/bots/tutorial Implement these methods to provide your bot's username, token, and handle incoming updates. Replace placeholder values with your actual bot details. ```java @Override public String getBotUsername() { return "TutorialBot"; } @Override public String getBotToken() { return "4839574812:AAFD39kkdpWt3ywyRZergyOLMaJhac60qc"; } @Override public void onUpdateReceived(Update update) { System.out.println(update); } ``` -------------------------------- ### Import Root Certificate to Keystore using Java Keytool Source: https://core.telegram.org/bots/webhooks Import a root certificate into a Java keystore. This is a prerequisite for exporting it in PEM format. ```bash keytool -import -alias Root -keystore YOURKEYSTORE.JKS -trustcacerts -file ROOTCERT.CER ``` -------------------------------- ### addToHomeScreen() Source: https://core.telegram.org/bots/webapps Prompts the user to add the Mini App to their home screen. ```APIDOC ## addToHomeScreen() ### Description Bot API 8.0+ A method that prompts the user to add the Mini App to the home screen. After successfully adding the icon, the `homeScreenAdded` event will be triggered if supported by the device. Note that if the device cannot determine the installation status, the event may not be received even if the icon has been added. ### Method Function ``` -------------------------------- ### getStickerSet Source: https://core.telegram.org/bots/api Use this method to get a sticker set. On success, a StickerSet object is returned. ```APIDOC ## GET /getStickerSet ### Description Retrieves a sticker set by its name. On success, a StickerSet object is returned. ### Method GET ### Endpoint /getStickerSet ### Parameters #### Path Parameters None #### Query Parameters - **name** (String) - Yes - Name of the sticker set #### Request Body None ### Request Example ```json { "name": "MyStickers" } ``` ### Response #### Success Response (200) - **StickerSet** (Object) - The StickerSet object. #### Response Example ```json { "ok": true, "result": { "name": "MyStickers", "title": "My Awesome Stickers", "is_animated": false, "is_video": false, "stickers": [ { "width": 512, "height": 512, "is_animated": false, "file_id": "CAACAgIAAxkBAAEh..." } ] } } ``` ``` -------------------------------- ### checkHomeScreenStatus([callback]) Source: https://core.telegram.org/bots/webapps Checks if adding to the home screen is supported and if the Mini App has already been added. ```APIDOC ## checkHomeScreenStatus([callback]) ### Description Bot API 8.0+ A method that checks if adding to the home screen is supported and if the Mini App has already been added. If an optional _callback_ parameter is provided, the _callback_ function will be called with a single argument _status_ , which is a string indicating the home screen status. Possible values for _status_ are: - **unsupported** – the feature is not supported, and it is not possible to add the icon to the home screen. ### Method Function ### Parameters #### Path Parameters - **callback** (Function) - Optional - A callback function to handle the status. ``` -------------------------------- ### Inspect Certificate with OpenSSL Source: https://core.telegram.org/bots/webhooks Use OpenSSL to view the details of a downloaded certificate file. ```bash openssl x509 -in yourdomain.crt -text -noout ``` -------------------------------- ### App Lifecycle Management Source: https://core.telegram.org/bots/webapps Methods for managing the Mini App's readiness and lifecycle. ```APIDOC ## ready() ### Description Informs the Telegram app that the Mini App is ready to be displayed. It is recommended to call this method as early as possible. Once called, the loading placeholder is hidden and the Mini App is shown. If not called, the placeholder is hidden only when the page is fully loaded. ### Method Function ### Parameters None ### Response None ``` ```APIDOC ## expand() ### Description Expands the Mini App to the maximum available height. To check if the Mini App is expanded to the maximum height, refer to the `Telegram.WebApp.isExpanded` parameter. ### Method Function ### Parameters None ### Response None ``` ```APIDOC ## close() ### Description Closes the Mini App. ### Method Function ### Parameters None ### Response None ``` -------------------------------- ### Gyroscope API Source: https://core.telegram.org/bots/webapps Provides access to gyroscope data. You can start and stop tracking gyroscope data. ```APIDOC ## Gyroscope ### Description This object provides access to gyroscope data on the device. ### Methods #### start(params[, callback]) Bot API 8.0+ Starts tracking gyroscope data using _params_ of type GyroscopeStartParams. If an optional _callback_ parameter is provided, the _callback_ function will be called with a boolean indicating whether tracking was successfully started. #### stop([callback]) Bot API 8.0+ Stops tracking gyroscope data. If an optional _callback_ parameter is provided, the _callback_ function will be called with a boolean indicating whether tracking was successfully stopped. All these methods return the Gyroscope object so they can be chained. ### Properties - **isStarted** (Boolean) - Indicates whether gyroscope tracking is currently active. - **x** (Float) - The current rotation rate around the X-axis, measured in rad/s. - **y** (Float) - The current rotation rate around the Y-axis, measured in rad/s. - **z** (Float) - The current rotation rate around the Z-axis, measured in rad/s. ``` -------------------------------- ### requestFullscreen() Source: https://core.telegram.org/bots/webapps Requests to open the Mini App in fullscreen mode. ```APIDOC ## requestFullscreen() ### Description Bot API 8.0+ A method that requests opening the Mini App in fullscreen mode. Although the header is transparent in fullscreen mode, it is recommended that the Mini App sets the header color using the _setHeaderColor_ method. This color helps determine a contrasting color for the status bar and other UI controls. ### Method Function ``` -------------------------------- ### DeviceOrientation API Source: https://core.telegram.org/bots/webapps Provides access to device orientation data. You can start and stop tracking orientation. ```APIDOC ## DeviceOrientation ### Description This object provides access to orientation data on the device. ### Methods #### start(params[, callback]) Bot API 8.0+ Starts tracking device orientation data using _params_ of type DeviceOrientationStartParams. If an optional _callback_ parameter is provided, the _callback_ function will be called with a boolean indicating whether tracking was successfully started. #### stop([callback]) Bot API 8.0+ Stops tracking device orientation data. If an optional _callback_ parameter is provided, the _callback_ function will be called with a boolean indicating whether tracking was successfully stopped. All these methods return the DeviceOrientation object so they can be chained. ### Properties - **isStarted** (Boolean) - Indicates whether device orientation tracking is currently active. - **absolute** (Boolean) - A boolean that indicates whether or not the device is providing orientation data in absolute values. - **alpha** (Float) - The rotation around the Z-axis, measured in radians. - **beta** (Float) - The rotation around the X-axis, measured in radians. - **gamma** (Float) - The rotation around the Y-axis, measured in radians. ``` -------------------------------- ### getMyDescription Source: https://core.telegram.org/bots/api Gets the current bot description for the given user language. Returns BotDescription on success. ```APIDOC ## getMyDescription ### Description Use this method to get the current bot description for the given user language. Returns BotDescription on success. ### Method GET ### Endpoint /getMyDescription ### Parameters #### Query Parameters - **language_code** (String) - Optional - A two-letter ISO 639-1 language code or an empty string. ### Response #### Success Response (200) - **description** (BotDescription) - The current bot description for the specified language. ``` -------------------------------- ### getMyName Source: https://core.telegram.org/bots/api Gets the current bot name for the given user language. Returns BotName on success. ```APIDOC ## getMyName ### Description Use this method to get the current bot name for the given user language. Returns BotName on success. ### Method GET ### Endpoint /getMyName ### Parameters #### Query Parameters - **language_code** (String) - Optional - A two-letter ISO 639-1 language code or an empty string. ### Response #### Success Response (200) - **name** (BotName) - The current bot name for the specified language. ``` -------------------------------- ### getMyDefaultAdministratorRights Source: https://core.telegram.org/bots/api Use this method to get the current default administrator rights of the bot. Returns ChatAdministratorRights on success. ```APIDOC ## getMyDefaultAdministratorRights ### Description Use this method to get the current default administrator rights of the bot. ### Method GET (assumed, as it retrieves state) ### Endpoint /getMyDefaultAdministratorRights ### Parameters #### Query Parameters - **for_channels** (Boolean) - Optional - Pass True to get default administrator rights of the bot in channels. Otherwise, default administrator rights of the bot for groups and supergroups will be returned. ### Response #### Success Response (200) - **result** (ChatAdministratorRights) - The current default administrator rights object. ``` -------------------------------- ### getFile Source: https://core.telegram.org/bots/api Retrieves basic information about a file and prepares it for downloading. Bots can download files up to 20MB. A File object is returned on success, containing a link to download the file which is valid for at least 1 hour. ```APIDOC ## getFile ### Description Use this method to get basic information about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size. On success, a File object is returned. The file can then be downloaded via the link `https://api.telegram.org/file/bot/`, where `` is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile again. ### Parameters #### Path Parameters - **file_id** (String) - Yes - File identifier to get information about **Note:** This function may not preserve the original file name and MIME type. You should save the file's MIME type and name (if available) when the File object is received. ``` -------------------------------- ### Upload Bot Files to Server Source: https://core.telegram.org/bots/tutorial Use `scp` to recursively copy your bot's directory, including the executable JAR and database, to the remote server. Ensure the destination path exists. ```bash $ scp -r /TBot/ username@server_ip:/bots/TBotRemote/ ``` -------------------------------- ### Get Managed Bot Token Source: https://core.telegram.org/bots/api Retrieves the token of a managed bot. Returns the token as a String on success. ```APIDOC ## GET getManagedBotToken ### Description Use this method to get the token of a managed bot. Returns the token as _String_ on success. ### Method GET ### Endpoint /getManagedBotToken ### Parameters #### Path Parameters - **user_id** (Integer) - Required - User identifier of the managed bot whose token will be returned ``` -------------------------------- ### Main Method for Bot Initialization and Message Sending Source: https://core.telegram.org/bots/tutorial This main method initializes the Telegram bots API, registers your bot, and sends an initial "Hello World!" message. The 'L' suffix is crucial for specifying a Long literal. ```java public static void main(String[] args) throws TelegramApiException { TelegramBotsApi botsApi = new TelegramBotsApi(DefaultBotSession.class); Bot bot = new Bot(); //We moved this line out of the register method, to access it later botsApi.registerBot(bot); bot.sendText(1234L, "Hello World!"); //The L just turns the Integer into a Long } ``` -------------------------------- ### BusinessOpeningHoursInterval Object Source: https://core.telegram.org/bots/api Defines a time interval during which a business is open, specified by start and end minutes within a week. ```APIDOC ## BusinessOpeningHoursInterval Object ### Description Describes an interval of time during which a business is open. ### Fields - **opening_minute** (Integer) - The minute's sequence number in a week, starting on Monday, marking the start of the time interval during which the business is open; 0 - 7 * 24 * 60. - **closing_minute** (Integer) - The minute's sequence number in a week, starting on Monday, marking the end of the time interval during which the business is open; 0 - 8 * 24 * 60. ``` -------------------------------- ### Create InlineKeyboardButton Instances Source: https://core.telegram.org/bots/tutorial Create instances of InlineKeyboardButton to define button text, callback data for interaction, or URLs for external links. ```java var next = InlineKeyboardButton.builder() .text("Next").callbackData("next") .build(); var back = InlineKeyboardButton.builder() .text("Back").callbackData("back") .build(); var url = InlineKeyboardButton.builder() .text("Tutorial") .url("https://core.telegram.org/bots/api") .build(); ``` -------------------------------- ### getCustomEmojiStickers Source: https://core.telegram.org/bots/api Use this method to get information about custom emoji stickers by their identifiers. Returns an Array of Sticker objects. ```APIDOC ## GET /getCustomEmojiStickers ### Description Retrieves information about custom emoji stickers using their identifiers. Returns an Array of Sticker objects. ### Method GET ### Endpoint /getCustomEmojiStickers ### Parameters #### Path Parameters None #### Query Parameters - **custom_emoji_ids** (Array of String) - Yes - A JSON-serialized list of custom emoji identifiers. At most 200 custom emoji identifiers can be specified. #### Request Body None ### Request Example ```json { "custom_emoji_ids": ["5379032100000000000", "5379032100000000001"] } ``` ### Response #### Success Response (200) - **Array of Sticker** (Array) - An array of Sticker objects. #### Response Example ```json { "ok": true, "result": [ { "width": 512, "height": 512, "is_animated": false, "file_id": "CAACAgIAAxkBAAEh..." } ] } ``` ``` -------------------------------- ### Get Business Connection Source: https://core.telegram.org/bots/api Retrieves information about the connection of the bot with a business account. Returns a BusinessConnection object on success. ```APIDOC ## GET getBusinessConnection ### Description Use this method to get information about the connection of the bot with a business account. Returns a BusinessConnection object on success. ### Method GET ### Endpoint /getBusinessConnection ### Parameters #### Path Parameters - **business_connection_id** (String) - Required - Unique identifier of the business connection ``` -------------------------------- ### Get Managed Bot Access Settings Source: https://core.telegram.org/bots/api Retrieves the access settings of a managed bot. Returns a BotAccessSettings object on success. ```APIDOC ## GET getManagedBotAccessSettings ### Description Use this method to get the access settings of a managed bot. Returns a BotAccessSettings object on success. ### Method GET ### Endpoint /getManagedBotAccessSettings ### Parameters #### Path Parameters - **user_id** (Integer) - Required - User identifier of the managed bot whose access settings will be returned ``` -------------------------------- ### Import Intermediate Certificate into Java Keystore Source: https://core.telegram.org/bots/webhooks Use the `keytool` command to import an intermediate certificate into your Java keystore. This is necessary for Java applications that rely on a specific keystore for trust verification. ```bash keytool -import -trustcacerts -alias intermediate -file intermediate.pem -keystore YOURKEYSTORE.jks ``` -------------------------------- ### Send Text Message Update (Postman) Source: https://core.telegram.org/bots/webhooks This section mentions using Postman for sending updates but does not provide a specific code example. -------------------------------- ### View Certificates in Windows Store Source: https://core.telegram.org/bots/self-signed Displays certificates stored in the user's certificate store on Windows. ```bash certutil -store -user my ``` -------------------------------- ### getGameHighScores Source: https://core.telegram.org/bots/api Use this method to get data for high score tables. Will return the score of the specified user and several of their neighbors in a game. ```APIDOC ## getGameHighScores ### Description Use this method to get data for high score tables. Will return the score of the specified user and several of their neighbors in a game. Returns an Array of GameHighScore objects. > This method will currently return scores for the target user, plus two of their closest neighbors on each side. Will also return the top three users if the user and their neighbors are not among them. Please note that this behavior is subject to change. ### Method GET ### Endpoint /getGameHighScores ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **user_id** (Integer) - Yes - Target user id - **chat_id** (Integer) - Optional - Required if _inline_message_id_ is not specified. Unique identifier for the target chat. - **message_id** (Integer) - Optional - Required if _inline_message_id_ is not specified. Identifier of the sent message. - **inline_message_id** (String) - Optional - Required if _chat_id_ and _message_id_ are not specified. Identifier of the inline message. ### Request Example ```json { "user_id": 12345, "chat_id": 67890, "message_id": 54321 } ``` ### Response #### Success Response (200) - **Array of GameHighScore objects** - Score data for the user and their neighbors. #### Response Example ```json { "ok": true, "result": [ { "position": 1, "user": { "id": 12345, "is_bot": false, "first_name": "Test" }, "score": 100 }, { "position": 2, "user": { "id": 67890, "is_bot": false, "first_name": "AnotherUser" }, "score": 90 } ] } ``` ``` -------------------------------- ### Inspect Certificate with Java Keytool Source: https://core.telegram.org/bots/webhooks Use Java's keytool to print detailed information about a certificate. ```bash keytool -printcert -v -yourdomain.crt ``` -------------------------------- ### getMyCommands Source: https://core.telegram.org/bots/api Gets the current list of the bot's commands for the given scope and user language. Returns an Array of BotCommand objects. ```APIDOC ## getMyCommands ### Description Use this method to get the current list of the bot's commands for the given scope and user language. Returns an Array of BotCommand objects. ### Method GET ### Endpoint /getMyCommands ### Parameters #### Query Parameters - **scope** (BotCommandScope) - Optional - A JSON-serialized object, describing scope of users. Defaults to BotCommandScopeDefault. - **language_code** (String) - Optional - A two-letter ISO 639-1 language code or an empty string. ### Response #### Success Response (200) - **commands** (Array of BotCommand) - An array of BotCommand objects. If commands aren't set, an empty list is returned. ``` -------------------------------- ### Test Voice Message Update Source: https://core.telegram.org/bots/webhooks Send a voice message update to your bot's webhook. This example simulates a voice note being sent by a user. ```bash curl -v -k -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{ "update_id":10000, "message":{ "date":1441645532, "chat":{ "last_name":"Test Lastname", "type": "private", "id":1111111, "first_name":"Test Firstname", "username":"Testusername" }, "message_id":1365, "from":{ "last_name":"Test Lastname", "id":1111111, "first_name":"Test Firstname", "username":"Testusername" }, "voice": { "file_id": "AwADBAADbXXXXXXXXXXXGBdhD2l6_XX", "duration": 5, "mime_type": "audio/ogg", "file_size": 23000 } } }' "https://YOUR.BOT.URL:YOURPORT/" ```