# Telegram API

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

## 型

| シンボル | 定義 | 備考 |
|---|---|---|
| `Bot` | `struct`（非公開フィールド） | `New` で作成する。メソッドは並行利用しても安全 |
| `Status` | `struct { Running bool; Username string; UserID int64 }` | `Status()` が返す |
| `Input` | `struct` | フィールド: `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 の設定](/ja/telegram#input) を参照 |
| `ReplyHandler` | `func(ctx context.Context, input Input) string` | |
| `ChatStatus` | `struct`（非公開フィールド） | `SendStatus` が管理するチャットごとのステータス項目。呼び出し側では作成しない |
| `Option` | `func(*options)` | `New` のオプション |
| `MessageOption` | `func(*messageOptions)` | `Send`、`SendInput`、`SendSelect`、`SendMultiSelect` のオプション |
| `StatusOption` | `func(*statusOptions)` | `SendStatus` のオプション |
| `SendType` | `int` | 定数 `TypeMarkdown`（MarkdownV2）、`TypeHTML` |
| `Command` | `struct { Name string; Description string }` | `SetCommands` の 1 項目。`Name` に先頭の `/` は付けない。[Telegram の設定](/ja/telegram#コマンドメニュー) を参照 |
| `FileType` | `int` | 定数 `TypeDocument`、`TypeVideo`、`TypeAudio` |

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

| 関数 | 効果 |
|---|---|
| `New(token string, opts ...Option) (*Bot, error)` | `token` が空の場合、または SDK の `getMe` チェック（タイムアウト 5 秒）が失敗した場合にエラー |
| `WithHTTPClient(client *http.Client) Option` | polling とアップロード用の HTTP クライアント |
| `WithPollTimeout(d time.Duration) Option` | `getUpdates` の long poll タイムアウト |
| `WithSendType(t SendType) MessageOption` | メッセージテキストの parse mode |
| `WithStatusEmoji(emoji string) StatusOption` | リアクションの絵文字。デフォルトは `🤔` |
| `WithStatusSendType(t SendType) StatusOption` | ステータステキストの parse mode |

## メソッド

| メソッド | 戻り値 | エラーと制限 |
|---|---|---|
| `Start(ctx context.Context)` | `error` | `GetMe` の失敗 |
| `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)` | `error` | API のエラー |
| `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 の設定](/ja/telegram) · [Telegram メッセージ](/ja/telegram-messages) · [Telegram インタラクション](/ja/telegram-interactions) · [ステータスメッセージ](/ja/status-messages) · [メディアの保存](/ja/media-save)
