How to get telegram api
Telegram APIs
We offer two kinds of APIs for developers. The Bot API allows you to easily create programs that use Telegram messages for an interface. The Telegram API and TDLib allow you to build your own customized Telegram clients. You are welcome to use both APIs free of charge.
You can also add Telegram Widgets to your website.
Designers are welcome to create Animated Stickers or Custom Themes for Telegram.
Bot API
This API allows you to connect bots to our system. Telegram Bots are special accounts that do not require an additional phone number to set up. These accounts serve as an interface for code running somewhere on your server.
To use this, you don't need to know anything about how our MTProto encryption protocol works — our intermediary server will handle all encryption and communication with the Telegram API for you. You communicate with this server via a simple HTTPS-interface that offers a simplified version of the Telegram API.
Learn more about the Bot API here »
Bot developers can also make use of our Payments API to accept payments from Telegram users around the world.
TDLib – build your own Telegram
Even if you're looking for maximum customization, you don't have to create your app from scratch. Try our Telegram Database Library (or simply TDLib), a tool for third-party developers that makes it easy to build fast, secure and feature-rich Telegram apps.
TDLib takes care of all network implementation details, encryption and local data storage, so that you can dedicate more time to design, responsive interfaces and beautiful animations.
TDLib supports all Telegram features and makes developing Telegram apps a breeze on any platform. It can be used on Android, iOS, Windows, macOS, Linux and virtually any other system. The library is open source and compatible with virtually any programming language.
Learn more about TDLib here »
Telegram API
This API allows you to build your own customized Telegram clients. It is 100% open for all developers who wish to create Telegram applications on our platform. Feel free to study the open source code of existing Telegram applications for examples of how things work here. Don't forget to register your application in our system.
- Getting Started
- Security
- Optimization
- API methods
Getting started
Creating an application
How to get your application identifier and create a new Telegram app.
User authorization
How to register a user's phone to start using the API.
Two-factor authentication
How to login to a user's account if they have enabled 2FA, how to change password.
QR code login
QR code login flow
Error handling
How to handle API return errors correctly.
Handling different data centers
How to connect to the closest DC access point for faster interaction with the API, and things to watch out for when developing a client.
Handling updates
How to subscribe to updates and handle them properly.
Handling PUSH-notifications
How to subscribe and handle them properly.
Channels, supergroups, gigagroups and basic groups
How to handle channels, supergroups, gigagroups, basic groups, and what's the difference between them.
Channel statistics
Telegram offers detailed channel statistics for channels and supergroups.
Calling methods
Additional options for calling methods.
Uploading and Downloading Files
How to transfer large data batches correctly.
Pagination
How to fetch results from large lists of objects.
Client configuration
The MTProto API has multiple client configuration parameters that can be fetched with the appropriate methods.
Security
Secret chats, end-to-end encryption
End-to-end-encrypted messaging.
Security guidelines
Important checks required in your client application.
Perfect Forward Secrecy
Binding temporary authorization key to permanent ones.
End-to-End Encryption in Voice and Video Calls
End-to-end-encrypted calls.
Optimization
Client optimization
Ways to boost API interactions.
API methods
Available method list
A list of available high-level methods.
API TL-schema, as JSON
Text and JSON-presentation of types and methods used in API.
Available layer list
A list of available schema versions.
Other articles
Working with bots, using the MTProto API
How to work with bots using the MTProto API.
Commands
Bots offer a set of commands that can be used by users in private, or in a chat.
Buttons
Users can interact with your bot via buttons or even inline buttons, straight from inline messages in any chat.
Inline queries
Users can interact with your bot via inline queries, straight from the text input field in any chat.
Games
Bots can offer users HTML5 games to play solo or to compete against each other in groups and one-on-one chats; how to work with games in the MTProto API.
Search & filters
Telegram allows applying detailed message filters while looking for messages in chats.
This allows the server to filter messages based on a text query, and even on their type, and this feature is often used by graphical clients to implement features like the chat gallery, chat profile pictures and more.
Polls
Telegram allows sending polls and quizzes, that can be voted on by thousands, if not millions of users in chats and channels.
Reactions
Telegram allows users to react on any message using specific emojis, triggering cute lottie animations.
Invite links and join requests
Channels, basic groups and supergroups may have a public username or a private invite link: private invite links may be further enhanced with per-user join requests.
Admin, banned and default rights for channels, supergroups and groups
How to handle admin permissions, granular bans and global permissions in channels, groups and supergroups.
Discussion groups
Groups can be associated to a channel as a discussion group, to allow users to discuss about posts.
Channel comments and message threads
Telegram allows commenting on a channel post or on a generic group message, thanks to message threads.
Admin log
Both supergroups and channels offer a so-called admin log, a log of recent relevant supergroup and channel actions, like the modification of group/channel settings or information on behalf of an admin, user kicks and bans, and more.
Pinned messages
Telegram allows pinning multiple messages on top of a specific chat.
Mentions
Telegram allows mentioning other users in case of urgent duckling matters, and quickly navigating to those mentions in order to read them as swiftly as possible.
Scheduled messages
Telegram allows scheduling messages.
Live geolocations
Telegram allows sending the live geolocation of a user in a chat, optionally setting a proximity alert.
Min constructors
Sometimes, user and channel constructors met in group chat updates may not contain full info about the user: how to handle such constructors.
Account deletion
How to reset an account if the 2FA password was forgotten.
Imported messages
Telegram allows importing messages and media from foreign chat apps.
Telegram Passport
How to work with Telegram Passport directly using the MTProto API.
Telegram Payments
How to work with Telegram Payments directly using the MTProto API.
Styled text with message entities
How to create styled text with message entities
Working with animated emojis
Graphical telegram clients should transform emojis into their respective animated version.
Working with animated dice
Telegram supports sending animated dice emojis.
Message drafts
How to handle message drafts
Folders
Working with folders
Top peer rating
If enabled, the rating of top peers indicates the relevance of a frequently used peer in a certain category (frequently messaged users, frequently used bots, inline bots, frequently visited channels and so on).
Handling file references
How to handle file references.
Seamless Telegram Login
Handle Seamless Telegram Login URL authorization requests.
Web events
When interacting with HTML5 games and the websites of payment gateways, Telegram apps should expose the following JS APIs.
Telegram APIs
We offer two kinds of APIs for developers. The Bot API allows you to easily create programs that use Telegram messages for an interface. The Telegram API and TDLib allow you to build your own customized Telegram clients. You are welcome to use both APIs free of charge.
You can also add Telegram Widgets to your website.
Designers are welcome to create Animated Stickers or Custom Themes for Telegram.
Bot API
This API allows you to connect bots to our system. Telegram Bots are special accounts that do not require an additional phone number to set up. These accounts serve as an interface for code running somewhere on your server.
To use this, you don't need to know anything about how our MTProto encryption protocol works — our intermediary server will handle all encryption and communication with the Telegram API for you. You communicate with this server via a simple HTTPS-interface that offers a simplified version of the Telegram API.
Learn more about the Bot API here »
Bot developers can also make use of our Payments API to accept payments from Telegram users around the world.
TDLib – build your own Telegram
Even if you're looking for maximum customization, you don't have to create your app from scratch. Try our Telegram Database Library (or simply TDLib), a tool for third-party developers that makes it easy to build fast, secure and feature-rich Telegram apps.
TDLib takes care of all network implementation details, encryption and local data storage, so that you can dedicate more time to design, responsive interfaces and beautiful animations.
TDLib supports all Telegram features and makes developing Telegram apps a breeze on any platform. It can be used on Android, iOS, Windows, macOS, Linux and virtually any other system. The library is open source and compatible with virtually any programming language.
Learn more about TDLib here »
Telegram API
This API allows you to build your own customized Telegram clients. It is 100% open for all developers who wish to create Telegram applications on our platform. Feel free to study the open source code of existing Telegram applications for examples of how things work here. Don't forget to register your application in our system.
- Getting Started
- Security
- Optimization
- API methods
Getting started
Creating an application
How to get your application identifier and create a new Telegram app.
User authorization
How to register a user's phone to start using the API.
Two-factor authentication
How to login to a user's account if they have enabled 2FA, how to change password.
QR code login
QR code login flow
Error handling
How to handle API return errors correctly.
Handling different data centers
How to connect to the closest DC access point for faster interaction with the API, and things to watch out for when developing a client.
Handling updates
How to subscribe to updates and handle them properly.
Handling PUSH-notifications
How to subscribe and handle them properly.
Channels, supergroups, gigagroups and basic groups
How to handle channels, supergroups, gigagroups, basic groups, and what's the difference between them.
Channel statistics
Telegram offers detailed channel statistics for channels and supergroups.
Calling methods
Additional options for calling methods.
Uploading and Downloading Files
How to transfer large data batches correctly.
Pagination
How to fetch results from large lists of objects.
Client configuration
The MTProto API has multiple client configuration parameters that can be fetched with the appropriate methods.
Security
Secret chats, end-to-end encryption
End-to-end-encrypted messaging.
Security guidelines
Important checks required in your client application.
Perfect Forward Secrecy
Binding temporary authorization key to permanent ones.
End-to-End Encryption in Voice and Video Calls
End-to-end-encrypted calls.
Optimization
Client optimization
Ways to boost API interactions.
API methods
Available method list
A list of available high-level methods.
API TL-schema, as JSON
Text and JSON-presentation of types and methods used in API.
Available layer list
A list of available schema versions.
Other articles
Working with bots, using the MTProto API
How to work with bots using the MTProto API.
Commands
Bots offer a set of commands that can be used by users in private, or in a chat.
Buttons
Users can interact with your bot via buttons or even inline buttons, straight from inline messages in any chat.
Inline queries
Users can interact with your bot via inline queries, straight from the text input field in any chat.
Games
Bots can offer users HTML5 games to play solo or to compete against each other in groups and one-on-one chats; how to work with games in the MTProto API.
Search & filters
Telegram allows applying detailed message filters while looking for messages in chats.
This allows the server to filter messages based on a text query, and even on their type, and this feature is often used by graphical clients to implement features like the chat gallery, chat profile pictures and more.
Polls
Telegram allows sending polls and quizzes, that can be voted on by thousands, if not millions of users in chats and channels.
Reactions
Telegram allows users to react on any message using specific emojis, triggering cute lottie animations.
Invite links and join requests
Channels, basic groups and supergroups may have a public username or a private invite link: private invite links may be further enhanced with per-user join requests.
Admin, banned and default rights for channels, supergroups and groups
How to handle admin permissions, granular bans and global permissions in channels, groups and supergroups.
Discussion groups
Groups can be associated to a channel as a discussion group, to allow users to discuss about posts.
Channel comments and message threads
Telegram allows commenting on a channel post or on a generic group message, thanks to message threads.
Admin log
Both supergroups and channels offer a so-called admin log, a log of recent relevant supergroup and channel actions, like the modification of group/channel settings or information on behalf of an admin, user kicks and bans, and more.
Pinned messages
Telegram allows pinning multiple messages on top of a specific chat.
Mentions
Telegram allows mentioning other users in case of urgent duckling matters, and quickly navigating to those mentions in order to read them as swiftly as possible.
Scheduled messages
Telegram allows scheduling messages.
Live geolocations
Telegram allows sending the live geolocation of a user in a chat, optionally setting a proximity alert.
Min constructors
Sometimes, user and channel constructors met in group chat updates may not contain full info about the user: how to handle such constructors.
Account deletion
How to reset an account if the 2FA password was forgotten.
Imported messages
Telegram allows importing messages and media from foreign chat apps.
Telegram Passport
How to work with Telegram Passport directly using the MTProto API.
Telegram Payments
How to work with Telegram Payments directly using the MTProto API.
Styled text with message entities
How to create styled text with message entities
Working with animated emojis
Graphical telegram clients should transform emojis into their respective animated version.
Working with animated dice
Telegram supports sending animated dice emojis.
Message drafts
How to handle message drafts
Folders
Working with folders
Top peer rating
If enabled, the rating of top peers indicates the relevance of a frequently used peer in a certain category (frequently messaged users, frequently used bots, inline bots, frequently visited channels and so on).
Handling file references
How to handle file references.
Seamless Telegram Login
Handle Seamless Telegram Login URL authorization requests.
Web events
When interacting with HTML5 games and the websites of payment gateways, Telegram apps should expose the following JS APIs.
Create a Telegram bot | Selectel Knowledge Base
Using bots, you can simplify the task of communicating with users by creating a smart assistant for them. Bots understand text commands and can access the API of your website, service, or be a standalone product with unique services. Usually, a server is required to create a bot, but in this article we will analyze an approach that allows us to do without it. It is ideal for large fluctuations in the number of requests and perfectly withstands peak loads.
You can set up a Telegram bot on Cloud Functions using the official API and an example prepared by us in 3 steps:
- Program the logic of the Telegram bot.
- Register a new bot in Telegram.
- Link the bot and its logic together.
Program the logic of the Telegram bot
To simplify the task, we have written an example of such a bot. Its source code is available at github.com/selectel/cloud-telegram-bot. He understands commands:
-
/start
with a welcome message; -
/sticker
with a sticker; -
/getwebhook
so you can get information about your bot settings; -
/setwebhook
to set up your bot, but more on that later.
Go through the following steps with our example bot to get comfortable:
- Download the source code as an archive ("Clone or download" → "Download ZIP") and extract it.
- Inside should be:
- "setup.py" with minimal code so that the Python environment takes the contents of the folder as a module to install;
- "requirements.txt" with a description of the dependencies;
- "bot" is the folder with the source code of our bot.
- Select all these files and folders, and then create a new ZIP archive from them, then the source code inside the archive will not have extra folders (as is the case with the archive downloaded from github).
- Go to control panel section Cloud Platform → Function and press the button Create Function .
- Select the runtime and give it a name, such as
Bot
. - In the Load field, select Archive .
- Download the ZIP file as Feature Code .
- Specify Path to file as
/bot/tele_bot.py
. - Specify Callable function as
main
. - Get the token according to the instructions and in the field Environment variables add its key and value.
- Click the Save and Deploy button .
- To get a link to call the function, go to the Triggers tab and click on the HTTP request toggle switch.
Now we have an API that implements the bot response logic. The next step is to register it in Telegram.
Register a new bot in Telegram
In order for Telegram to know about the existence of our bot, it needs to be registered. There is only one way to do this:
- Find the @BotFather bot in Telegram. This is an official bot created specifically for managing bots.
-
Send him a command:
/newbot
-
@BotFather will ask you what you want to name your bot. In the next message, send its name ending in "_bot".
-
Write down the received token from @BotFather - this is the key for working with the Telegram API.
Now we have an API, registering a bot in Telegram and its token. It remains to tie it together.
How to link the bot and its logic together?
At this stage, you need to make sure that the bot knows the user's token, and Telegram knows where its API is:
- Find the "TOKEN" environment variable in the function settings. We left it empty at the first stage.
- Set this variable to your bot's token that you received from @BotFather.
- Click Save and Expand .
Next, we need to send the messages that users send to Telegram to our bot - to the API that was created for it.
Method 1. Through the @SelectelServerless_bot bot
- Find the @SelectelServerless_bot bot in Telegram.
-
Enter command:
/setwebhook
-
The bot will respond with what it receives from the Telegram API. If everything is fine, it will be "true".
-
To make sure everything is correct, send the command:
/getwebhook
-
The response should contain information about the webhook, including the URL you specified.
Method 2. From a prepared form
Open the form (or copy it to your Cloud storage). Paste the token from your bot into the first field, the URL of the cloud function into the second and click on the "Set Webhook" button. Api.telegram.org will be called and you will see the result.
Note: VPN may be required.
Total
Ready for work, a bot available in Telegram that responds to commands and is able to automatically scale under load and without a server.
What is the Telegram API
Back
What is API
To begin with, we will talk about what is generally hidden under this abbreviation. To make it clearer for you, first we will delve into the origins of the history of programming. Once upon a time, code was written completely from scratch. That is, in order for the program to simply show the user some word, the developer had to manually write it in machine language, using only 0 and 1. Of course, it could not always go on like this, so one day it was decided to automate this whole process by creating libraries with a built-in set of functions. That is, to display “Hi”, the developer had to simply write “cout << “Hi””, and the file he connected himself translated this into a sequence of zeros and ones. Realizing that this is quite convenient, the developers introduced the concept of "API" - a built-in interface that allows you to send commands to the operating system, computer, or something else in a language that it understands. APIs have automated the creation of games or the writing of office programs, making, for example, applying a texture to an object easier.
What telegram API is for
Now that you understand the essence of this, let's move on to a more specific example. Namely, to the interface of bots for telegrams. It allows you to: Program your bot. Ask him various commands for interacting with users. Get convenient access. In fact, without an API, bot programmers would have to write their own artificial intelligence every time. With its use, everything becomes much easier. This API has ready-made functions for outputting and entering text, answering prescribed questions, and other things like that. That is, in fact, the developer only needs to enter his own text, if we are talking about a very primitive robot.
What scripting language does telegram use
If you seriously took up the task of writing a robot, then the first thing that comes to your mind is the question: “What language does everything work here in? Is there some built-in language like apibridge? In fact, this question cannot be answered unambiguously. To perform all its functions, the messenger uses: The language in which all commands for robots are written. HTML. It is used to create all the favorite and recently released games. JavaScript. Used for some scripts.
What is json and how is it related to the telegram API
Finally, the last thing you need to know in order to understand how the messenger and its bots function is what json is.