# LINE API

`github.com/pardnchiu/go-bot/core/line` 的全部 exported 符號，底層為 `github.com/line/line-bot-sdk-go/v8` v8.18.0 的 `linebot` 套件。

## 型別

| 符號 | 定義 | 說明 |
|---|---|---|
| `Bot` | `struct`（欄位未匯出） | 以 `New` 建立；方法可並行呼叫 |
| `Status` | `struct { Running bool; UserID, BasicID, DisplayName string }` | `Status()` 的回傳值；身分欄位取自 `GetBotInfo` |
| `Input` | `struct` | 欄位：`SourceType`、`UserID`、`Username`、`GroupID`、`RoomID`、`ReplyToken`、`MessageID`、`MessageType`、`Text`、`FileName`（皆為 `string`）、`Raw *linebot.Event`。見 [LINE 設定](/zh/line#input) |
| `ReplyHandler` | `func(ctx context.Context, input Input) string` | |
| `Option` | `func(*options)` | `New` 的選項 |

## 建構子與選項

| 函式 | 效果 |
|---|---|
| `New(secret, token, port string, opts ...Option) (*Bot, error)` | 任一參數為空或被 SDK 拒絕時回 error |
| `WithPath(path string) Option` | Webhook path；預設 `/linebot/webhook`；空值沿用預設 |

## 方法

| 方法 | 回傳 | 錯誤與限制 |
|---|---|---|
| `Start(ctx context.Context)` | `error` | `GetBotInfo` 失敗、`net.Listen` 失敗 |
| `Close()` | `error` | `http.Server.Shutdown` 失敗（5 秒 timeout） |
| `Status()` | `Status` | |
| `Reply(handler ReplyHandler)` | — | 取代先前的 handler |
| `Send(ctx, to, text string)` | `(*linebot.BasicResponse, error)` | `to` 為空、API 錯誤 |
| `Save(ctx, messageID, dir string)` | `(string, error)` | 空參數、超過 50 MiB、API 錯誤、檔案系統錯誤 |

## 相關頁面

[LINE 設定](/zh/line) · [LINE 訊息](/zh/line-messages) · [媒體落地](/zh/media-save)
