@meetopenbot/slack 1.1.0 → 1.2.0
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 +19 -12
- package/dist/config.js +26 -34
- package/dist/index.js +14 -3
- package/dist/invoke.js +19 -17
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,27 +10,30 @@ Slack specialist agent for OpenBot: Events API ingress, simple LLM replies, and
|
|
|
10
10
|
|
|
11
11
|
## Setup
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
### Connect
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
- For private channels: `groups:history` (bot must be invited)
|
|
17
|
-
- For DMs: `im:history`, `im:read`, `im:write`
|
|
15
|
+
A workspace owner clicks **Connect** on the Slack agent and approves "Add to Slack". That installs OpenBot's Slack app in their Slack workspace. OpenBot keeps the bot token, and the agent gets it on every run. Nothing to paste. The plugin asks for these bot scopes:
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
- `app_mentions:read`, `im:history`: mentions and DMs
|
|
18
|
+
- `channels:read`, `channels:history`, `users:read`, `users.profile:read`: reading channels, threads and people
|
|
19
|
+
- `chat:write`, `reactions:write`: replying and reacting
|
|
20
|
+
|
|
21
|
+
On **OpenBot Cloud** this works as is. A **self-hosted** runtime brings its own Slack app:
|
|
22
|
+
|
|
23
|
+
1. Create a Slack app and add `<your runtime URL>/api/webhooks/oauth-callback` under **OAuth & Permissions → Redirect URLs**. Slack needs an `https` URL, so use a tunnel for a local runtime.
|
|
24
|
+
2. On the runtime host, set `OPENBOT_OAUTH_SLACK_CLIENT_ID` and `OPENBOT_OAUTH_SLACK_CLIENT_SECRET` from the app's **Basic Information** page. Workspace variables don't count.
|
|
25
|
+
|
|
26
|
+
Then add the plugin to `~/.openbot/agents/slack/AGENT.md`:
|
|
20
27
|
|
|
21
28
|
```yaml
|
|
22
29
|
plugins:
|
|
23
30
|
- id: "@meetopenbot/slack"
|
|
24
31
|
config:
|
|
25
|
-
signingSecret: your-signing-secret
|
|
26
|
-
botToken: xoxb-your-bot-token
|
|
27
|
-
teamId: T01234567
|
|
28
|
-
authMode: credits
|
|
29
32
|
model: anthropic/claude-haiku-5-5
|
|
30
33
|
channelMappings: "C01234567:engineering,C89ABCDEF:support"
|
|
31
34
|
```
|
|
32
35
|
|
|
33
|
-
On cloud,
|
|
36
|
+
On cloud, the model runs on your workspace credits by default. For BYOK, add `ANTHROPIC_API_KEY` (or `OPENAI_API_KEY` for OpenAI models) under workspace settings.
|
|
34
37
|
|
|
35
38
|
### Channel routing (webhook ingress)
|
|
36
39
|
|
|
@@ -47,13 +50,17 @@ Slack channels without a mapping route to **`general`**.
|
|
|
47
50
|
|
|
48
51
|
This applies only to **webhook ingress delegation**, not Slack MCP tools.
|
|
49
52
|
|
|
50
|
-
|
|
53
|
+
### Events (inbound mentions)
|
|
54
|
+
|
|
55
|
+
1. Set `SLACK_SIGNING_SECRET` to the app's signing secret.
|
|
56
|
+
|
|
57
|
+
2. Point Slack **Event Subscriptions** request URL to:
|
|
51
58
|
|
|
52
59
|
```
|
|
53
60
|
https://<your-host>/api/webhooks/slack
|
|
54
61
|
```
|
|
55
62
|
|
|
56
|
-
|
|
63
|
+
3. Subscribe to **`app_mention`** for channel mentions. Add **`message.im`** only if you want DMs.
|
|
57
64
|
|
|
58
65
|
Do **not** subscribe to `message.channels` or `message.groups` — that causes duplicate replies alongside `app_mention`.
|
|
59
66
|
|
package/dist/config.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { lookupSecret, modelConfigField,
|
|
1
|
+
import { lookupSecret, modelConfigField, trimmedString, } from "@meetopenbot/plugin-sdk";
|
|
2
2
|
export const DEFAULT_OPENBOT_CHANNEL_ID = "general";
|
|
3
3
|
export const ROUTING_AGENT_ID = "system";
|
|
4
4
|
export const SLACK_USER_DISPLAY_NAME = "Slack user";
|
|
5
|
+
export const DEFAULT_SLACK_MODEL = "anthropic/claude-haiku-5-5";
|
|
5
6
|
const modelField = await modelConfigField({
|
|
6
7
|
providers: ["anthropic", "openai"],
|
|
7
8
|
override: true,
|
|
8
|
-
defaultValue:
|
|
9
|
+
defaultValue: DEFAULT_SLACK_MODEL,
|
|
9
10
|
});
|
|
10
11
|
export const pluginConfigSchema = {
|
|
11
12
|
type: "object",
|
|
@@ -53,37 +54,28 @@ export function readSlackConfig(config) {
|
|
|
53
54
|
export function resolveSlackSigningSecret() {
|
|
54
55
|
return lookupSecret({ envKeys: ["SLACK_SIGNING_SECRET"] });
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
57
|
+
/** Bot scopes asked for at sign-in: the MCP tools plus mention and DM ingress. */
|
|
58
|
+
export const SLACK_BOT_SCOPES = [
|
|
59
|
+
"app_mentions:read",
|
|
60
|
+
"channels:history",
|
|
61
|
+
"channels:read",
|
|
62
|
+
"chat:write",
|
|
63
|
+
"im:history",
|
|
64
|
+
"reactions:write",
|
|
65
|
+
"users:read",
|
|
66
|
+
"users.profile:read",
|
|
67
|
+
];
|
|
68
|
+
/** The bot token and team from `context.connection`, or undefined when not connected. */
|
|
69
|
+
export function slackCredentials(context) {
|
|
70
|
+
const connection = context.connection;
|
|
71
|
+
if (connection?.kind !== "oauthToken")
|
|
72
|
+
return undefined;
|
|
73
|
+
const team = connection.account.team;
|
|
74
|
+
const teamId = typeof team?.id === "string" ? team.id : "";
|
|
75
|
+
if (!connection.accessToken || !teamId)
|
|
76
|
+
return undefined;
|
|
77
|
+
return { botToken: connection.accessToken, teamId };
|
|
67
78
|
}
|
|
68
|
-
export function
|
|
69
|
-
|
|
70
|
-
const botToken = lookupSecret({ envKeys: ["SLACK_BOT_TOKEN"] });
|
|
71
|
-
const teamId = lookupSecret({ envKeys: ["SLACK_TEAM_ID"] });
|
|
72
|
-
const model = trimmedString(config.model) ?? "anthropic/claude-haiku-5-5";
|
|
73
|
-
const missing = [];
|
|
74
|
-
if (!botToken)
|
|
75
|
-
missing.push("botToken");
|
|
76
|
-
if (!teamId)
|
|
77
|
-
missing.push("teamId");
|
|
78
|
-
if (missing.length > 0)
|
|
79
|
-
return { ok: false, missing };
|
|
80
|
-
return {
|
|
81
|
-
ok: true,
|
|
82
|
-
credentials: {
|
|
83
|
-
signingSecret,
|
|
84
|
-
botToken: botToken,
|
|
85
|
-
teamId: teamId,
|
|
86
|
-
model,
|
|
87
|
-
},
|
|
88
|
-
};
|
|
79
|
+
export function resolveSlackModel(config) {
|
|
80
|
+
return trimmedString(config.model) ?? DEFAULT_SLACK_MODEL;
|
|
89
81
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import { definePlugin, } from "@meetopenbot/plugin-sdk";
|
|
2
|
-
import { pluginConfigSchema, readSlackConfig } from "./config.js";
|
|
2
|
+
import { pluginConfigSchema, readSlackConfig, SLACK_BOT_SCOPES, slackCredentials, } from "./config.js";
|
|
3
3
|
import { handleSlackInvoke, handleSlackOutbound } from "./invoke.js";
|
|
4
4
|
import { handleSlackWebhook } from "./webhook.js";
|
|
5
5
|
export const plugin = definePlugin({
|
|
6
6
|
name: "Slack",
|
|
7
7
|
description: "Slack Events API ingress, local agent runtime, and system delegation for webhooks",
|
|
8
8
|
configSchema: pluginConfigSchema,
|
|
9
|
+
// One bot per Slack workspace, installed by a workspace owner with "Add to Slack".
|
|
10
|
+
connection: {
|
|
11
|
+
kind: "oauthApp",
|
|
12
|
+
id: "slack",
|
|
13
|
+
scope: "workspace",
|
|
14
|
+
label: "Slack workspace",
|
|
15
|
+
authorizeUrl: "https://slack.com/oauth/v2/authorize",
|
|
16
|
+
tokenUrl: "https://slack.com/api/oauth.v2.access",
|
|
17
|
+
scopes: SLACK_BOT_SCOPES,
|
|
18
|
+
scopeSeparator: ",",
|
|
19
|
+
},
|
|
9
20
|
async *onWebhook({ event, state, context }) {
|
|
10
21
|
const slackConfig = readSlackConfig(context.config);
|
|
11
22
|
yield* handleSlackWebhook({
|
|
@@ -21,6 +32,7 @@ export const plugin = definePlugin({
|
|
|
21
32
|
ctx: handlerCtx,
|
|
22
33
|
agentId: context.agentId,
|
|
23
34
|
config: slackConfig,
|
|
35
|
+
credentials: slackCredentials(context),
|
|
24
36
|
host: context.host,
|
|
25
37
|
publicBaseUrl: context.publicBaseUrl,
|
|
26
38
|
});
|
|
@@ -28,10 +40,9 @@ export const plugin = definePlugin({
|
|
|
28
40
|
async *onEvent(event, context) {
|
|
29
41
|
if (event.type !== "agent:output")
|
|
30
42
|
return;
|
|
31
|
-
const slackConfig = readSlackConfig(context.config);
|
|
32
43
|
yield* handleSlackOutbound({
|
|
33
44
|
event: event,
|
|
34
|
-
|
|
45
|
+
credentials: slackCredentials(context),
|
|
35
46
|
});
|
|
36
47
|
},
|
|
37
48
|
});
|
package/dist/invoke.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { agentModelKeyEnv, agentModelProvider, agentOutput, creditsErrorMessage, hasLlmAuth, llmAuthNotConfiguredMessage, shouldHandleInvoke, toAgentTurnEvents, } from "@meetopenbot/plugin-sdk";
|
|
3
3
|
import { runSlackAgent } from "./agent.js";
|
|
4
|
-
import {
|
|
4
|
+
import { resolveOpenBotChannelId, resolveSlackModel, ROUTING_AGENT_ID, SLACK_USER_DISPLAY_NAME, } from "./config.js";
|
|
5
5
|
import { buildPromptWithSlackContext } from "./context.js";
|
|
6
6
|
import { postSlackMessage } from "./post.js";
|
|
7
7
|
import { getSlackThreadMeta, isSlackWebhookIngress } from "./webhook.js";
|
|
8
|
+
/**
|
|
9
|
+
* The host connects Slack before `run`. A run without credentials means the host is too
|
|
10
|
+
* old to know `oauthApp` connections.
|
|
11
|
+
*/
|
|
12
|
+
export const SLACK_NEEDS_NEWER_RUNTIME = "Slack needs a newer OpenBot runtime to connect. Update the runtime and try again.";
|
|
8
13
|
async function* bridgeSystemAgentRun(args) {
|
|
9
14
|
const runId = `slack_${randomUUID()}`;
|
|
10
15
|
const slackMeta = getSlackThreadMeta(args.meta);
|
|
@@ -101,12 +106,12 @@ export async function* handleSlackInvoke(args) {
|
|
|
101
106
|
const userMessage = (args.event.data.content ?? "").trim();
|
|
102
107
|
if (!userMessage || !threadId)
|
|
103
108
|
return;
|
|
109
|
+
const credentials = args.credentials;
|
|
104
110
|
if (fromWebhook) {
|
|
105
|
-
|
|
106
|
-
if (!auth.ok) {
|
|
111
|
+
if (!credentials) {
|
|
107
112
|
yield {
|
|
108
113
|
type: "agent:output",
|
|
109
|
-
data: { content:
|
|
114
|
+
data: { content: SLACK_NEEDS_NEWER_RUNTIME },
|
|
110
115
|
meta: {
|
|
111
116
|
agentId: ROUTING_AGENT_ID,
|
|
112
117
|
threadId,
|
|
@@ -141,7 +146,7 @@ export async function* handleSlackInvoke(args) {
|
|
|
141
146
|
if (slackMeta?.channel && slackMeta.ts) {
|
|
142
147
|
try {
|
|
143
148
|
prompt = await buildPromptWithSlackContext({
|
|
144
|
-
token:
|
|
149
|
+
token: credentials.botToken,
|
|
145
150
|
channel: slackMeta.channel,
|
|
146
151
|
messageTs: slackMeta.ts,
|
|
147
152
|
threadTs: slackMeta.threadTs,
|
|
@@ -177,19 +182,19 @@ export async function* handleSlackInvoke(args) {
|
|
|
177
182
|
}
|
|
178
183
|
return;
|
|
179
184
|
}
|
|
180
|
-
|
|
181
|
-
if (!auth.ok) {
|
|
185
|
+
if (!credentials) {
|
|
182
186
|
yield agentOutput({
|
|
183
187
|
agentId: args.agentId,
|
|
184
|
-
content:
|
|
188
|
+
content: SLACK_NEEDS_NEWER_RUNTIME,
|
|
185
189
|
threadId,
|
|
186
190
|
meta: args.event.meta,
|
|
187
191
|
});
|
|
188
192
|
return;
|
|
189
193
|
}
|
|
194
|
+
const model = resolveSlackModel(args.config);
|
|
190
195
|
let provider;
|
|
191
196
|
try {
|
|
192
|
-
const modelProvider = agentModelProvider(
|
|
197
|
+
const modelProvider = agentModelProvider(model);
|
|
193
198
|
provider = modelProvider;
|
|
194
199
|
if (!hasLlmAuth(modelProvider)) {
|
|
195
200
|
yield agentOutput({
|
|
@@ -202,9 +207,9 @@ export async function* handleSlackInvoke(args) {
|
|
|
202
207
|
}
|
|
203
208
|
for await (const item of runSlackAgent({
|
|
204
209
|
prompt: userMessage,
|
|
205
|
-
botToken:
|
|
206
|
-
teamId:
|
|
207
|
-
model
|
|
210
|
+
botToken: credentials.botToken,
|
|
211
|
+
teamId: credentials.teamId,
|
|
212
|
+
model,
|
|
208
213
|
})) {
|
|
209
214
|
yield* toAgentTurnEvents(item, args.agentId, threadId, args.event.meta);
|
|
210
215
|
}
|
|
@@ -226,14 +231,11 @@ export async function* handleSlackOutbound(args) {
|
|
|
226
231
|
if (args.event.meta?.agentId !== ROUTING_AGENT_ID)
|
|
227
232
|
return;
|
|
228
233
|
const slack = getSlackThreadMeta(args.event.meta);
|
|
229
|
-
if (!slack?.channel)
|
|
230
|
-
return;
|
|
231
|
-
const auth = resolveSlackCredentials(args.config);
|
|
232
|
-
if (!auth.ok)
|
|
234
|
+
if (!slack?.channel || !args.credentials)
|
|
233
235
|
return;
|
|
234
236
|
try {
|
|
235
237
|
await postSlackMessage({
|
|
236
|
-
token:
|
|
238
|
+
token: args.credentials.botToken,
|
|
237
239
|
channel: slack.channel,
|
|
238
240
|
text: args.event.data.content,
|
|
239
241
|
threadTs: slack.threadTs ?? slack.ts,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meetopenbot/slack",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Slack Events API ingress, simple agent replies, and thread delivery for OpenBot",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@meetopenbot/plugin-sdk": "^2.
|
|
22
|
+
"@meetopenbot/plugin-sdk": "^2.8.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^20.10.1",
|