美文网首页
[Telegram] 获取更新

[Telegram] 获取更新

作者: w_w_wei | 来源:发表于2019-08-18 16:29 被阅读0次

Getting updates

有两种方法可以收到bot的信息更新, 一是能过getUpdates方法主动请求数据,
一是设置webhook, 将会获取到的数据保存在服务器上,直到bot收到他们.但是数据不会保存超过24小时.

不管你选择哪种, 你都会得到一个序列化的JSON对象Update .

Update

这个 object 包含bot将要收到的数据.
在任意的update对象中最多可以包含下面列表中的任意一项

Field Type Description
update_id Integer The update‘s unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID 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
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
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

getUpdates

这个方法使用long polling (wiki)来接受传入的更新数据。将会返回Update 对象组成的数组。

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 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 List the types of updates 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 updates regardless of type (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. |

Notes
1. 如果设置了传出的webhook,该方法将无法工作。
2. 为了避免重复更新,请在每次服务器响应后重新计算 offset

相关文章

网友评论

      本文标题:[Telegram] 获取更新

      本文链接:https://www.haomeiwen.com/subject/wvogcqtx.html