skip to Main Content

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.

5

Answers


  1. 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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
  4. 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.

    Login or Signup to reply.
  5. For any javascript users,
    use telegram package in npm

    npm install telegram
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search