Telegram
telegram package 以 long polling、同步 reply dispatch、媒體 helper 與 Telegram 專屬互動功能封裝 github.com/go-telegram/bot。
生命週期與 input
New(token, opts...) 驗證 token 非空,但不啟動 polling。Start(ctx) 呼叫 GetMe、檢查 webhook,必要時移除既有 webhook,接著啟動 polling。Close() 取消 loop 並清除 status 與 multi-select state。
Input 包含 ChatID、ChatName、MessageID、sender 欄位、text/caption、Photo、Document、CallbackData、CallbackPicks 與 raw update。
訊息與媒體
| Method | 行為 |
|---|---|
Send |
可選 reply target,以及 MarkdownV2 或 HTML parse mode |
SendFile |
streaming 上傳 document、video 或 audio 路徑 |
SendPhoto |
單張照片或 2–10 張 album |
SendVoice |
將 tts.Get 結果上傳為 voice.ogg |
Save |
下載檔案,硬上限 20 MiB |
互動 prompt
SendInput 使用 ForceReply。SendSelect 每個項目建立一個 inline button;callback 先 ack、清 keyboard,再以 CallbackData 呼叫 Reply。SendMultiSelect 會建立 toggle button 與 Done;toggle 只重繪 state,Done 清 keyboard 後以 CallbackPicks 呼叫一次 handler。
Status
SendStatus 會為每個 chat 建立或編輯一則 debounce 訊息。第一次 flush 會在原訊息加預設 🤔 reaction。FinishStatus 清 reaction 並刪除 status 訊息。