Telegram MT v0.0.1-alpha MTProto

MTProto implementation for Elixir. At this time, the project is still far from complete : expect things to break.

Other resources

A demo client is avaible on github. You may also want to take a look to the README page of the project, where you can find more detailed informations and examples.

Overview

This library allows you to handle mutiple users, which is fondamental since it was originally designed in order to build bridges between Telegram and other messaging services. Each session is equivalent to an user and has its own connection to Telegram’s servers. Note that you have to set (see MTProto.Session.set_client/2) a process to be notified of incoming messages for every session.

  • MTProto (this module) - provides a “friendly” way to interact with ‘low-level’ methods. It allow you to connect/login/logout/send messages.
  • MTProto.API (and submodules) - implementation of the Telegram API, as explained here and here.
  • MTProto.Session : Provides manual control over sessions.
  • Many modules [1] are not designed to be used by the “standard” user hence are not documented here. You’re welcome to take a look/contribute : everything is on github.

[1] : MTProto.Session.Brain, MTProto.Session.Handler, MTProto.Session.HandlerSupervisor, MTProto.Session.Listener, MTProto.Session.ListenerSupervisor, MTProto.Auth, MTProto.Crypto, MTProto.DC, MTProto.Method, MTProto.Payload, MTProto.Registry, MTProto.Supervisor and MTProto.TCP.

Summary

Functions

Connect and create a session on the specified DC. If dc_id is not provided, connect to a random DC (out of the 5 available DC.) If there is no authorization key related to the DC, the authorization key generation will be initiated

Fetch the the contact list

Send an encrypted message to Telegram on the session sid. Similar (alias) to MTProto.Session.send(sid, msg, :encrypted)

Initiate the authentification procedure by sending a message to the account linked to the provided phone number on the session session_id (generated with connect/1)

Initilize the connection (if not initialized yet) with default values and the version of API layer to use

Sign in given the phone number and the code received from Telegram (by SMS, call, or via an open client). phone_code_hash is returned in the response to MTProto.send_code/2and is stored in the session. You don’t need to provide it, but you can override the phone_code_hash stored in the session by providing it here

Log out the user

Start the supervision tree and set default values in the registry. Automatically started

Functions

connect(dc_id \\ :random)

Connect and create a session on the specified DC. If dc_id is not provided, connect to a random DC (out of the 5 available DC.) If there is no authorization key related to the DC, the authorization key generation will be initiated.

Returns {:ok, session_id}.

get_contacts(session_id)

Fetch the the contact list.

send(session_id, msg)

Send an encrypted message to Telegram on the session sid. Similar (alias) to MTProto.Session.send(sid, msg, :encrypted).

send_code(session_id, phone)

Initiate the authentification procedure by sending a message to the account linked to the provided phone number on the session session_id (generated with connect/1).

send_message(session_id, dst_id, content, type \\ :contact)

Send a text message to an user/group.

  • session_id
  • dst_id - ID (integer) of the recipient of the message
  • content - content of the message (string)
  • type - type of the recipient, either an user (:contact) or a group (:chat)
send_with_initialization(session_id, msg)

Initilize the connection (if not initialized yet) with default values and the version of API layer to use.

sign_in(session_id, phone, code, code_hash \\ :session)

Sign in given the phone number and the code received from Telegram (by SMS, call, or via an open client). phone_code_hash is returned in the response to MTProto.send_code/2and is stored in the session. You don’t need to provide it, but you can override the phone_code_hash stored in the session by providing it here.

sign_out(session_id)

Log out the user.

start(type, args)

Start the supervision tree and set default values in the registry. Automatically started.