API pipeline: Connect a Telegram account as an oracle (phone → code → 2FA), start and stop it, sign it in again when Telegram asks

Index: API pipelines — index

Goal: a Telegram account of yours works as an oracle: it answers people under its agenda and runs your campaigns. You sign it in once (phone → code → 2FA), start and stop it, and sign it in again when Telegram ends its session.

Steps

1. Request the login code. Choose a session_key (any unique string, e.g. a UUID) and reuse it in steps 1–4. api_id and api_hash come from my.telegram.org.

POST /v0/my/oracles/register
{"step": "start", "session_key": "3f6c…", "phone": "+15550000000",
 "api_id": "12345678", "api_hash": "0123abcd…"}
→ {"session_key": "3f6c…", "state": "awaiting_code"}

2. Send the code Telegram delivered to the account.

POST /v0/my/oracles/register
{"step": "code", "session_key": "3f6c…", "code": "12345"}
→ {"session_key": "3f6c…", "state": "awaiting_password"}   2FA is on: step 3
→ {"session_key": "3f6c…", "state": "authorized"}          no 2FA: step 4

3. 2FA cloud password (only when asked).

POST /v0/my/oracles/register
{"step": "password", "session_key": "3f6c…", "password": "…"}
→ {"session_key": "3f6c…", "state": "authorized"}

Any step may answer {"state": "failed", "error": "…"}: start over with a new session_key.

4. Create the oracle with the same session_key, right after the last step.

POST /v0/my/oracles
Idempotency-Key: oracle-anna-1
{"kind": "mtproto_account", "title": "Anna", "session_key": "3f6c…",
 "project": "<your Pro project>", "agenda": "<agenda nonce>"}
→ {"nonce": "470000000000000001", "card_type": "oracle", "kind": "mtproto_account",
   "status": "STOPPED", "phone_masked": "+15•••••••00", …}

5. Start and stop.

POST /v0/my/oracles/470000000000000001/start
→ {"success": true, "status": "STARTING"}

Poll GET /v0/my/oracles/{nonce} every few seconds: ACTIVE (running, usually within a minute), FAILED (session_note says why), REAUTH_REQUIRED or PENDING (step 6). POST …/stop → {"success": true, "status": "STOPPED"}.

6. Sign in again when the status is REAUTH_REQUIRED (Telegram ended the session) or PENDING (sign-in never finished).

POST /v0/my/oracles/{nonce}/reauth/start      {}
→ {"session_key": "9a1b…", "state": "awaiting_code", "phone_masked": "+15•••••••00", "status": "REAUTH_REQUIRED"}
POST /v0/my/oracles/{nonce}/reauth/code       {"session_key": "9a1b…", "code": "12345"}
→ {"state": "awaiting_password", …}  or  {"state": "complete", …}
POST /v0/my/oracles/{nonce}/reauth/password   {"session_key": "9a1b…", "password": "…"}
→ {"state": "complete", "status": "…"}

Behind

Rules

API surface

Endpoint Purpose FE AI / oracle
POST /v0/my/oracles/register Sign-in steps: start, code, password yes user's own AI, with the person at hand
POST /v0/my/oracles Create the oracle from a finished sign-in yes yes
GET /v0/my/oracles, GET /v0/my/oracles/{nonce} List; status, session_note, restriction yes yes
PATCH /v0/my/oracles/{nonce} Agenda, project, listen_dm, gender, text yes yes
POST /v0/my/oracles/{nonce}/start, /stop Run / stop yes yes
POST /v0/my/oracles/{nonce}/reauth/start, /code, /password Sign in again yes user's own AI, with the person at hand
DELETE /v0/my/oracles/{nonce} Stop and delete yes rarely

Mentioned