Skip to content

Protocol Reference

mtgo-ipc uses JSON-RPC 2.0 over a Unix domain socket. Framing is newline-delimited JSON — one message per line terminated by \n.

Message Types

Three message types share the wire:

DirectionTypeKey fieldExample
client → serverRequestmethod + id{"jsonrpc":"2.0","id":1,"method":"health"}
server → clientResponseresult/error + id{"jsonrpc":"2.0","id":1,"result":{"status":"ok"}}
server → clientEventevent (no id){"event":"updates.raw","data":{...}}

Clients distinguish messages by shape: if it has event, it's a push update; if it has id without method, it's a response; if it has method, it's a request.

Methods

health

Liveness probe. Does not touch the Telegram connection.

json
→ {"jsonrpc":"2.0","id":1,"method":"health"}
← {"jsonrpc":"2.0","id":1,"result":{"status":"ok"}}

mtgo.info

Returns build metadata and connection state.

json
← {"jsonrpc":"2.0","id":2,"result":{"name":"mtgo-ipc","version":"0.1.0-dev","connected":true,"api_id":22333936,"dc":4}}

mtgo.connect

Connects to Telegram. Credentials are provided by the client — the server starts with none.

Params:

FieldTypeRequiredDescription
api_idintyesTelegram API ID
api_hashstringyesTelegram API hash
bot_tokenstringnoBot token (alternative to session)
sessionstringnoSession string (Telethon/Pyrogram/GramJS/mtcute — auto-detected)
json
→ {"jsonrpc":"2.0","id":3,"method":"mtgo.connect","params":{"api_id":22333936,"api_hash":"...","bot_token":"123:ABC"}}
← {"jsonrpc":"2.0","id":3,"result":{"connected":true}}

Idempotent

If already connected, returns {"connected":true} without re-authenticating. The first caller's credentials establish the session.

mtgo.close

Disconnects from Telegram. The server stays alive — call mtgo.connect to reconnect.

auth.status

Reports the current authentication state.

json
← {"jsonrpc":"2.0","id":5,"result":{"authorized":true,"user_id":5998453459,"is_bot":true,"username":"DavidSiteBot"}}

telegram.invoke

Executes any Telegram MTProto TL function by name with JSON arguments.

Params:

FieldTypeDescription
methodstringTL function name (e.g. "help.getConfig")
argsobjectJSON arguments matching TL request struct fields
json
→ {"jsonrpc":"2.0","id":6,"method":"telegram.invoke","params":{"method":"help.getConfig","args":{}}}
← {"jsonrpc":"2.0","id":6,"result":{"_":"config","dc_options":[...],"this_dc":4,...}}

getMe — the MTProto equivalent of Bot API getMe:

json
→ {"jsonrpc":"2.0","id":7,"method":"telegram.invoke","params":{"method":"users.getFullUser","args":{"id":{"_":"inputUserSelf"}}}}
← {"jsonrpc":"2.0","id":7,"result":{"_":"users.userFull","users":[{"id":5998453459,"username":"DavidSiteBot","bot":true,...}]}}

Requires connection

Returns error code -32001 if called before mtgo.connect succeeds.

Error Codes

CodeMeaning
-32700Parse error
-32600Invalid Request
-32601Method not found
-32602Invalid params
-32603Internal error
-32001Not connected

Released under the Apache-2.0 License.