api 7.1更新字段
Field | Type | Description |
update_id | Integer | The update’s unique identifier. Update identifiers start from a certain positive number and increase sequentially. This identifier becomes especially handy if you’re using webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order. If there are no new updates for at least a week, then identifier of the next update will be chosen randomly instead of sequentially. |
message | Message | Optional. New incoming message of any kind – text, photo, sticker, etc. |
edited_message | Message | Optional. New version of a message that is known to the bot and was edited. This update may at times be triggered by changes to message fields that are either unavailable or not actively used by your bot. |
channel_post | Message | Optional. New incoming channel post of any kind – text, photo, sticker, etc. |
edited_channel_post | Message | Optional. New version of a channel post that is known to the bot and was edited. This update may at times be triggered by changes to message fields that are either unavailable or not actively used by your bot. |
message_reaction | MessageReactionUpdated | Optional. A reaction to a message was changed by a user. The bot must be an administrator in the chat and must explicitly specify “message_reaction” in the list of allowed_updates to receive these updates. The update isn’t received for reactions set by bots. |
message_reaction_count | MessageReactionCountUpdated | Optional. Reactions to a message with anonymous reactions were changed. The bot must be an administrator in the chat and must explicitly specify “message_reaction_count” in the list of allowed_updates to receive these updates. The updates are grouped and can be sent with delay up to a few minutes. |
inline_query | InlineQuery | Optional. New incoming inline query |
chosen_inline_result | ChosenInlineResult | Optional. The result of an inline query that was chosen by a user and sent to their chat partner. Please see our documentation on the feedback collecting for details on how to enable these updates for your bot. |
callback_query | CallbackQuery | Optional. New incoming callback query |
shipping_query | ShippingQuery | Optional. New incoming shipping query. Only for invoices with flexible price |
pre_checkout_query | PreCheckoutQuery | Optional. New incoming pre-checkout query. Contains full information about checkout |
poll | Poll | Optional. New poll state. Bots receive only updates about manually stopped polls and polls, which are sent by the bot |
poll_answer | PollAnswer | Optional. A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself. |
my_chat_member | ChatMemberUpdated | Optional. The bot’s chat member status was updated in a chat. For private chats, this update is received only when the bot is blocked or unblocked by the user. |
chat_member | ChatMemberUpdated | Optional. A chat member’s status was updated in a chat. The bot must be an administrator in the chat and must explicitly specify “chat_member” in the list of allowed_updates to receive these updates. |
chat_join_request | ChatJoinRequest | Optional. A request to join the chat has been sent. The bot must have the can_invite_users administrator right in the chat to receive these updates. |
chat_boost | ChatBoostUpdated | Optional. A chat boost was added or changed. The bot must be an administrator in the chat to receive these updates. |
removed_chat_boost | ChatBoostRemoved | Optional. A boost was removed from a chat. The bot must be an administrator in the chat to receive these updates. |
getupdates方法
Parameter | Type | Required | Description |
offset | Integer | Optional | Identifier of the first update to be returned. Must be greater by one than the highest among the identifiers of previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id. The negative offset can be specified to retrieve updates starting from -offset update from the end of the updates queue. All previous updates will be forgotten. |
limit | Integer | Optional | Limits the number of updates to be retrieved. Values between 1-100 are accepted. Defaults to 100. |
timeout | Integer | Optional | Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short polling should be used for testing purposes only. |
allowed_updates | Array of String | Optional | A JSON-serialized list of the update types you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all update types except chat_member, message_reaction, and message_reaction_count (default). If not specified, the previous setting will be used. Please note that this parameter doesn’t affect updates created before the call to the getUpdates, so unwanted updates may be received for a short period of time. |
2.为了避免重复更新,请在每个服务器响应后重新计算偏移。
setwebhook方法
Parameter | Type | Required | Description |
url | String | Yes | HTTPS URL to send updates to. Use an empty string to remove webhook integration |
certificate | InputFile | Optional | Upload your public key certificate so that the root certificate in use can be checked. See our self-signed guide for details. |
ip_address | String | Optional | The fixed IP address which will be used to send webhook requests instead of the IP address resolved through DNS |
max_connections | Integer | Optional | The maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use lower values to limit the load on your bot’s server, and higher values to increase your bot’s throughput. |
allowed_updates | Array of String | Optional | A JSON-serialized list of the update types you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all update types except chat_member, message_reaction, and message_reaction_count (default). If not specified, the previous setting will be used. Please note that this parameter doesn’t affect updates created before the call to the setWebhook, so unwanted updates may be received for a short period of time. |
drop_pending_updates | Boolean | 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. |
drop_pending_updates | Boolean | Optional | Pass True to drop all pending updates |
2.要使用自签名证书,您需要使用证书参数上传公共密钥证书。 请上传为InputFile,发送一个字符串将无效。
3.当前支持Webhooks的端口:443、80、88、8443。
getwebhookinfo:
使用此方法获取当前的Webhook状态。 不需要参数。 成功,返回Webhookinfo对象。 如果机器人使用getupdates,将返回带有URL字段空的对象。
WebhookInfo方法
Field | Type | Description |
url | String | Webhook URL, may be empty if webhook is not set up |
has_custom_certificate | Boolean | True, if a custom certificate was provided for webhook certificate checks |
pending_update_count | Integer | Number of updates awaiting delivery |
ip_address | String | Optional. Currently used webhook IP address |
last_error_date | Integer | Optional. Unix time for the most recent error that happened when trying to deliver an update via webhook |
last_error_message | String | Optional. Error message in human-readable format for the most recent error that happened when trying to deliver an update via webhook |
last_synchronization_error_date | Integer | Optional. Unix time of the most recent error that happened when trying to synchronize available updates with Telegram datacenters |
max_connections | Integer | Optional. The maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery |
allowed_updates | Array of String | Optional. A list of update types the bot is subscribed to. Defaults to all update types except chat_member |
发表回复