OpenClawSkills
GitHub
チャンネル • 5分で読める

Twitch

Twitch チャットボットの導入と設定(IRC)。

IRC接続でTwitchチャットをサポート。OpenClawはTwitchユーザー(botアカウント)としてチャンネルに接続し、メッセージの送受信を行います。

Tutorial.step

プラグインのインストールが必要

Twitchはプラグインとして提供されており、コアインストールには含まれていません。

CLI経由でインストール(npm registry):

Bash
openclaw plugins install @openclaw/twitch

ローカルインストール(gitリポジトリから実行する場合):

Bash
openclaw plugins install ./extensions/twitch

Details: ''/plugin''

Tutorial.step

初心者向けクイックセットアップ

1. bot用の専用Twitchアカウントを作成(既存アカウントも可)。

2. 認証情報を生成:''Twitch Token Generator''

- Bot Tokenを選択

- scopesに''chat:read''と''chat:write''が含まれていることを確認

- Client IDとAccess Tokenをコピー

3. TwitchユーザーIDを検索:

https://www.streamweasels.com/tools/convert-twitch-username-to-user-id/

4. tokenを設定:

- Env:''OPENCLAW_TWITCH_ACCESS_TOKEN=...''(default accountのみ)

- またはconfig:''channels.twitch.accessToken''

- 両方が設定されている場合、configが優先(envはdefault accountのフォールバック)。

5. gatewayを起動。

''重要:'' 認証されていないユーザーによるbotトリガーを防ぐため、アクセス制御(''allowFrom''または''allowedRoles'')を設定してください。''requireMention''はデフォルトで''true''。

Minimal configuration:

Json5
{
  channels: {
    twitch: {
      enabled: true,
      username: "openclaw",
      accessToken: "oauth:abc123...",
      clientId: "xyz789...",
      channel: "vevisk",
      allowFrom: ["123456789"],
    },
  },
}
Tutorial.step

これは何か

- Gatewayが管理するTwitchチャンネル。

- 決定論的ルーティング:返信は常にTwitchに戻ります。

- Each account maps to an isolated session key: ''agent:<agentId>:twitch:<accountName>''.

- ''username''はbotアカウント(認証用)、''channel''は参加するチャットルーム(必須)。

Tutorial.step

セットアップ(詳細)

#

Tutorial.step

認証情報の生成

''Twitch Token Generator''を使用:

- Bot Tokenを選択

- scopesを確認:''chat:read''と''chat:write''

- Client IDとAccess Tokenをコピー

この方法では手動でのアプリ登録は不要ですが、tokenは数時間後に期限切れになる可能性があります。

#

Tutorial.step

botの設定

Env(default accountのみ):

Bash
OPENCLAW_TWITCH_ACCESS_TOKEN=oauth:abc123...

またはconfig:

Json5
{
  channels: {
    twitch: {
      enabled: true,
      username: "openclaw",
      accessToken: "oauth:abc123...",
      clientId: "xyz789...",
      channel: "vevisk",
    },
  },
}

envとconfigの両方が存在する場合、configが優先されます。

#

Tutorial.step

アクセス制御(推奨)

Json5
{
  channels: {
    twitch: {
      allowFrom: ["123456789"]
    },
  },
}

''allowFrom''は厳格な許可リスト(最も安全)。ロールでアクセスを制御したい場合は、''allowFrom''を設定せず、''allowedRoles''を使用してください。

''利用可能なロール:'' ''"moderator"''、''"owner"''、''"vip"''、''"subscriber"''、''"all"''。

なぜユーザーIDを使うのか? ユーザー名は変更・偽装可能ですが、ユーザーIDは永続的です。

ユーザーIDの検索:

https://www.streamweasels.com/tools/convert-twitch-username-%20to-user-id/

Tutorial.step

Tokenの更新(オプション)

''Twitch Token Generator''で生成されたtokenは自動更新できません——期限切れ後に再生成が必要です。

自動token更新を希望する場合は、''Twitch Developer Console''で独自のTwitchアプリを作成し、configに追加してください:

Json5
{
  channels: {
    twitch: {
      clientSecret: "your_client_secret",
      refreshToken: "your_refresh_token",
    },
  },
}

botはtokenの期限切れ前に自動更新を行い、更新イベントをログに記録します。

Tutorial.step

複数アカウント

''channels.twitch.accounts''を使用して各アカウントのtokenを設定します。共有構造については''/gateway/configuration''を参照してください。

例(1つのbotアカウントが2つのチャンネルに参加):

Json5
{
  channels: {
    twitch: {
      accounts: {
        channel1: {
          username: "openclaw",
          accessToken: "oauth:abc123...",
          clientId: "xyz789...",
          channel: "vevisk",
        },
        channel2: {
          username: "openclaw",
          accessToken: "oauth:def456...",
          clientId: "uvw012...",
          channel: "secondchannel",
        },
      },
    },
  },
}

注意:各アカウントは独自のtokenが必要です(通常、1つのtokenは1つのチャンネルに対応)。

Tutorial.step

アクセス制御(その他の例)

#

Tutorial.step

ロールベースの制限

Json5
{
  channels: {
    twitch: {
      accounts: {
        default: {
          allowedRoles: ["moderator", "vip"],
        },
      },
    },
  },
}

#

Tutorial.step

ユーザーID許可リスト(最も安全)

Json5
{
  channels: {
    twitch: {
      accounts: {
        default: {
          allowFrom: ["123456789", "987654321"],
        },
      },
    },
  },
}

#

Tutorial.step

ロールアクセス(代替案)

''allowFrom''は厳格な許可リスト。一度設定すると、これらのユーザーIDのみが許可されます。

ロールで許可する場合、''allowFrom''を空にし、''allowedRoles''を使用してください:

Json5
{
  channels: {
    twitch: {
      accounts: {
        default: {
          allowedRoles: ["moderator"],
        },
      },
    },
  },
}

#

Tutorial.step

@mention要件の無効化

デフォルト''requireMention=true''。すべてのメッセージに返信する場合:

Json5
{
  channels: {
    twitch: {
      accounts: {
        default: {
          requireMention: false,
        },
      },
    },
  },
}
Tutorial.step

トラブルシューティング

まず診断コマンドを実行:

Bash
openclaw doctor
openclaw channels status --probe

#

Tutorial.step

Botが応答しない

- アクセス制御を確認:ユーザーIDが''allowFrom''にあるか、一時的に''allowFrom''を削除し''allowedRoles: ["all"]''を設定してテスト。

- botが''channel''で指定されたチャンネルに参加しているか確認。

#

Tutorial.step

Tokenの問題

"Failed to connect"または認証エラー:

- ''accessToken''がOAuth access tokenであることを確認(通常''oauth:''で始まる)

- token scopesに''chat:read''と''chat:write''が含まれていることを確認

- token更新が有効な場合、''clientSecret''と''refreshToken''が設定されていることを確認

#

Tutorial.step

Token更新が動作しない

ログの更新イベントを確認:

Terminal
Using env token source for mybot
Access token refreshed for user 123456 (expires in 14400s)

"token refresh disabled (no refresh token)"が表示される場合:

- ''clientSecret''が提供されていることを確認

- ''refreshToken''が提供されていることを確認

Tutorial.step

Configuration

Account設定フィールド:

- ''username'':botユーザー名

- ''accessToken'':''chat:read''/''chat:write''を含むOAuth access token

- ''clientId'':Twitch Client ID(Token Generatorまたは独自アプリ)

- ''channel'':参加するチャンネル(必須)

- ''enabled'':アカウントを有効にするか(デフォルト''true'')

- ''clientSecret'':オプション、自動token更新用

- ''refreshToken'':オプション、自動token更新用

- ''expiresIn'': expiration seconds

- ''obtainmentTimestamp'':token取得タイムスタンプ

- ''allowFrom'':ユーザーID許可リスト

- ''allowedRoles'':ロールベースアクセス制御(''"moderator" | "owner" | "vip" | "subscriber" | "all"'')

- ''requireMention'':@mentionが必要か(デフォルト''true'')

Provider設定フィールド:

- ''channels.twitch.enabled''

- ''channels.twitch.username''(単一アカウント簡易設定)

- ''channels.twitch.accessToken''(単一アカウント簡易設定)

- ''channels.twitch.clientId''(単一アカウント簡易設定)

- ''channels.twitch.channel''(単一アカウント簡易設定)

- ''channels.twitch.accounts.<accountName>'' (multi-account config)

完全な例:

Json5
{
  channels: {
    twitch: {
      enabled: true,
      username: "openclaw",
      accessToken: "oauth:abc123...",
      clientId: "xyz789...",
      channel: "vevisk",
      clientSecret: "secret123...",
      refreshToken: "refresh456...",
      allowFrom: ["123456789"],
      allowedRoles: ["moderator", "vip"],
      accounts: {
        default: {
          username: "mybot",
          accessToken: "oauth:abc123...",
          clientId: "xyz789...",
          channel: "your_channel",
          enabled: true,
          clientSecret: "secret123...",
          refreshToken: "refresh456...",
          expiresIn: 14400,
          obtainmentTimestamp: 1706092800000,
          allowFrom: ["123456789", "987654321"],
          allowedRoles: ["moderator"],
        },
      },
    },
  },
}
Tutorial.step

ツールアクション

Agentは''twitch''アクションを呼び出せます:

- ''send'':チャンネルにメッセージを送信

Example:

Json5
{
  action: "twitch",
  params: {
    message: "Hello Twitch!",
    to: "#mychannel",
  },
}
Tutorial.step

セキュリティと運用

- tokenはパスワードとして扱う:gitにコミットしない

- 長期運用には自動token更新を有効化

- アクセス制御にはユーザーID許可リストを使用(ユーザー名は使用しない)

- ログで更新と接続状態を監視

- 最小限のscopesのみ申請:''chat:read''と''chat:write''

- 動作しない場合:他のプロセスがセッションを使用していないことを確認し、gatewayを再起動

Tutorial.step

Limitations

- 単一メッセージ500文字(単語境界で自動分割)

- 分割前にMarkdownを削除

- 追加のレート制限なし(Twitchの組み込み制限に依存)