Telegram Bot API

Please download to get full document.

View again

of 80
16 views
DOCX
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Document Description
Telegram
Document Share
Documents Related
Document Tags
Document Transcript
  Telegram Bot API The Bot API is an HTTP-based interface created for developers keen on building bots for Telegram. To learn how to create and set up a bot, please consult our   Introduction to Bots  and  Bot FAQ .  Recent changes November 17, 2017 Bot API 3.5 .     Added the new method sendMediaGroup and two kinds of  InputMedia objects to support   the new albums feature.      Added support for pinning messages in channels. pinChatMessage and unpinChatMessage accept channels.       Added the new fields  provider_data , send_phone_number_to_provider  , send_email_to_provider   to sendInvoicef or sharing information about the invoice with the payment provider. October 11, 2017 Bot API 3.4 .    Bots can now send and receive Live Locations. Added new field live_period   to the sendLocation method and the editMessageLiveLocation and stopMessageLiveLocation methods as well as the   necessary objects for inline bots.    Bots can use the new setChatStickerSet and deleteChatStickerSet methods to manage group sticker sets.       The getChat request now returns the group's sticker set for supergroups if available.      Bots now receive entities from media captions in the new field caption_entities  in Message.    August 23, 2017 Bot API 3.3 .    Bots can now mention users via inline mentions, without using usernames.    getChat now also returns pinned messages in supergroups, if present. Added the new   field  pinned_message  to the Chat object.     Added the new fields author_signature  and forward_signature  to the Message object.       Added the new field is_bot   to the User  object. July 21, 2017 Bot API 3.2 . Teach your bot to handle stickers and sticker sets.      Added new methods for working with stickers: getStickerSet, uploadStickerFile, createNewStickerSet, addStickerToSet, setStic   kerPositionInSet, and deleteStickerFromSet.      Added the fields set_name  and mask_position  to the Sticker  object, plus two new objects, StickerSet, and MaskPosition.  June 30, 2017  Bot API 3.1 . Build your own robotic police force for supergoups with these new methods for admin bots:     Added new methods restrictChatMember  and promoteChatMember  to manage users and admins, added new parameter until_date  to kickChatMember  for temporary bans.     Added new methods exportChatInviteLink, setChatPhoto, deleteChatPhoto, setChatTitle, setChatDes   cription, pinChatMessage and unpinChatMessage to manage groups and channels.       Added the new fields  photo , description  and invite_link   to the Chat object.     Added the new fields until_date , can_be_edited  , can_change_info , can_post_messages , can_edit_messages , can_delete_messages , can_invite_users , can_restrict_members , can_pin_messag es , can_promote_members , can_send_messages , can_send_media_messages , can_send_other_messages  and can_add_web_page_previews  to the ChatMember  object. See earlier changes »     Authorizing your bot 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.  Making requests  All queries to the Telegram Bot API must be served over HTTPS and need to be presented in this form: https://api.telegram.org/bot<token>/METHOD_NAME . Like this for example: https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/getMe We support GET  and POST  HTTP methods. We support four ways of passing parameters in Bot  API requests:    URL query string       application/x-www-form-urlencoded    application/json (except for uploading files)    multipart/form-data (use to upload files) The response contains a JSON object, which always has a Boolean field ‘ok’ and may have an optional String field ‘description’ with a human - readable description of the result. If ‘ok’ equals true, the request was successful and the result of the query can be found in the ‘result’ field. In case of an unsuccessf  ul request, ‘ok’ equals false and the error is explained in the ‘description’.  An Integer ‘error_code’ field is also returned, but its contents are subject to change in the future. Some errors may also have an optional field ‘parameters’ of the type  ResponseParameters,    which can help to automatically handle the error.     All methods in the Bot API are case-insensitive.     All queries must be made using UTF-8. Making requests when getting updates If you're using  webhooks , you can perform a request to the Bot API while sending an answer to the webhook. Use either application/json  or application/x-www-form-urlencoded   or multipart/form-data  response content type for passing parameters. Specify the method to be invoked in the method   parameter of the request. It's not possible to know that such a request was successful or get its result. Please see our  FAQ for examples.  Getting updates There are two mutually exclusive ways of receiving updates for your bot —  the getUpdates method on one hand and Webhooks on the other. Incoming updates are stored   on the server until the bot receives them either way, but they will not be kept longer than 24 hours. Regardless of which option you choose, you will receive JSON-serialized Update objects as a   result. Update This object represents an incoming update.    At most one  of the optional parameters can be present in any given update. Field   Type   Description  update_id Integer The update‘s unique identifier. Update identifiers start from a  positive number and increase sequentially. This ID becomes e handy if you’re using  Webhooks, since it allows you to ignore updates or to restore the correct update sequence, should they order. If there are no new updates for at least a week, then idenext update will be chosen randomly instead of sequentially. message Message   Optional  . New incoming message of any kind  —   text, photo, edited_message Message   Optional  . New version of a message that is known to the bot achannel_post Message   Optional  . New incoming channel post of any kind  —   text, phetc. edited_channel_post Message   Optional  . New version of a channel post that is known to the 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 u their chat partner. Please see our documentation on the feedbacollecting for details on how to enable these updates for your callback_query CallbackQuery Optional  . New incoming callback query shipping_query ShippingQuery Optional  . New incoming shipping query. Only for invoices wi price   pre_checkout_query PreCheckoutQuery Optional  . New incoming pre-checkout query. Contains full inabout checkout   getUpdates Use this method to receive incoming updates using long polling (wiki). An Array of  Update objects is returned. Parameters   Type   Required   Description  offset Integer Optional Identifier of the first update to be returned. Must be greater by ohighest among the identifiers of previously received updates. By updates starting with the earliest unconfirmed update are returneconsidered confirmed as soon as getUpdates is called with an of  its update_id  . The negative offset can be specified to retrieve upfrom -offset   update from the end of the updates queue. All previwill forgotten. limit Integer Optional Limits the number of updates to be retrieved. Values between 1accepted. Defaults to 100. timeout Integer Optional Timeout in seconds for long polling. Defaults to 0, i.e. usual shoShould be positive, short polling should be used for testing purpallowed_updates Array of String Optional List the types of updates you want your bot to receive. For exam [“message”, “edited_channel_post”, “callback_query”] to only r  of these types. See Update for a complete list of available update Specify an empty list to receive all updates regardless of type (dspecified, the previous setting will be used. Please note that this parameter doesn't affect updates created bef the getUpdates, so unwanted updates may be received for a shorttime.   Notes   1.  This method will not work if an outgoing webhook is set up. 2.  In order to avoid getting duplicate updates, recalculate offset   after each server response. setWebhook 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. 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.  
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks