# はじめに

go-bot を Go module に追加し、1 つのプラットフォームで最小構成のエコー bot を動かします。

## 前提条件

| 項目 | 要件 |
|---|---|
| Go | 1.25.0 以降（`go.mod`） |
| Telegram | BotFather から取得した Bot token |
| Discord | Bot token。Developer Portal で **Message Content Intent** を有効にしておく必要があります |
| LINE | Channel secret、長期の channel access token、webhook ポートへ転送する公開 HTTPS URL |

Telegram と Discord はアウトバウンドで接続するため、NAT の内側でも動作します。LINE はイベントをサーバーへプッシュするため、インバウンドの HTTPS エンドポイントが必要です（ローカルでのテストには ngrok などのリバースプロキシが使えます）。

## インストール

```bash
go get github.com/pardnchiu/go-bot@latest
```

使用するプラットフォームのパッケージだけを import します。

```go
import (
    "github.com/pardnchiu/go-bot/core/telegram"
    "github.com/pardnchiu/go-bot/core/discord"
    "github.com/pardnchiu/go-bot/core/line"
)
```

## 最小構成のエコー bot

どのプラットフォームも同じ順序で呼び出します。`New`、`Reply`、`Start`、そして終了時に `Close` です。handler が空でない値を返すと、それが返信として送り返されます。

```go
package main

import (
    "context"
    "log"
    "os"
    "os/signal"
    "syscall"

    "github.com/pardnchiu/go-bot/core/telegram"
)

func main() {
    bot, err := telegram.New(os.Getenv("TELEGRAM_TOKEN"))
    if err != nil {
        log.Fatal(err)
    }
    bot.Reply(func(ctx context.Context, in telegram.Input) string {
        return "you said: " + in.Text
    })

    ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
    defer stop()
    if err := bot.Start(ctx); err != nil {
        log.Fatal(err)
    }
    <-ctx.Done()
    bot.Close()
}
```

Discord 版と LINE 版で変わるのはコンストラクタと `Input` 型だけです。

| プラットフォーム | コンストラクタ | Handler の入力 |
|---|---|---|
| Telegram | `telegram.New(token)` | `telegram.Input` |
| Discord | `discord.New(token)` | `discord.Input` |
| LINE | `line.New(secret, token, "8080")` | `line.Input` |

ライブラリ自体は環境変数を読みません。上記の変数名はあなたのプログラム側のものです。

## 次のステップ

- [Bot のライフサイクル](/ja/core-concepts) — `Start` が何を検証し、`Close` がどう終了するか
- [Reply Handler](/ja/reply-handler) — 返信の送信先と panic 時の挙動
- プラットフォームの設定: [Telegram](/ja/telegram)、[Discord](/ja/discord)、[LINE](/ja/line)
