62

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.

Ramtin Soltani
  • 2,650
  • 3
  • 24
  • 45

5 Answers5

37

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.

Community
  • 1
  • 1
Charles Okwuagwu
  • 10,538
  • 16
  • 87
  • 157
  • Is there any libraries for android.? – yadunath.narayanan Feb 04 '17 at 19:58
  • Like other APIs we have a particular code written by the API provider for just including that piece of code to your app and APIs are ready to be used. Is there any such thing for Telegram API? I just want to start from scratch. – Climb Tree May 20 '17 at 14:10
21

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.

Chris Brand
  • 1,962
  • 16
  • 9
  • 1
    Thanks for the answer. My main goal is to write a simple Telegram Client which is able to send messages to contacts (by checking if the phone number is registered in Telegram). And I want to do this in C#. Which method do you recommend the most? Can the Bot API be used to invoke the methods in Telegram API (or methods of Bot API similar to those)? – Ramtin Soltani Jul 07 '15 at 01:56
  • 4
    The Bot API works well if you want to create an application that can integrate with Telegram (think Slack and Slack integrations), like seeings Jenkins/Travis CI build notifications display in your Telegram chat. Bots don't have to be assigned to a number. If you want to create a client that allows person to person message sending, then you have to use the normal Telegram API. Unfortunately I have had little luck getting it to work properly, I can only suggest you have a look at the samples https://github.com/zhukov/webogram or https://github.com/enricostara/telegram.link – Chris Brand Jul 07 '15 at 05:55
  • @ChrisBrand I know this is an old post, but did you have any luck with the normal Telegram API? I am getting a "getaddrinfo ENOTFOUND api.telegram.org api.telegram.org:443" error when trying to `POST` to the Telegram API using `nodejs`. When I do it in Postman, it works fine – deanwilliammills Jan 06 '19 at 18:11
  • Bot api is not complete( You can't call a number of API methods from bot api – Green Oct 04 '22 at 15:50
12

I was looking for a quick solution to interact with Telegram API (not bot API which is limited) and integrate it with a python project. Found the following python client implementation which was a big help. Hope it helps someone. As others have mentioned, telegram API is complicated to understand, but you can get going with Telethon in a very short time without pre knowledge about the telegram API protocol.

https://github.com/LonamiWebs/Telethon

To install telethon just type:

pip install telethon

Here is a short code demonstrating how easy you can get to use the API to print recent chats:

enter image description here The example taken from telethon github page.

apadana
  • 13,456
  • 15
  • 82
  • 98
0

For .NET programmers, there is now WTelegramClient, that allows you to call Telegram Client APIs (connecting as a user, not bot).

The library is very complete but also very simple to use. Follow the README on GitHub for an easy introduction.

It requires a permanent connection, but it can be integrated in an ASP.net website. See this FAQ, it contains an example website.

Wizou
  • 1,336
  • 13
  • 24
-1

For any javascript users, use telegram package in npm

npm install telegram