Search code examples
tcptelegrammtproto

How to make a query to Telegram API in cmd or bash


One of the first steps to start using the API is this. I have MTProto server (149.154.167.40:443), phone number, api id, hash...

How do I exactly do it? How do I make such a query? I sooo don't get it.

Thanks in advance


Solution

  • There are two classes of MTProto methods: Encrypted and Plain.

    Before you can start sending encrypted messages you need a valid session (and server salt) in one of Telegram's DCs (Data Centers).

    To create a valid session, you need to go through the process of creating an Auth-Key. Going through this process will get you started on how to communicate with the Telegram Server.

    All the examples linked below communicate with Telegram Servers via TCP

    1. Obtain your API Keys as outlined here https://core.telegram.org/api/obtaining_api_id
    2. You need to perform the basic Auth-key creation as outlined here, this gives you your initial Session & Server_Salt
    3. Next you complete these steps
    4. You can now properly send the request you attempted in the sample code

    msg = TL.invokewithlayer(@layer, TL.initconnection(@app_id, @device_model, @system_version, @app_version, @lang_code, TL.help_getnearestdc))

    MTProto format is: auth_id + msg_key + enc_payload

    enc_payload = AES_IGE_enc(payload)
    
    payload = salt + session_id + msg_id + seq_no + len(msg) + msg + padding
    

    You can get the above from here