Telegram MT v0.1.1-alpha MTProto.Session View Source

Provide advanced control over sessions.

Session

%MTProto.Session{auth_key: <<0, 0, 0, 0, 0, 0, 0, 0>>, b: nil, client: nil,
dc: nil, dh_prime: nil, g_a: nil, handler: nil, initialized?: false,
last_msg_id: 0, listener: nil, msg_seqno: 0, new_nonce: nil,
phone_code_hash: nil, seqno: 0, server_nonce: nil, server_salt: 0, socket: 0,
user_id: nil}
  • :user_id - Telegram ID of the user
  • :auth_key - authorization key, default to <<0::8*8>>
  • server_salt - default to 0
  • :handler - PID of the process handling messages (parse, dispatch, send);
  • :listener - PID of the process listening for incoming messages
  • :dc - id of the datacenter used by the session (1,2,3,4,5). See MTProto.DC
  • :initialized - was the session initialized ? (See MTProto.API.init_connection/5)
  • :phone_code_hash - phone_code_hash returned when sending code (SMS, call, open client)
  • :seqno - sequence number
  • :msg_seqno - message sequence number
  • :socket - socket used to receive and send message (to Telegram’s servers)

Link to this section Summary

Functions

Close a session given its id. Stop both listener and handler, remove the session from the registry

Export {user_id, auth_key, server_salt} from a session

Import user_id, auth_key and server_salt to a session

Open a new session. dc_id is used to select which datacenter to connect, client is the PID of the process to be notified when receiving new messages

Send a message to telegram’s servers on session session_id. Default behavior is to send an encrypted message : you can send a plaintext message by specifying :plain as third argument. Returns

Set the PID (client) of the process to be notified when receiving new messages on session session_id

Link to this section Functions

Close a session given its id. Stop both listener and handler, remove the session from the registry.

Export {user_id, auth_key, server_salt} from a session.

Link to this function import(session_id, user_id, auth_key, server_salt) View Source

Import user_id, auth_key and server_salt to a session.

Link to this function open(dc_id, client \\ nil) View Source

Open a new session. dc_id is used to select which datacenter to connect, client is the PID of the process to be notified when receiving new messages.

Returns the session_id.

Link to this function send(session_id, message, type \\ :encrypted) View Source

Send a message to telegram’s servers on session session_id. Default behavior is to send an encrypted message : you can send a plaintext message by specifying :plain as third argument. Returns :

  • {:ok, message_id}
  • {:err, reason}
Link to this function set_client(session_id, client) View Source

Set the PID (client) of the process to be notified when receiving new messages on session session_id.