diff --git a/data/web/blogfork.telegram.org/bots/api-changelog.html b/data/web/blogfork.telegram.org/bots/api-changelog.html index f799ca7ac3..52ec1d00b1 100644 --- a/data/web/blogfork.telegram.org/bots/api-changelog.html +++ b/data/web/blogfork.telegram.org/bots/api-changelog.html @@ -54,6 +54,43 @@ To learn how to create…">
+Subscribe to @BotNews to be the first to know about the latest updates and join the discussion in @BotTalk
Bot API 6.1
+Media in Descriptions
+Web App Improvements
+Join Requests & Payments
+Telegram Premium Support (more info)
+Attachment Menu Integration
+Other Changes
+Bot API 6.0
To see a Web App in action, try our sample @DurgerKingBot.
Bot API 6.1
+Web Apps always receive data about the user's current color theme in real time, so you can adjust the appearance of your interfaces to match it. For example, when users switch between Day and Night modes or use various custom themes.
@@ -131,13 +144,14 @@--TL;DR: Web App Bots can request to be added directly to a user's attachment menu, allowing them to be quickly launched from any private chat. To try this mode, open this attachment menu link for @DurgerKingBot, then use the menu in any private chat.
+TL;DR: Web App Bots can request to be added directly to a user's attachment menu, allowing them to be quickly launched from any chat. To try this mode, open this attachment menu link for @DurgerKingBot, then use the menu in any type of chat.
Web App Bots can request to be added directly to a user's attachment menu, allowing them to be quickly launched from any private chat (with either a user or another bot).
+Web App Bots can request to be added directly to a user's attachment menu, allowing them to be quickly launched from any type of chat. NEW You can configure in which types of chats your web app can be started from the attachment menu (private, groups, supergroups or channels).
Attachment menu integration is currently only available for major advertisers on the Telegram Ad Platform. However, all bots can use it in the test server environment.
To enable this feature for your bot, open @BotFather from an account on the test server and send the /setattach
command – or go to Bot Settings > Configure Attachment Menu. Then specify the URL that will be opened to launch the bot's Web App via its icon in the attachment menu.
In addition to the user's theme settings, the bot will receive basic user information (ID
, name
, username
, language_code
, photo
), as well as public info about the chat partner (ID
, name
, username
, photo
) and a unique identifier for the web view session query_id, which allows messages of any type to be sent to the chat on behalf of the user that opened the bot.
The bot can call the Bot API method answerWebAppQuery, which sends an inline message from the user via the bot to the private chat where it was launched and closes the Web App.
+NEW You can add a 'Settings' item to the context menu of your Web App using @BotFather. When users select this option from the menu, your bot will receive a settingsButtonClicked
event.
In addition to the user's theme settings, the bot will receive basic user information (ID
, name
, username
, language_code
, photo
), as well as public info about the chat partner (ID
, name
, username
, photo
) or the chat info (ID
, type
, title
, username
, photo
) and a unique identifier for the web view session query_id, which allows messages of any type to be sent to the chat on behalf of the user that opened the bot.
The bot can call the Bot API method answerWebAppQuery, which sends an inline message from the user via the bot to the chat where it was launched and closes the Web App.
@@ -166,6 +180,11 @@You can read more about adding bots to the attachment menu here.
var(--tg-color-scheme)
.var(--tg-viewport-stable-height)
.viewportHeight
, the value of viewportStableHeight
does not change as the position of the Web App changes with user gestures or during animations. The value of viewportStableHeight
will be updated after all gestures and animations are completed and the Web App reaches its final size.viewportChanged
with the passed parameter isStateStable=true
, which will allow you to track when the stable state of the height of the visible area changes.#RRGGBB
format.#RRGGBB
format.#RRGGBB
format or you can use keywords bg_color, secondary_bg_color instead.#RRGGBB
format.var(--tg-theme-button-text-color)
.#RRGGBB
format.var(--tg-theme-secondary-bg-color)
.NEW This object controls the back button, which can be displayed in the header of the Web App in the Telegram interface.
+Field | +Type | +Description | +
---|---|---|
isVisible | +Boolean | +Shows whether the button is visible. Set to false by default. | +
onClick(callback) | +Function | +Bot API 6.1+ A method that sets the button press event handler. An alias for Telegram.WebApp.onEvent('backButtonClicked', callback) |
+
offClick(callback) | +Function | +Bot API 6.1+ A method that removes the button press event handler. An alias for Telegram.WebApp.offEvent('backButtonClicked', callback) |
+
show() | +Function | +Bot API 6.1+ A method to make the button active and visible. | +
hide() | +Function | +Bot API 6.1+ A method to hide the button. | +
All these methods return the BackButton object so they can be chained.
This object controls the main button, which is displayed at the bottom of the Web App in the Telegram interface.
A method that sets the button press event handler. An alias for Telegram.WebApp.onEvent('mainButtonClicked', callback) |
||
offClick(callback) NEW | +Function | +A method that removes the button press event handler. An alias for Telegram.WebApp.offEvent('mainButtonClicked', callback) |
+
show() | Function | A method to make the button visible. Note that opening the Web App from the attachment menu hides the main button until the user interacts with the Web App interface. |
@@ -363,6 +481,35 @@
All these methods return the MainButton object so they can be chained.
+NEW This object controls haptic feedback.
+Field | +Type | +Description | +
---|---|---|
impactOccurred(style) | +Function | +Bot API 6.1+ A method tells that an impact occurred. The Telegram app may play the appropriate haptics based on style value passed. Style can be one of these values: - light, indicates a collision between small or lightweight UI objects, - medium, indicates a collision between medium-sized or medium-weight UI objects, - heavy, indicates a collision between large or heavyweight UI objects, - rigid, indicates a collision between hard or inflexible UI objects, - soft, indicates a collision between soft or flexible UI objects. |
+
notificationOccurred(type) | +Function | +Bot API 6.1+ A method tells that a task or action has succeeded, failed, or produced a warning. The Telegram app may play the appropriate haptics based on type value passed. Type can be one of these values: - error, indicates that a task or action has failed, - success, indicates that a task or action has completed successfully, - warning, indicates that a task or action produced a warning. |
+
selectionChanged() | +Function | +Bot API 6.1+ A method tells that the user has changed a selection. The Telegram app may play the appropriate haptics. Do not use this feedback when the user makes or confirms a selection; use it only when the selection changes. |
+
All these methods return the HapticFeedback object so they can be chained.
This object contains data that is transferred to the Web App when it is opened. It is empty if the Web App was launched from a keyboard button.
receiver | WebAppUser | -Optional. An object containing data about the chat partner of the current user in the chat where the bot was launched via the attachment menu. Returned only for Web Apps launched via the attachment menu. | +Optional. An object containing data about the chat partner of the current user in the chat where the bot was launched via the attachment menu. Returned only for private chats and only for Web Apps launched via the attachment menu. | +
chat NEW | +WebAppChat | +Optional. An object containing data about the chat where the bot was launched via the attachment menu. Returned for supergroups, channels and group chats – only for Web Apps launched via the attachment menu. | |
start_param | @@ -395,6 +547,11 @@Optional. The value of the startattach parameter, passed via link. Only returned for Web Apps when launched from the attachment menu via link. The value of the start_param parameter will also be passed in the GET-parameter tgWebAppStartParam , so the Web App can load the correct interface right away. |
||
can_send_after NEW | +Integer | +Optional. Time in seconds, after which a message can be sent via the answerWebAppQuery method. | +|
auth_date | Integer | Unix time when the form was opened. | @@ -454,6 +611,44 @@
NEW This object represents a chat.
+Field | +Type | +Description | +
---|---|---|
id | +Integer | +Unique identifier for this chat. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier. | +
type | +String | +Type of chat, can be either “group”, “supergroup” or “channel” | +
title | +String | +Title of the chat | +
username | +String | +Optional. Username of the chat | +
photo_url | +String | +Optional. URL of the chat’s photo. The photo can be in .jpeg or .svg formats. Only returned for Web Apps launched from the attachment menu. | +
To validate data received via the Web App, one should send the data from the Telegram.WebApp.initData field to the bot's backend. The data is a query string, which is composed of a series of field-value pairs.
You can verify the integrity of the data received by comparing the received hash parameter with the hexadecimal representation of the HMAC-SHA-256 signature of the data-check-string with the secret key, which is the HMAC-SHA-256 signature of the bot's token with the constant string WebAppData
used as a key.
mainButtonClicked
backButtonClicked
NEWsettingsButtonClicked
NEWinvoiceClosed
NEWThe following link formats are also supported:
https://t.me/username?attach=botusername
https://t.me/username?attach=botusername&startattach=command
https://t.me/+1234567890?attach=botusername
https://t.me/+1234567890?attach=botusername&startattach=command
These links open the Web App in the attachment menu in the chat with a specific user. If the bot wasn't already added to the attachment menu, the user will be prompted to do so. If a non-empty startattach parameter was included in the link, it will be passed to the Web App in the start_param field and in the GET parameter tgWebAppStartParam.
+Bot API 6.1+ supports a new link format:
+https://t.me/botusername?startattach&choose=users+bots
https://t.me/botusername?startattach=command&choose=groups+channels
Opening such a link prompts the user to choose a specific chat and opens the attachment menu in that chat. If the bot wasn't already added to the attachment menu, the user will be prompted to do so. You can specify which types of chats the user will be able to choose from. It can be one or more of the following types: users, bots, groups, channels separated by a +
sign. If a non-empty startattach parameter was included in the link, it will be passed to the Web App in the start_param field and in the GET parameter tgWebAppStartParam.
To log in to the test environment, use either of the following:
@@ -511,10 +721,31 @@ if (hex(HMAC_SHA256(data_check_string, secret_key)) == hash) {The test environment is completely separate from the main environment, so you will need to create a new user account and a new bot with @BotFather.
After receiving your bot token, you can send requests to the Bot API in this format:
-https://api.telegram.org/bot<token>/test/METHOD_NAME
https://api.telegram.org/bot<token>/test/METHOD_NAME
+Note: When working with the test environment, you may use HTTP links without TLS to test your Web App.
Use these tools to find app-specific issues in your Web App:
+Android
+chrome://inspect/#devices
in Chrome – you will see your Web App there when you launch it on your phone.Telegram Desktop on Windows and Linux
+Telegram macOS
++Subscribe to @BotNews to be the first to know about the latest updates and join the discussion in @BotTalk
Bot API 6.1
+Media in Descriptions
+Web App Improvements
+Join Requests & Payments
+Telegram Premium Support (more info)
+Attachment Menu Integration
+Other Changes
+Bot API 6.0
+Subscribe to @BotNews to be the first to know about the latest updates and join the discussion in @BotTalk
Bot API 6.1
+Media in Descriptions
+Web App Improvements
+Join Requests & Payments
+Telegram Premium Support (more info)
+Attachment Menu Integration
+Other Changes
+Bot API 6.0
Bot API 5.5
-Note: After this update it will become impossible to forward messages from some chats. Use the fields has_protected_content in the classes Message and Chat to check this.
-Note: After this update users are able to send messages on behalf of channels they own. Bots are expected to use the field sender_chat in the class Message to correctly support such messages.
-Note: As previously announced, user identifiers can now have up to 52 significant bits and require a 64-bit integer or double-precision float type to be stored safely.
Each bot is given a unique authentication token when it is created. The token looks something like 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
, but we'll use simply <token> in this document instead. You can learn about obtaining tokens and generating new ones in this document.
Use this method to specify a URL and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified URL, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. Returns True on success.
-If you'd like to make sure that the webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. https://www.example.com/<token>
. Since nobody else knows your bot's token, you can be pretty sure it's us.
If you'd like to make sure that the webhook was set by you, you can specify secret data in the parameter secret_token. If specified, the request will contain a header “X-Telegram-Bot-Api-Secret-Token” with the secret token as content.
Optional | Pass True to drop all pending updates | ||
secret_token | +String | +Optional | +A secret token to be sent in a header “X-Telegram-Bot-Api-Secret-Token” in every webhook request, 1-256 characters. Only characters A-Z , a-z , 0-9 , _ and - are allowed. The header is useful to ensure that the request comes from a webhook set by you. |
+
Notes
-
1. You will not be able to receive updates using getUpdates for as long as an outgoing webhook is set up.
2. To use a self-signed certificate, you need to upload your public key certificate using certificate parameter. Please upload as InputFile, sending a String will not work.
3. Ports currently supported for webhooks: 443, 80, 88, 8443.NEW! If you're having any trouble setting up webhooks, please check out this amazing guide to webhooks.
+If you're having any trouble setting up webhooks, please check out this amazing guide to webhooks.
Use this method to remove webhook integration if you decide to switch back to getUpdates. Returns True on success.
@@ -454,6 +484,16 @@ To learn how to create…">tg://user?id=<user_id>
links only in chats with the user. Returned only in getChat.Use this method to create a link for an invoice. Returns the created invoice link as String on success.
+Parameter | +Type | +Required | +Description | +
---|---|---|---|
title | +String | +Yes | +Product name, 1-32 characters | +
description | +String | +Yes | +Product description, 1-255 characters | +
payload | +String | +Yes | +Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes. | +
provider_token | +String | +Yes | +Payment provider token, obtained via BotFather | +
currency | +String | +Yes | +Three-letter ISO 4217 currency code, see more on currencies | +
prices | +Array of LabeledPrice | +Yes | +Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) | +
max_tip_amount | +Integer | +Optional | +The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145 . See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0 |
+
suggested_tip_amounts | +Array of Integer | +Optional | +A JSON-serialized array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount. | +
provider_data | +String | +Optional | +JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider. | +
photo_url | +String | +Optional | +URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. | +
photo_size | +Integer | +Optional | +Photo size in bytes | +
photo_width | +Integer | +Optional | +Photo width | +
photo_height | +Integer | +Optional | +Photo height | +
need_name | +Boolean | +Optional | +Pass True, if you require the user's full name to complete the order | +
need_phone_number | +Boolean | +Optional | +Pass True, if you require the user's phone number to complete the order | +
need_email | +Boolean | +Optional | +Pass True, if you require the user's email address to complete the order | +
need_shipping_address | +Boolean | +Optional | +Pass True, if you require the user's shipping address to complete the order | +
send_phone_number_to_provider | +Boolean | +Optional | +Pass True, if the user's phone number should be sent to the provider | +
send_email_to_provider | +Boolean | +Optional | +Pass True, if the user's email address should be sent to the provider | +
is_flexible | +Boolean | +Optional | +Pass True, if the final price depends on the shipping method | +
If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. On success, True is returned.
An object with input data transferred to the Web App. WARNING: Data from this field should not be trusted. You should only use data from initData on the bot's server and only after it has been validated. |
||||
version NEW | +String | +The version of the Bot API available in the user's Telegram app. | +||
colorScheme | String | The color scheme currently used in the Telegram app. Either “light” or “dark”. Also available as the CSS variable var(--tg-color-scheme) . |
@@ -191,11 +210,46 @@
The height of the visible area of the Web App in its last stable state. Also available in CSS as a variable var(--tg-viewport-stable-height) .The application can display just the top part of the Web App, with its lower part remaining outside the screen area. From this position, the user can “pull” the Web App to its maximum height, while the bot can do the same by calling the expand() method. Unlike the value of viewportHeight , the value of viewportStableHeight does not change as the position of the Web App changes with user gestures or during animations. The value of viewportStableHeight will be updated after all gestures and animations are completed and the Web App reaches its final size.Note the event viewportChanged with the passed parameter isStateStable=true , which will allow you to track when the stable state of the height of the visible area changes. |
|
headerColor NEW | +String | +Current header color in the #RRGGBB format. |
+||
backgroundColor NEW | +String | +Current background color in the #RRGGBB format. |
+||
BackButton NEW | +BackButton | +An object for controlling the back button which can be displayed in the header of the Web App in the Telegram interface. | +||
MainButton | MainButton | An object for controlling the main button, which is displayed at the bottom of the Web App in the Telegram interface. | ||
HapticFeedback NEW | +HapticFeedback | +An object for controlling haptic feedback. | +||
isVersionAtLeast(version) NEW | +Function | +Returns true if the user's app supports a version of the Bot API that is equal to or higher than the version passed as the parameter. | +||
setHeaderColor(color) NEW | +Function | +Bot API 6.1+ A method that sets the app header color. You can only pass Telegram.WebApp.themeParams.bg_color or Telegram.WebApp.themeParams.secondary_bg_color as a color or you can use keywords bg_color, secondary_bg_color instead. | +||
setBackgroundColor(color) NEW | +Function | +Bot API 6.1+ A method that sets the app background color in the #RRGGBB format or you can use keywords bg_color, secondary_bg_color instead. |
+||
onEvent(eventType, eventHandler) | Function | A method that sets the app event handler. Check the list of available events. | @@ -211,6 +265,21 @@A method used to send data to the bot. When this method is called, a service message is sent to the bot containing the data data of the length up to 4096 bytes, and the Web App is closed. See the field web_app_data in the class Message. This method is only available for Web Apps launched via a Keyboard button. |
|
openLink(url) NEW | +Function | +A method that opens a link in an external browser. The Web App will not be closed. Note that this method can be called only in response to the user interaction with the Web App interface (e.g. click inside the Web App or on the main button) |
+||
openTelegramLink(url) NEW | +Function | +A method that opens a telegram link inside Telegram app. The Web App will be closed. | +||
openInvoice(url[, callback]) NEW | +Function | +Bot API 6.1+ A method that opens an invoice using the link url. The Web App will receive the event invoiceClosed when the invoice is closed. If an optional callback parameter was passed, the callback function will be called and the invoice status will be passed as the first argument. | +||
ready() | Function | A method that informs the Telegram app that the Web App is ready to be displayed. It is recommended to call this method as early as possible, as soon as all essential interface elements are loaded. Once this method is called, the loading placeholder is hidden and the Web App is shown. If the method is not called, the placeholder will be hidden only when the page is fully loaded. |
@@ -268,12 +337,56 @@
String | Optional. Button text color in the #RRGGBB format.Also available as the CSS variable var(--tg-theme-button-text-color) . |
secondary_bg_color NEW | +String | +Optional. Bot API 6.1+ Secondary background color in the #RRGGBB format.Also available as the CSS variable var(--tg-theme-secondary-bg-color) . |
+
NEW This object controls the back button, which can be displayed in the header of the Web App in the Telegram interface.
+Field | +Type | +Description | +
---|---|---|
isVisible | +Boolean | +Shows whether the button is visible. Set to false by default. | +
onClick(callback) | +Function | +Bot API 6.1+ A method that sets the button press event handler. An alias for Telegram.WebApp.onEvent('backButtonClicked', callback) |
+
offClick(callback) | +Function | +Bot API 6.1+ A method that removes the button press event handler. An alias for Telegram.WebApp.offEvent('backButtonClicked', callback) |
+
show() | +Function | +Bot API 6.1+ A method to make the button active and visible. | +
hide() | +Function | +Bot API 6.1+ A method to hide the button. | +
All these methods return the BackButton object so they can be chained.
This object controls the main button, which is displayed at the bottom of the Web App in the Telegram interface.
A method that sets the button press event handler. An alias for Telegram.WebApp.onEvent('mainButtonClicked', callback) |
||
offClick(callback) NEW | +Function | +A method that removes the button press event handler. An alias for Telegram.WebApp.offEvent('mainButtonClicked', callback) |
+
show() | Function | A method to make the button visible. Note that opening the Web App from the attachment menu hides the main button until the user interacts with the Web App interface. |
@@ -363,6 +481,35 @@
All these methods return the MainButton object so they can be chained.
+NEW This object controls haptic feedback.
+Field | +Type | +Description | +
---|---|---|
impactOccurred(style) | +Function | +Bot API 6.1+ A method tells that an impact occurred. The Telegram app may play the appropriate haptics based on style value passed. Style can be one of these values: - light, indicates a collision between small or lightweight UI objects, - medium, indicates a collision between medium-sized or medium-weight UI objects, - heavy, indicates a collision between large or heavyweight UI objects, - rigid, indicates a collision between hard or inflexible UI objects, - soft, indicates a collision between soft or flexible UI objects. |
+
notificationOccurred(type) | +Function | +Bot API 6.1+ A method tells that a task or action has succeeded, failed, or produced a warning. The Telegram app may play the appropriate haptics based on type value passed. Type can be one of these values: - error, indicates that a task or action has failed, - success, indicates that a task or action has completed successfully, - warning, indicates that a task or action produced a warning. |
+
selectionChanged() | +Function | +Bot API 6.1+ A method tells that the user has changed a selection. The Telegram app may play the appropriate haptics. Do not use this feedback when the user makes or confirms a selection; use it only when the selection changes. |
+
All these methods return the HapticFeedback object so they can be chained.
This object contains data that is transferred to the Web App when it is opened. It is empty if the Web App was launched from a keyboard button.
receiver | WebAppUser | -Optional. An object containing data about the chat partner of the current user in the chat where the bot was launched via the attachment menu. Returned only for Web Apps launched via the attachment menu. | +Optional. An object containing data about the chat partner of the current user in the chat where the bot was launched via the attachment menu. Returned only for private chats and only for Web Apps launched via the attachment menu. | +
chat NEW | +WebAppChat | +Optional. An object containing data about the chat where the bot was launched via the attachment menu. Returned for supergroups, channels and group chats – only for Web Apps launched via the attachment menu. | |
start_param | @@ -395,6 +547,11 @@Optional. The value of the startattach parameter, passed via link. Only returned for Web Apps when launched from the attachment menu via link. The value of the start_param parameter will also be passed in the GET-parameter tgWebAppStartParam , so the Web App can load the correct interface right away. |
||
can_send_after NEW | +Integer | +Optional. Time in seconds, after which a message can be sent via the answerWebAppQuery method. | +|
auth_date | Integer | Unix time when the form was opened. | @@ -454,6 +611,44 @@
NEW This object represents a chat.
+Field | +Type | +Description | +
---|---|---|
id | +Integer | +Unique identifier for this chat. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier. | +
type | +String | +Type of chat, can be either “group”, “supergroup” or “channel” | +
title | +String | +Title of the chat | +
username | +String | +Optional. Username of the chat | +
photo_url | +String | +Optional. URL of the chat’s photo. The photo can be in .jpeg or .svg formats. Only returned for Web Apps launched from the attachment menu. | +
To validate data received via the Web App, one should send the data from the Telegram.WebApp.initData field to the bot's backend. The data is a query string, which is composed of a series of field-value pairs.
You can verify the integrity of the data received by comparing the received hash parameter with the hexadecimal representation of the HMAC-SHA-256 signature of the data-check-string with the secret key, which is the HMAC-SHA-256 signature of the bot's token with the constant string WebAppData
used as a key.
mainButtonClicked
backButtonClicked
NEWsettingsButtonClicked
NEWinvoiceClosed
NEWThe following link formats are also supported:
https://t.me/username?attach=botusername
https://t.me/username?attach=botusername&startattach=command
https://t.me/+1234567890?attach=botusername
https://t.me/+1234567890?attach=botusername&startattach=command
These links open the Web App in the attachment menu in the chat with a specific user. If the bot wasn't already added to the attachment menu, the user will be prompted to do so. If a non-empty startattach parameter was included in the link, it will be passed to the Web App in the start_param field and in the GET parameter tgWebAppStartParam.
+Bot API 6.1+ supports a new link format:
+https://t.me/botusername?startattach&choose=users+bots
https://t.me/botusername?startattach=command&choose=groups+channels
Opening such a link prompts the user to choose a specific chat and opens the attachment menu in that chat. If the bot wasn't already added to the attachment menu, the user will be prompted to do so. You can specify which types of chats the user will be able to choose from. It can be one or more of the following types: users, bots, groups, channels separated by a +
sign. If a non-empty startattach parameter was included in the link, it will be passed to the Web App in the start_param field and in the GET parameter tgWebAppStartParam.
To log in to the test environment, use either of the following:
@@ -511,10 +721,31 @@ if (hex(HMAC_SHA256(data_check_string, secret_key)) == hash) {The test environment is completely separate from the main environment, so you will need to create a new user account and a new bot with @BotFather.
After receiving your bot token, you can send requests to the Bot API in this format:
-https://api.telegram.org/bot<token>/test/METHOD_NAME
https://api.telegram.org/bot<token>/test/METHOD_NAME
+Note: When working with the test environment, you may use HTTP links without TLS to test your Web App.
Use these tools to find app-specific issues in your Web App:
+Android
+chrome://inspect/#devices
in Chrome – you will see your Web App there when you launch it on your phone.Telegram Desktop on Windows and Linux
+Telegram macOS
++Subscribe to @BotNews to be the first to know about the latest updates and join the discussion in @BotTalk
Bot API 6.1
+Media in Descriptions
+Web App Improvements
+Join Requests & Payments
+Telegram Premium Support (more info)
+Attachment Menu Integration
+Other Changes
+Bot API 6.0
+Subscribe to @BotNews to be the first to know about the latest updates and join the discussion in @BotTalk
Bot API 6.1
+Media in Descriptions
+Web App Improvements
+Join Requests & Payments
+Telegram Premium Support (more info)
+Attachment Menu Integration
+Other Changes
+Bot API 6.0
Bot API 5.5
-Note: After this update it will become impossible to forward messages from some chats. Use the fields has_protected_content in the classes Message and Chat to check this.
-Note: After this update users are able to send messages on behalf of channels they own. Bots are expected to use the field sender_chat in the class Message to correctly support such messages.
-Note: As previously announced, user identifiers can now have up to 52 significant bits and require a 64-bit integer or double-precision float type to be stored safely.
Each bot is given a unique authentication token when it is created. The token looks something like 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
, but we'll use simply <token> in this document instead. You can learn about obtaining tokens and generating new ones in this document.
Use this method to specify a URL and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified URL, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. Returns True on success.
-If you'd like to make sure that the webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. https://www.example.com/<token>
. Since nobody else knows your bot's token, you can be pretty sure it's us.
If you'd like to make sure that the webhook was set by you, you can specify secret data in the parameter secret_token. If specified, the request will contain a header “X-Telegram-Bot-Api-Secret-Token” with the secret token as content.
Optional | Pass True to drop all pending updates | ||
secret_token | +String | +Optional | +A secret token to be sent in a header “X-Telegram-Bot-Api-Secret-Token” in every webhook request, 1-256 characters. Only characters A-Z , a-z , 0-9 , _ and - are allowed. The header is useful to ensure that the request comes from a webhook set by you. |
+
Notes
-
1. You will not be able to receive updates using getUpdates for as long as an outgoing webhook is set up.
2. To use a self-signed certificate, you need to upload your public key certificate using certificate parameter. Please upload as InputFile, sending a String will not work.
3. Ports currently supported for webhooks: 443, 80, 88, 8443.NEW! If you're having any trouble setting up webhooks, please check out this amazing guide to webhooks.
+If you're having any trouble setting up webhooks, please check out this amazing guide to webhooks.
Use this method to remove webhook integration if you decide to switch back to getUpdates. Returns True on success.
@@ -454,6 +484,16 @@ To learn how to create…">tg://user?id=<user_id>
links only in chats with the user. Returned only in getChat.Use this method to create a link for an invoice. Returns the created invoice link as String on success.
+Parameter | +Type | +Required | +Description | +
---|---|---|---|
title | +String | +Yes | +Product name, 1-32 characters | +
description | +String | +Yes | +Product description, 1-255 characters | +
payload | +String | +Yes | +Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes. | +
provider_token | +String | +Yes | +Payment provider token, obtained via BotFather | +
currency | +String | +Yes | +Three-letter ISO 4217 currency code, see more on currencies | +
prices | +Array of LabeledPrice | +Yes | +Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) | +
max_tip_amount | +Integer | +Optional | +The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145 . See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0 |
+
suggested_tip_amounts | +Array of Integer | +Optional | +A JSON-serialized array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount. | +
provider_data | +String | +Optional | +JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider. | +
photo_url | +String | +Optional | +URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. | +
photo_size | +Integer | +Optional | +Photo size in bytes | +
photo_width | +Integer | +Optional | +Photo width | +
photo_height | +Integer | +Optional | +Photo height | +
need_name | +Boolean | +Optional | +Pass True, if you require the user's full name to complete the order | +
need_phone_number | +Boolean | +Optional | +Pass True, if you require the user's phone number to complete the order | +
need_email | +Boolean | +Optional | +Pass True, if you require the user's email address to complete the order | +
need_shipping_address | +Boolean | +Optional | +Pass True, if you require the user's shipping address to complete the order | +
send_phone_number_to_provider | +Boolean | +Optional | +Pass True, if the user's phone number should be sent to the provider | +
send_email_to_provider | +Boolean | +Optional | +Pass True, if the user's email address should be sent to the provider | +
is_flexible | +Boolean | +Optional | +Pass True, if the final price depends on the shipping method | +
If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. On success, True is returned.
An object with input data transferred to the Web App. WARNING: Data from this field should not be trusted. You should only use data from initData on the bot's server and only after it has been validated. |
||||
version NEW | +String | +The version of the Bot API available in the user's Telegram app. | +||
colorScheme | String | The color scheme currently used in the Telegram app. Either “light” or “dark”. Also available as the CSS variable var(--tg-color-scheme) . |
@@ -191,11 +210,46 @@
The height of the visible area of the Web App in its last stable state. Also available in CSS as a variable var(--tg-viewport-stable-height) .The application can display just the top part of the Web App, with its lower part remaining outside the screen area. From this position, the user can “pull” the Web App to its maximum height, while the bot can do the same by calling the expand() method. Unlike the value of viewportHeight , the value of viewportStableHeight does not change as the position of the Web App changes with user gestures or during animations. The value of viewportStableHeight will be updated after all gestures and animations are completed and the Web App reaches its final size.Note the event viewportChanged with the passed parameter isStateStable=true , which will allow you to track when the stable state of the height of the visible area changes. |
|
headerColor NEW | +String | +Current header color in the #RRGGBB format. |
+||
backgroundColor NEW | +String | +Current background color in the #RRGGBB format. |
+||
BackButton NEW | +BackButton | +An object for controlling the back button which can be displayed in the header of the Web App in the Telegram interface. | +||
MainButton | MainButton | An object for controlling the main button, which is displayed at the bottom of the Web App in the Telegram interface. | ||
HapticFeedback NEW | +HapticFeedback | +An object for controlling haptic feedback. | +||
isVersionAtLeast(version) NEW | +Function | +Returns true if the user's app supports a version of the Bot API that is equal to or higher than the version passed as the parameter. | +||
setHeaderColor(color) NEW | +Function | +Bot API 6.1+ A method that sets the app header color. You can only pass Telegram.WebApp.themeParams.bg_color or Telegram.WebApp.themeParams.secondary_bg_color as a color or you can use keywords bg_color, secondary_bg_color instead. | +||
setBackgroundColor(color) NEW | +Function | +Bot API 6.1+ A method that sets the app background color in the #RRGGBB format or you can use keywords bg_color, secondary_bg_color instead. |
+||
onEvent(eventType, eventHandler) | Function | A method that sets the app event handler. Check the list of available events. | @@ -211,6 +265,21 @@A method used to send data to the bot. When this method is called, a service message is sent to the bot containing the data data of the length up to 4096 bytes, and the Web App is closed. See the field web_app_data in the class Message. This method is only available for Web Apps launched via a Keyboard button. |
|
openLink(url) NEW | +Function | +A method that opens a link in an external browser. The Web App will not be closed. Note that this method can be called only in response to the user interaction with the Web App interface (e.g. click inside the Web App or on the main button) |
+||
openTelegramLink(url) NEW | +Function | +A method that opens a telegram link inside Telegram app. The Web App will be closed. | +||
openInvoice(url[, callback]) NEW | +Function | +Bot API 6.1+ A method that opens an invoice using the link url. The Web App will receive the event invoiceClosed when the invoice is closed. If an optional callback parameter was passed, the callback function will be called and the invoice status will be passed as the first argument. | +||
ready() | Function | A method that informs the Telegram app that the Web App is ready to be displayed. It is recommended to call this method as early as possible, as soon as all essential interface elements are loaded. Once this method is called, the loading placeholder is hidden and the Web App is shown. If the method is not called, the placeholder will be hidden only when the page is fully loaded. |
@@ -268,12 +337,56 @@
String | Optional. Button text color in the #RRGGBB format.Also available as the CSS variable var(--tg-theme-button-text-color) . |
secondary_bg_color NEW | +String | +Optional. Bot API 6.1+ Secondary background color in the #RRGGBB format.Also available as the CSS variable var(--tg-theme-secondary-bg-color) . |
+
NEW This object controls the back button, which can be displayed in the header of the Web App in the Telegram interface.
+Field | +Type | +Description | +
---|---|---|
isVisible | +Boolean | +Shows whether the button is visible. Set to false by default. | +
onClick(callback) | +Function | +Bot API 6.1+ A method that sets the button press event handler. An alias for Telegram.WebApp.onEvent('backButtonClicked', callback) |
+
offClick(callback) | +Function | +Bot API 6.1+ A method that removes the button press event handler. An alias for Telegram.WebApp.offEvent('backButtonClicked', callback) |
+
show() | +Function | +Bot API 6.1+ A method to make the button active and visible. | +
hide() | +Function | +Bot API 6.1+ A method to hide the button. | +
All these methods return the BackButton object so they can be chained.
This object controls the main button, which is displayed at the bottom of the Web App in the Telegram interface.
A method that sets the button press event handler. An alias for Telegram.WebApp.onEvent('mainButtonClicked', callback) |
||
offClick(callback) NEW | +Function | +A method that removes the button press event handler. An alias for Telegram.WebApp.offEvent('mainButtonClicked', callback) |
+
show() | Function | A method to make the button visible. Note that opening the Web App from the attachment menu hides the main button until the user interacts with the Web App interface. |
@@ -363,6 +481,35 @@
All these methods return the MainButton object so they can be chained.
+NEW This object controls haptic feedback.
+Field | +Type | +Description | +
---|---|---|
impactOccurred(style) | +Function | +Bot API 6.1+ A method tells that an impact occurred. The Telegram app may play the appropriate haptics based on style value passed. Style can be one of these values: - light, indicates a collision between small or lightweight UI objects, - medium, indicates a collision between medium-sized or medium-weight UI objects, - heavy, indicates a collision between large or heavyweight UI objects, - rigid, indicates a collision between hard or inflexible UI objects, - soft, indicates a collision between soft or flexible UI objects. |
+
notificationOccurred(type) | +Function | +Bot API 6.1+ A method tells that a task or action has succeeded, failed, or produced a warning. The Telegram app may play the appropriate haptics based on type value passed. Type can be one of these values: - error, indicates that a task or action has failed, - success, indicates that a task or action has completed successfully, - warning, indicates that a task or action produced a warning. |
+
selectionChanged() | +Function | +Bot API 6.1+ A method tells that the user has changed a selection. The Telegram app may play the appropriate haptics. Do not use this feedback when the user makes or confirms a selection; use it only when the selection changes. |
+
All these methods return the HapticFeedback object so they can be chained.
This object contains data that is transferred to the Web App when it is opened. It is empty if the Web App was launched from a keyboard button.
receiver | WebAppUser | -Optional. An object containing data about the chat partner of the current user in the chat where the bot was launched via the attachment menu. Returned only for Web Apps launched via the attachment menu. | +Optional. An object containing data about the chat partner of the current user in the chat where the bot was launched via the attachment menu. Returned only for private chats and only for Web Apps launched via the attachment menu. | +
chat NEW | +WebAppChat | +Optional. An object containing data about the chat where the bot was launched via the attachment menu. Returned for supergroups, channels and group chats – only for Web Apps launched via the attachment menu. | |
start_param | @@ -395,6 +547,11 @@Optional. The value of the startattach parameter, passed via link. Only returned for Web Apps when launched from the attachment menu via link. The value of the start_param parameter will also be passed in the GET-parameter tgWebAppStartParam , so the Web App can load the correct interface right away. |
||
can_send_after NEW | +Integer | +Optional. Time in seconds, after which a message can be sent via the answerWebAppQuery method. | +|
auth_date | Integer | Unix time when the form was opened. | @@ -454,6 +611,44 @@
NEW This object represents a chat.
+Field | +Type | +Description | +
---|---|---|
id | +Integer | +Unique identifier for this chat. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier. | +
type | +String | +Type of chat, can be either “group”, “supergroup” or “channel” | +
title | +String | +Title of the chat | +
username | +String | +Optional. Username of the chat | +
photo_url | +String | +Optional. URL of the chat’s photo. The photo can be in .jpeg or .svg formats. Only returned for Web Apps launched from the attachment menu. | +
To validate data received via the Web App, one should send the data from the Telegram.WebApp.initData field to the bot's backend. The data is a query string, which is composed of a series of field-value pairs.
You can verify the integrity of the data received by comparing the received hash parameter with the hexadecimal representation of the HMAC-SHA-256 signature of the data-check-string with the secret key, which is the HMAC-SHA-256 signature of the bot's token with the constant string WebAppData
used as a key.
mainButtonClicked
backButtonClicked
NEWsettingsButtonClicked
NEWinvoiceClosed
NEWThe following link formats are also supported:
https://t.me/username?attach=botusername
https://t.me/username?attach=botusername&startattach=command
https://t.me/+1234567890?attach=botusername
https://t.me/+1234567890?attach=botusername&startattach=command
These links open the Web App in the attachment menu in the chat with a specific user. If the bot wasn't already added to the attachment menu, the user will be prompted to do so. If a non-empty startattach parameter was included in the link, it will be passed to the Web App in the start_param field and in the GET parameter tgWebAppStartParam.
+Bot API 6.1+ supports a new link format:
+https://t.me/botusername?startattach&choose=users+bots
https://t.me/botusername?startattach=command&choose=groups+channels
Opening such a link prompts the user to choose a specific chat and opens the attachment menu in that chat. If the bot wasn't already added to the attachment menu, the user will be prompted to do so. You can specify which types of chats the user will be able to choose from. It can be one or more of the following types: users, bots, groups, channels separated by a +
sign. If a non-empty startattach parameter was included in the link, it will be passed to the Web App in the start_param field and in the GET parameter tgWebAppStartParam.
To log in to the test environment, use either of the following:
@@ -511,10 +721,31 @@ if (hex(HMAC_SHA256(data_check_string, secret_key)) == hash) {The test environment is completely separate from the main environment, so you will need to create a new user account and a new bot with @BotFather.
After receiving your bot token, you can send requests to the Bot API in this format:
-https://api.telegram.org/bot<token>/test/METHOD_NAME
https://api.telegram.org/bot<token>/test/METHOD_NAME
+Note: When working with the test environment, you may use HTTP links without TLS to test your Web App.
Use these tools to find app-specific issues in your Web App:
+Android
+chrome://inspect/#devices
in Chrome – you will see your Web App there when you launch it on your phone.Telegram Desktop on Windows and Linux
+Telegram macOS
+