API 參考
渠道方對比

Telegram 接入授權

Telegram 支援 code(驗證碼)、qrcode(QR Code)同 session(會話匯入)三種 auth_mode,統一行 /v1/accounts 同標準授權接口:/auth/start、/auth/code、/auth/password、/auth/qr/start、/auth/qr/check、/auth/session。

code

驗證碼流程:平台發起驗證碼請求,使用者經 SMS 或者 App 內收到再回傳返。

  1. 1. POST /v1/accounts,provider=telegram、auth_mode=code,provider_data 入面要有 api_id、api_hash、phone。
  2. 2. POST /v1/accounts/{account_id}/auth/start,叫 Telegram 落驗證碼。
  3. 3. 使用者收到驗證碼後,POST /v1/accounts/{account_id}/auth/code 把驗證碼送返。
  4. 4. 帳號開咗二階段驗證嘅話,status 會變 awaiting_password — 叫 POST /v1/accounts/{account_id}/auth/password 送密碼。
  5. 5. 成功後叫 POST /v1/accounts/{account_id}/runtime/start 開啓帳號上線。
  • provider_data.api_id喺 my.telegram.org 申請到嘅 Telegram App ID。Telegram 三種流程都要填。
  • provider_data.api_hash喺 my.telegram.org 申請到嘅 Telegram App Hash。Telegram 三種流程都要填。
  • provider_data.phone帳號綁定嘅 E.164 電話號碼。只有 code 流程用到。

qrcode

QR Code 流程:攞 QR token,俾使用者喺 Telegram App 入面掃。

  1. 1. POST /v1/accounts,provider=telegram、auth_mode=qrcode,provider_data 提供 api_id / api_hash。
  2. 2. POST /v1/accounts/{account_id}/auth/qr/start,回應入面就會有要顯示嘅 QR token。
  3. 3. 輪詢 POST /v1/accounts/{account_id}/auth/qr/check,等到 status=authorized。QR 大概 30 秒過期,過期再叫一次 qr/start 就更新。
  4. 4. 成功後叫 POST /v1/accounts/{account_id}/runtime/start。
  • provider_data.api_id喺 my.telegram.org 申請到嘅 Telegram App ID。Telegram 三種流程都要填。
  • provider_data.api_hash喺 my.telegram.org 申請到嘅 Telegram App Hash。Telegram 三種流程都要填。

session

會話匯入流程:將已有授權會話匯入 UnifyPort。

  1. 1. POST /v1/accounts,provider=telegram、auth_mode=session。
  2. 2. POST /v1/accounts/{account_id}/auth/session,params.session_url 指去個可以下載嘅 .session 檔。
  3. 3. import 嘅回應確認 session 有效後,POST /v1/accounts/{account_id}/runtime/start。
  • params.session_url已有 Telegram 會話嘅 URL 或參考。

備註

  • 二階段密碼每次試都係無狀態。打錯密碼就先 cancel,再重新行 /auth/qr/start 或 /auth/start。
  • QR token 大概 30 秒就過期。過期再叫一次 qr/start 就更新到 — 前端記住重新畫 QR。
  • 帳號設定階段就會自動 inject 個 webhook URL,授權狀態變化同登入事件會同入站訊息行同一個 webhook 端點。