@elizaos/plugin-twitch 2.0.0-alpha.7 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +132 -0
- package/auto-enable.ts +21 -0
- package/dist/accounts.d.ts +17 -0
- package/dist/accounts.d.ts.map +1 -0
- package/dist/connector-account-provider.d.ts +18 -0
- package/dist/connector-account-provider.d.ts.map +1 -0
- package/dist/index.d.ts +1 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +544 -679
- package/dist/index.js.map +9 -12
- package/dist/providers/userContext.d.ts.map +1 -1
- package/dist/service.d.ts +18 -1
- package/dist/service.d.ts.map +1 -1
- package/dist/toon.d.ts +2 -0
- package/dist/toon.d.ts.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/workflow-credential-provider.d.ts +21 -0
- package/dist/workflow-credential-provider.d.ts.map +1 -0
- package/package.json +19 -9
- package/dist/actions/joinChannel.d.ts +0 -6
- package/dist/actions/joinChannel.d.ts.map +0 -1
- package/dist/actions/leaveChannel.d.ts +0 -6
- package/dist/actions/leaveChannel.d.ts.map +0 -1
- package/dist/actions/listChannels.d.ts +0 -6
- package/dist/actions/listChannels.d.ts.map +0 -1
- package/dist/actions/sendMessage.d.ts +0 -6
- package/dist/actions/sendMessage.d.ts.map +0 -1
- package/dist/providers/channelState.d.ts +0 -9
- package/dist/providers/channelState.d.ts.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# @elizaos/plugin-twitch
|
|
2
|
+
|
|
3
|
+
Twitch chat integration plugin for ElizaOS agents.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Real-time Chat**: Connect to Twitch channels and participate in chat
|
|
8
|
+
- **Multi-channel Support**: Join and monitor multiple channels simultaneously
|
|
9
|
+
- **Role-based Access Control**: Filter interactions by user roles (broadcaster, moderator, VIP, subscriber)
|
|
10
|
+
- **Mention Detection**: Optionally only respond when @mentioned
|
|
11
|
+
- **Token Refresh**: Automatic OAuth token refresh (when configured)
|
|
12
|
+
- **Markdown Stripping**: Automatically converts markdown to plain text for Twitch
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @elizaos/plugin-twitch
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Prerequisites
|
|
21
|
+
|
|
22
|
+
1. **Twitch Developer Account**: Register your application at [Twitch Developer Console](https://dev.twitch.tv/console)
|
|
23
|
+
2. **OAuth Token**: Generate a token with `chat:read` and `chat:edit` scopes at [Twitch Token Generator](https://twitchtokengenerator.com/)
|
|
24
|
+
|
|
25
|
+
## Configuration
|
|
26
|
+
|
|
27
|
+
Set the following environment variables:
|
|
28
|
+
|
|
29
|
+
### Required
|
|
30
|
+
|
|
31
|
+
| Variable | Description |
|
|
32
|
+
|----------|-------------|
|
|
33
|
+
| `TWITCH_USERNAME` | Bot's Twitch username |
|
|
34
|
+
| `TWITCH_CLIENT_ID` | Application client ID from Twitch Developer Console |
|
|
35
|
+
| `TWITCH_ACCESS_TOKEN` | OAuth access token with chat:read and chat:edit scopes |
|
|
36
|
+
| `TWITCH_CHANNEL` | Primary channel to join (without # prefix) |
|
|
37
|
+
|
|
38
|
+
### Optional
|
|
39
|
+
|
|
40
|
+
| Variable | Description | Default |
|
|
41
|
+
|----------|-------------|---------|
|
|
42
|
+
| `TWITCH_CLIENT_SECRET` | Application client secret (for token refresh) | - |
|
|
43
|
+
| `TWITCH_REFRESH_TOKEN` | OAuth refresh token (for automatic refresh) | - |
|
|
44
|
+
| `TWITCH_CHANNELS` | Comma-separated list of additional channels | - |
|
|
45
|
+
| `TWITCH_REQUIRE_MENTION` | Only respond when @mentioned | `false` |
|
|
46
|
+
| `TWITCH_ALLOWED_ROLES` | Comma-separated roles allowed to interact | `all` |
|
|
47
|
+
|
|
48
|
+
### Allowed Roles
|
|
49
|
+
|
|
50
|
+
- `all` - Anyone can interact
|
|
51
|
+
- `owner` / `broadcaster` - Channel owner only
|
|
52
|
+
- `moderator` - Moderators
|
|
53
|
+
- `vip` - VIP users
|
|
54
|
+
- `subscriber` - Subscribers
|
|
55
|
+
|
|
56
|
+
## Usage
|
|
57
|
+
|
|
58
|
+
### Basic Setup
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import twitchPlugin from "@elizaos/plugin-twitch";
|
|
62
|
+
|
|
63
|
+
const agent = new Agent({
|
|
64
|
+
plugins: [twitchPlugin],
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Actions
|
|
69
|
+
|
|
70
|
+
Twitch chat operations route through the canonical `MESSAGE` action using
|
|
71
|
+
`source: "twitch"`.
|
|
72
|
+
|
|
73
|
+
| Primary action | Operation | Description |
|
|
74
|
+
|----------------|-----------|-------------|
|
|
75
|
+
| `MESSAGE` | `send` | Send a message to a Twitch channel |
|
|
76
|
+
| `MESSAGE` | `join_channel` | Join a Twitch channel |
|
|
77
|
+
| `MESSAGE` | `leave_channel` | Leave a Twitch channel |
|
|
78
|
+
| `MESSAGE` | `list_channels` | List joined Twitch channels |
|
|
79
|
+
|
|
80
|
+
### Providers
|
|
81
|
+
|
|
82
|
+
Twitch does not register standalone planner providers. Channel and user context
|
|
83
|
+
is exposed through the Twitch message connector hooks.
|
|
84
|
+
|
|
85
|
+
### Events
|
|
86
|
+
|
|
87
|
+
The plugin emits the following events:
|
|
88
|
+
|
|
89
|
+
| Event | Description |
|
|
90
|
+
|-------|-------------|
|
|
91
|
+
| `TWITCH_MESSAGE_RECEIVED` | A chat message was received |
|
|
92
|
+
| `TWITCH_MESSAGE_SENT` | A message was sent |
|
|
93
|
+
| `TWITCH_JOIN_CHANNEL` | Bot joined a channel |
|
|
94
|
+
| `TWITCH_LEAVE_CHANNEL` | Bot left a channel |
|
|
95
|
+
| `TWITCH_CONNECTION_READY` | Connected to Twitch |
|
|
96
|
+
| `TWITCH_CONNECTION_LOST` | Connection lost |
|
|
97
|
+
|
|
98
|
+
## Message Limits
|
|
99
|
+
|
|
100
|
+
- Maximum message length: 500 characters
|
|
101
|
+
- Messages longer than 500 characters are automatically split
|
|
102
|
+
|
|
103
|
+
## Security Considerations
|
|
104
|
+
|
|
105
|
+
1. **Token Security**: Never expose your access token in client-side code
|
|
106
|
+
2. **Scope Limitation**: Only request necessary OAuth scopes
|
|
107
|
+
3. **Role Filtering**: Use `TWITCH_ALLOWED_ROLES` to restrict who can interact
|
|
108
|
+
4. **Mention Requirement**: Enable `TWITCH_REQUIRE_MENTION` in busy channels
|
|
109
|
+
|
|
110
|
+
## Troubleshooting
|
|
111
|
+
|
|
112
|
+
### Connection Issues
|
|
113
|
+
|
|
114
|
+
1. Verify your OAuth token is valid and not expired
|
|
115
|
+
2. Check that the username matches the token owner
|
|
116
|
+
3. Ensure the client ID is correct
|
|
117
|
+
|
|
118
|
+
### Authentication Errors
|
|
119
|
+
|
|
120
|
+
1. Regenerate your OAuth token
|
|
121
|
+
2. Verify scopes include `chat:read` and `chat:edit`
|
|
122
|
+
3. Check for typos in environment variables
|
|
123
|
+
|
|
124
|
+
### Message Not Sending
|
|
125
|
+
|
|
126
|
+
1. Verify you have joined the target channel
|
|
127
|
+
2. Check that the channel name is correct (no # prefix)
|
|
128
|
+
3. Ensure your token has `chat:edit` scope
|
|
129
|
+
|
|
130
|
+
## License
|
|
131
|
+
|
|
132
|
+
MIT
|
package/auto-enable.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Auto-enable check for @elizaos/plugin-twitch.
|
|
2
|
+
//
|
|
3
|
+
// Plugin manifest entry-point — referenced by package.json's
|
|
4
|
+
// `elizaos.plugin.autoEnableModule`. Keep this module light: env reads only,
|
|
5
|
+
// no service init, no transitive imports of the full plugin runtime. The
|
|
6
|
+
// auto-enable engine loads dozens of these per boot.
|
|
7
|
+
import type { PluginAutoEnableContext } from "@elizaos/core";
|
|
8
|
+
|
|
9
|
+
/** Enable when a `twitch` connector block is present and not explicitly disabled. */
|
|
10
|
+
export function shouldEnable(ctx: PluginAutoEnableContext): boolean {
|
|
11
|
+
const c = (ctx.config?.connectors as Record<string, unknown> | undefined)
|
|
12
|
+
?.twitch;
|
|
13
|
+
if (!c || typeof c !== "object") return false;
|
|
14
|
+
const config = c as Record<string, unknown>;
|
|
15
|
+
if (config.enabled === false) return false;
|
|
16
|
+
// The full per-connector field check (clientId/oauth token/channel) lives
|
|
17
|
+
// in the central engine's isConnectorConfigured. We delegate to a simple
|
|
18
|
+
// "block present + not explicitly disabled" check here; the central
|
|
19
|
+
// engine's stricter check remains as a fallback during migration.
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IAgentRuntime } from "@elizaos/core";
|
|
2
|
+
import type { TwitchRole, TwitchSettings } from "./types.js";
|
|
3
|
+
export declare const DEFAULT_TWITCH_ACCOUNT_ID = "default";
|
|
4
|
+
export type TwitchAccountConfig = Partial<Omit<TwitchSettings, "additionalChannels" | "allowedRoles" | "allowedUserIds" | "accountId">> & {
|
|
5
|
+
accountId?: string;
|
|
6
|
+
id?: string;
|
|
7
|
+
additionalChannels?: string[] | string;
|
|
8
|
+
channels?: string[] | string;
|
|
9
|
+
allowedRoles?: TwitchRole[] | string;
|
|
10
|
+
allowedUserIds?: string[] | string;
|
|
11
|
+
};
|
|
12
|
+
export declare function normalizeTwitchAccountId(accountId?: unknown): string;
|
|
13
|
+
export declare function listTwitchAccountIds(runtime: IAgentRuntime): string[];
|
|
14
|
+
export declare function resolveDefaultTwitchAccountId(runtime: IAgentRuntime): string;
|
|
15
|
+
export declare function readTwitchAccountId(...sources: unknown[]): string | undefined;
|
|
16
|
+
export declare function resolveTwitchAccountSettings(runtime: IAgentRuntime, requestedAccountId?: string | null): TwitchSettings;
|
|
17
|
+
//# sourceMappingURL=accounts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../src/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE7D,eAAO,MAAM,yBAAyB,YAAY,CAAC;AAEnD,MAAM,MAAM,mBAAmB,GAAG,OAAO,CACvC,IAAI,CACF,cAAc,EACd,oBAAoB,GAAG,cAAc,GAAG,gBAAgB,GAAG,WAAW,CACvE,CACF,GAAG;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,kBAAkB,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IACvC,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC7B,YAAY,CAAC,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IACrC,cAAc,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;CACpC,CAAC;AAiGF,wBAAgB,wBAAwB,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAIpE;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,EAAE,CAerE;AAED,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAU5E;AAED,wBAAgB,mBAAmB,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,GAAG,SAAS,CA8B7E;AAED,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,aAAa,EACtB,kBAAkB,CAAC,EAAE,MAAM,GAAG,IAAI,GACjC,cAAc,CA4DhB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Twitch ConnectorAccountManager provider.
|
|
3
|
+
*
|
|
4
|
+
* Adapts the multi-account scaffolding in `accounts.ts` to the
|
|
5
|
+
* `ConnectorAccountProvider` contract from
|
|
6
|
+
* `@elizaos/core/connectors/account-manager`.
|
|
7
|
+
*
|
|
8
|
+
* Source of truth for accounts is character settings (`character.settings.twitch`)
|
|
9
|
+
* + TWITCH_ACCOUNTS JSON env var + single-account env vars (TWITCH_USERNAME,
|
|
10
|
+
* TWITCH_CLIENT_ID, TWITCH_ACCESS_TOKEN, TWITCH_REFRESH_TOKEN, TWITCH_CHANNEL).
|
|
11
|
+
*
|
|
12
|
+
* AccountKey is the twitch user id (or username when only that's available).
|
|
13
|
+
* Role is `OWNER` since twitch OAuth tokens authenticate the user/channel.
|
|
14
|
+
*/
|
|
15
|
+
import type { ConnectorAccountProvider, IAgentRuntime } from "@elizaos/core";
|
|
16
|
+
export declare const TWITCH_PROVIDER_ID = "twitch";
|
|
17
|
+
export declare function createTwitchConnectorAccountProvider(runtime: IAgentRuntime): ConnectorAccountProvider;
|
|
18
|
+
//# sourceMappingURL=connector-account-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connector-account-provider.d.ts","sourceRoot":"","sources":["../src/connector-account-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAIV,wBAAwB,EACxB,aAAa,EACd,MAAM,eAAe,CAAC;AASvB,eAAO,MAAM,kBAAkB,WAAW,CAAC;AA4B3C,wBAAgB,oCAAoC,CAClD,OAAO,EAAE,aAAa,GACrB,wBAAwB,CA+C1B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,16 +4,9 @@
|
|
|
4
4
|
* This plugin provides Twitch chat integration using the @twurple library.
|
|
5
5
|
*/
|
|
6
6
|
import type { Plugin } from "@elizaos/core";
|
|
7
|
+
export * from "./accounts.js";
|
|
7
8
|
export { TwitchService } from "./service.js";
|
|
8
9
|
export * from "./types.js";
|
|
9
|
-
import { joinChannel } from "./actions/joinChannel.js";
|
|
10
|
-
import { leaveChannel } from "./actions/leaveChannel.js";
|
|
11
|
-
import { listChannels } from "./actions/listChannels.js";
|
|
12
|
-
import { sendMessage } from "./actions/sendMessage.js";
|
|
13
|
-
export { sendMessage, joinChannel, leaveChannel, listChannels };
|
|
14
|
-
import { channelStateProvider } from "./providers/channelState.js";
|
|
15
|
-
import { userContextProvider } from "./providers/userContext.js";
|
|
16
|
-
export { channelStateProvider, userContextProvider };
|
|
17
10
|
/**
|
|
18
11
|
* Twitch plugin definition.
|
|
19
12
|
*/
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAiB,MAAM,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAiB,MAAM,EAAE,MAAM,eAAe,CAAC;AAG3D,cAAc,eAAe,CAAC;AAE9B,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,cAAc,YAAY,CAAC;AAW3B;;GAEG;AACH,QAAA,MAAM,YAAY,EAAE,MAmGnB,CAAC;AAEF,eAAe,YAAY,CAAC"}
|