Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to interact with Telegram API

I'm really confused as I'm trying to use Telegram's APIs after reading a lot of the documentation on http://core.telegram.org.

I have registered my app and got a hash_id and all of that stuff. But I'm not sure where to begin with.

I had worked with Spotify's API before, and was able to interact with it using http://api.spotify.com/v1/method?params:values form.

I can't find the URL for Telegram's API. I also searched a lot on the internet but couldn't find any useful examples.

Does anyone know anything about getting started to work with Telegram's API? Any help would be appreciated.

like image 558
Ramtin Soltani Avatar asked Jul 05 '15 08:07

Ramtin Soltani


People also ask

Can we use Telegram as an API?

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.

How does Telegram Bot API work?

How do bots work? At the core, Telegram Bots are special accounts that do not require an additional phone number to set up. Users can interact with bots in two ways: Send messages and commands to bots by opening a chat with them or by adding them to groups.

Is Telegram API free?

We offer our API free of charge, but your users must be aware of the fact that your app uses the Telegram API and is part of the Telegram ecosystem. This fact must be featured prominently in the app's description in the app stores and in the in-app intro if your app has it.


2 Answers

If you really want to understand Telegram API development from scratch. My advice would be to follow the steps here

https://core.telegram.org/mtproto/auth_key

and here

https://core.telegram.org/mtproto/samples-auth_key

Try to successfully generate an AuthKey.

This exercise will get you familiar with enough of the basics as well as help you build up routines you will need to do further work on Telegram API.

I have outlined the basics for you to get started in this SO post.

Also i think the API documentation online is not so well-written, but following the above step by step while reading the API documentation, for just AuthKey generation, would get you familiar with the language and writing style of the authors of the API

Good Luck.

like image 195
Charles Okwuagwu Avatar answered Oct 23 '22 06:10

Charles Okwuagwu


The Telegram API is not as easy to use as a normal HTTP/Rest API, you have to interact with their MTProto protocol. You also have to do all sorts of encryption and decryption. Telegram recently released a new Bot API which abstracts all the complications behind a decent HTTP API. Usage example in NodeJS using https://github.com/arcturial/telegrambot:

var TelegramBot = require('telegrambot'); var api = new TelegramBot('<YOUR TOKEN HERE>');  api.getUpdates({ offset: 0 }, function (err, updates) {     // array of message updates since last poll     console.log(updates); });  api.sendMessage({ chat_id: 0, text: 'test' }, function (err, message) {     // the chat_id is the id received in the getUpdates() call }); 

The token can be generated using their BotFather application. You can also use their deep-linking feature to add a link to your website to initiate a conversation with the bot, like so:

https://telegram.me/triviabot?start=payload

The payload value can be anything you want, like a cache key you might use for validating a real person etc.

I know it doesn't directly answer your question, but from personal experience I found it's better to interact with the Bot API than trying to implement all the intricacies required for the normal API. If you are adamant about using their normal API, the IPs are 149.154.167.40:443 (test) and 149.154.167.50:443 (production). They provide the IP details under https://my.telegram.org/apps.

like image 43
Chris Brand Avatar answered Oct 23 '22 07:10

Chris Brand