v0.5.0

Telegram API

Last updated


Every exported symbol of github.com/pardnchiu/go-bot/core/telegram, built on github.com/go-telegram/bot v1.20.0.

Types


SymbolDefinitionNotes
Botstruct (unexported fields)Create with New; methods are safe for concurrent use
Statusstruct { Running bool; Username string; UserID int64 }Returned by Status()
InputstructFields: 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. See Telegram Setup
ReplyHandlerfunc(ctx context.Context, input Input) string
ChatStatusstruct (unexported fields)Per-chat status entry managed by SendStatus; not constructed by callers
Optionfunc(*options)Options for New
MessageOptionfunc(*messageOptions)Options for Send, SendInput, SendSelect, SendMultiSelect
StatusOptionfunc(*statusOptions)Options for SendStatus
SendTypeintConstants TypeMarkdown (MarkdownV2), TypeHTML
FileTypeintConstants TypeDocument, TypeVideo, TypeAudio

Constructor and options


FunctionEffect
New(token string, opts ...Option) (*Bot, error)Error when token is empty or the SDK's getMe check fails (5-second timeout)
WithHTTPClient(client *http.Client) OptionHTTP client for polling and uploads
WithPollTimeout(d time.Duration) OptionLong-poll timeout for getUpdates
WithSendType(t SendType) MessageOptionParse mode for message text
WithStatusEmoji(emoji string) StatusOptionReaction emoji; default 🤔
WithStatusSendType(t SendType) StatusOptionParse mode for status text

Methods


MethodReturnsErrors and limits
Start(ctx context.Context)errorGetMe failure
Close()errorAlways nil
Status()Status
Reply(handler ReplyHandler)—Replaces the previous handler
Send(ctx, chatID int64, replyTo int, text string, opts ...MessageOption)(*models.Message, error)API error
Delete(ctx, chatID int64, msgID int)errorAPI error
SendFile(ctx, chatID int64, fileType FileType, path string, caption ...string)(*models.Message, error)Empty path, os.Open failure, unknown FileType
SendPhoto(ctx, chatID int64, paths []string, caption ...string)([]*models.Message, error)0 or more than 10 non-empty paths
SendVoice(ctx, chatID int64, path string, caption ...string)(*models.Message, error)Empty path, os.Open failure
SendInput(ctx, chatID int64, replyTo int, text string, opts ...MessageOption)(*models.Message, error)Empty text
SendSelect(ctx, chatID int64, replyTo int, text string, items []string, opts ...MessageOption)(*models.Message, error)Empty text, no non-empty item
SendMultiSelect(ctx, chatID int64, replyTo int, text string, items []string, opts ...MessageOption)(*models.Message, error)Empty text, no non-empty item, reserved item __bot_multiselect_done__
SendStatus(ctx, chatID int64, replyTo int, text string, opts ...StatusOption)errorSend/edit error when flushed immediately
FinishStatus(ctx, chatID int64)errorDelete error, or ctx.Err() while waiting for an in-flight edit
Save(ctx, fileID, dir string)(string, error)Empty args, file over 20 MiB, HTTP non-200, file system errors


Telegram Setup · Telegram Messages · Telegram Interactions · Status Messages · Saving Media
中文