v0.5.1

Telegram API

最終更新


github.com/go-telegram/bot v1.20.0 を土台にした github.com/pardnchiu/go-bot/core/telegram のすべての exported シンボルです。

型


シンボル定義備考
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 が管理するチャットごとのステータス項目。呼び出し側では作成しない
Optionfunc(*options)New のオプション
MessageOptionfunc(*messageOptions)Send、SendInput、SendSelect、SendMultiSelect のオプション
StatusOptionfunc(*statusOptions)SendStatus のオプション
SendTypeint定数 TypeMarkdown(MarkdownV2)、TypeHTML
Commandstruct { Name string; Description string }SetCommands の 1 項目。Name に先頭の / は付けない。Telegram の設定 を参照
FileTypeint定数 TypeDocument、TypeVideo、TypeAudio

コンストラクタとオプション


関数効果
New(token string, opts ...Option) (*Bot, error)token が空の場合、または SDK の getMe チェック(タイムアウト 5 秒)が失敗した場合にエラー
WithHTTPClient(client *http.Client) Optionpolling とアップロード用の HTTP クライアント
WithPollTimeout(d time.Duration) OptiongetUpdates の long poll タイムアウト
WithSendType(t SendType) MessageOptionメッセージテキストの parse mode
WithStatusEmoji(emoji string) StatusOptionリアクションの絵文字。デフォルトは 🤔
WithStatusSendType(t SendType) StatusOptionステータステキストの 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()
SetCommands(ctx, commands []Command)error空の Name または Description([Invalid])、setMyCommands の失敗([Upstream])
Save(ctx, fileID, dir string)(string, error)空の引数、20 MiB を超えるファイル、200 以外の HTTP ステータス、ファイルシステムのエラー

関連ページ


Telegram の設定 · Telegram メッセージ · Telegram インタラクション · ステータスメッセージ · メディアの保存