目標:不寫專案,跑通最小三件套 getMe → getUpdates → sendMessage。在下面選擇你的平台。需要一個真實 bot token,請保密。
總覽
這是確認「token 可用 + 能發訊息」的最快方式。三個呼叫與平台無關,只是工具不同(Windows 用 PowerShell,iOS 用捷徑)。
前置條件
一個 mpbot token(測試/開發用,與生產 Bot 隔離)。
你已在 MPChat 裡給該 Bot 發過至少一則訊息——Bot 不能主動發起會話,這一步用來產生
chat_id。切勿透過 iCloud、截圖或聊天分享 token。
Windows:PowerShell(三步)
先為目前工作階段設定 token,再依序執行:
$token = "YOUR_MPBOT_TOKEN"# 1) getMe - 驗證 token
Invoke-RestMethod -Uri "https://call.mp.net/bot/bot$token/getMe" -Method Get# 2) getUpdates - 從你之前的訊息裡讀 chat_id
$body = '{"timeout":5,"limit":10}'
Invoke-RestMethod -Uri "https://call.mp.net/bot/bot$token/getUpdates" -Method Post -ContentType "application/json" -Body $body# 3) sendMessage - 回覆(貼上第 2 步拿到的 chat id)
$send = '{"chat_id":"YOUR_CHAT_ID","text":"Hello from mpbot."}'
Invoke-RestMethod -Uri "https://call.mp.net/bot/bot$token/sendMessage" -Method Post -ContentType "application/json" -Body $send
iOS:捷徑(三步)
建立三個「取得 URL 內容」捷徑。token 透過「要求輸入」傳入——不要開啟 iCloud 共享。
getMe:GET
https://call.mp.net/bot/bot{token}/getMe——成功標誌是"ok": true。getUpdates:POST,標頭
Content-Type: application/json,內文{"timeout":5,"limit":10}。讀取result[].message.chat.id。sendMessage:POST,內文
{"chat_id":"<chat_id>","text":"Hello from mpbot."}。
如何判讀成功
所有回應都是 JSON。成功形如
{ "ok": true, "result": ... }。第 3 步之後,訊息會出現在你與該 Bot 的 MPChat 會話裡。
排查
401:token 錯誤或已 revoke——重新核對。
getUpdates 回傳 []:你還沒給 Bot 發訊息,或 updates 已被消費。
409:已啟用 Webhook,與輪詢互斥。請勿自行執行
deleteWebhook,聯絡 Bot 維護者。sendMessage 回傳 400:
chat_id錯誤或會話尚未建立。
相關文章
這是參數簡化的試跑流程。正式開發請用 curl/Node.js 快速接入,並正確處理 offset。
