~fnux/telegram-mt-elixir

Native MTProto implementation for Elixir
65645d44 — Timothée Floure 3 years ago
Add deprecation warning, redirect to elixir-tdlib
9820eb43 — Timothée Floure 3 years ago
Fix type issue in example config file
1deb1855 — Timothée Floure 4 years ago
Fix typo in CHANGELOG.md

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~fnux/telegram-mt-elixir
read/write
git@git.sr.ht:~fnux/telegram-mt-elixir

You can also use your local clone with git send-email.

#This project is being abandonned in favor of bindings with telegram's tdlib

Telegram released a C++ library with a JSON interface. Since MTProto is a pain to implement, I drop this project (= native implementation in elixir) in favor of elixir-tdlib.


#Telegram MT(Proto)

MTProto implementation in elixir. The project is still in alpha : Expect things to break. Note that it's my fisrt real elixir project, so it's probably awful.

This library is on hex.pm and the documentation is available here.

#Status & Roadmap

Version v0.1.1-alpha has been released (changelog).

Status : you currently can signin, receive and send message, fetch contacts and chats, save and restore sessions.

#Configuration

Don't forget to add (and fill!) the following to your config.exs :

# You can find your API ID and API HASH on https://my.telegram.org/
config :telegram_mt,
  api_id: "00000", # Required.
  api_hash: "00000", # Required.
  msg_max_retry_count: 2, # Required. Maximum number of retry for a failed message.
  public_key: "public_key" # Optional. Custom path for Telegram's public key.

# Optional. Custom configuration for the `telegram_tl` library.
config :telegram_tl, tl_path: "/path/to/mtproto.json",
  api_version: 57,
  api_path: "/path/to/api-layer-57.json"

#Overview

This library allows you to handle mutiple users, which is fondamental since it was originally designed 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.
  • MTProto.DC : Provides manual control over DCs.
  • Many modules [1] are not designed to be used by the "standard" user hence not documented here.

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

Each session has one listener and one handler (they are registered in the SessionRegistry registry). The DCRegistry registry saves the data related to each specific DC (Telegram uses 5 DCs) such as the address or the authorization key.

#Example

» iex -S mix

Interactive Elixir (1.4.0) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> MTProto.start()

09:41:19.160 [info]  Starting Telegram MT.
{:ok, #PID<0.164.0>}

iex> {:ok, session_id} = MTProto.connect(4) # Connect to DC 4

09:42:02.934 [debug] [Handler] 5144610857678255187 : starting handler.
09:42:02.935 [debug] [Listener] 5144610857678255187 : starting listener.
{:ok, 5144610857678255187}

iex> MTProto.request_authkey(session_id)

09:43:21.153 [debug] Requesting authorization key for session 5144610857678255187...
09:43:21.993 [debug] The authorization key was successfully generated.

iex> MTProto.send_code(session_id, "0041123456789")

No client for 5144610857678255187, printing to console.
{5144610857678255187,
 %{msg_id: 6444013746561167361, name: "rpc_result",
   req_msg_id: 6444013745160060928,
   result: %{is_password: %{name: "boolFalse"}, name: "auth.sentCode",
     phone_code_hash: "qwertzuiopasdfg123",
     phone_registered: %{name: "boolTrue"}, send_call_timeout: 120}}}

iex> MTProto.sign_in(session_id, "0041123456789", "01234")

No client for 5144610857678255187, printing to console.
{5144610857678255187,
 %{msg_id: 6444014010308812801, name: "rpc_result",
   req_msg_id: 6444014007153065984,
   result: %{expires: 2147483647, name: "auth.authorization",
     user: %{first_name: "Fnux", id: 122205918, inactive: %{name: "boolFalse"},
       last_name: "", name: "userSelf", phone: "41123456789",
       photo: %{name: "userProfilePhoto",
         photo_big: %{dc_id: 4, local_id: 52832, name: "fileLocation",
           secret: 01234567890123456789, volume_id: 430507451},
         photo_id: 524870421643897743,
         photo_small: %{dc_id: 4, local_id: 52830, name: "fileLocation",
           secret: 123456789012345678, volume_id: 430507451}},
       status: %{name: "userStatusOffline", was_online: 1500363697},
       username: "fnux_ch"}}}}