v0.5.0

Telegram API

最後更新


github.com/pardnchiu/go-bot/core/telegram 的全部 exported 符號,底層為 github.com/go-telegram/bot v1.20.0。

型別


符號定義說明
Botstruct(欄位未匯出)以 New 建立;方法可並行呼叫
Statusstruct { Running bool; Username string; UserID int64 }Status() 的回傳值
Inputstruct欄位:ChatID int64、ChatName string、MessageID int、UserID int64、Username string、Text string、Caption string、Photo []models.PhotoSize、Document *models.Document、CallbackData string、CallbackPicks []string、Raw *models.Update。見 Telegram 設定
ReplyHandlerfunc(ctx context.Context, input Input) string
ChatStatusstruct(欄位未匯出)SendStatus 管理的每個 chat 狀態項目;呼叫端不需建立
Optionfunc(*options)New 的選項
MessageOptionfunc(*messageOptions)Send、SendInput、SendSelect、SendMultiSelect 的選項
StatusOptionfunc(*statusOptions)SendStatus 的選項
SendTypeint常數 TypeMarkdown(MarkdownV2)、TypeHTML
FileTypeint常數 TypeDocument、TypeVideo、TypeAudio

建構子與選項


函式效果
New(token string, opts ...Option) (*Bot, error)token 為空或 SDK 的 getMe 檢查失敗(5 秒逾時)時回 error
WithHTTPClient(client *http.Client) Optionpolling 與上傳使用的 HTTP client
WithPollTimeout(d time.Duration) OptiongetUpdates 的 long-poll timeout
WithSendType(t SendType) MessageOption訊息文字的 parse mode
WithStatusEmoji(emoji string) StatusOptionreaction emoji;預設 🤔
WithStatusSendType(t SendType) StatusOptionstatus 文字的 parse mode

方法


方法回傳錯誤與限制
Start(ctx context.Context)errorGetMe 失敗
Close()error一律 nil
Status()Status
Reply(handler ReplyHandler)—取代先前的 handler
Send(ctx, chatID int64, replyTo int, text string, opts ...MessageOption)(*models.Message, error)API 錯誤
Delete(ctx, chatID int64, msgID int)errorAPI 錯誤
SendFile(ctx, chatID int64, fileType FileType, path string, caption ...string)(*models.Message, error)空路徑、os.Open 失敗、未知的 FileType
SendPhoto(ctx, chatID int64, paths []string, caption ...string)([]*models.Message, error)非空路徑為 0 個或超過 10 個
SendVoice(ctx, chatID int64, path string, caption ...string)(*models.Message, error)空路徑、os.Open 失敗
SendInput(ctx, chatID int64, replyTo int, text string, opts ...MessageOption)(*models.Message, error)空文字
SendSelect(ctx, chatID int64, replyTo int, text string, items []string, opts ...MessageOption)(*models.Message, error)空文字、沒有非空項目
SendMultiSelect(ctx, chatID int64, replyTo int, text string, items []string, opts ...MessageOption)(*models.Message, error)空文字、沒有非空項目、保留項目 __bot_multiselect_done__
SendStatus(ctx, chatID int64, replyTo int, text string, opts ...StatusOption)error立即 flush 時的送出/編輯錯誤
FinishStatus(ctx, chatID int64)error刪除錯誤,或等待進行中編輯時的 ctx.Err()
Save(ctx, fileID, dir string)(string, error)空參數、超過 20 MiB、HTTP 非 200、檔案系統錯誤

相關頁面


Telegram 設定 · Telegram 訊息 · Telegram 互動 · 狀態訊息 · 媒體落地
EN