Telegram MT v0.0.1-alpha MTProto.Session

Provide advanced control over sessions.

Session

%MTProto.Session{client: nil, dc: nil, handler: nil, initialized?: false,
listener: nil, msg_seqno: 0, phone_code_hash: nil, seqno: 0, socket: 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)

Summary

Functions

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

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

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

Functions

close(session_id)

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

open(dc_id, client \\ nil)

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

send(session_id, message, type \\ :encrypted)

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.

set_client(session_id, client)

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