@meetopenbot/slack 1.0.4 → 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 CHANGED
@@ -5,32 +5,35 @@ Slack specialist agent for OpenBot: Events API ingress, simple LLM replies, and
5
5
  ## Features (MVP)
6
6
 
7
7
  - **Ingress** — verify Slack webhooks, dedupe events, prefetch thread/channel context, turn messages into `agent:invoke`
8
- - **Agent** — OpenAI + Slack MCP tools (`post_message`, `list_channels`, etc.)
8
+ - **Agent** — Claude Haiku 5.5 (or an OpenAI model) + Slack MCP tools (`post_message`, `list_channels`, etc.)
9
9
  - **Egress** — post inbound-thread replies via `chat.postMessage`
10
10
 
11
11
  ## Setup
12
12
 
13
- 1. Create a Slack app with bot scopes:
13
+ ### Connect
14
14
 
15
- - `app_mentions:read`, `chat:write`, `channels:history`, `users:read`
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
- 2. Add the plugin to `~/.openbot/agents/slack/AGENT.md`:
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
- model: openai/gpt-6-luna
32
+ model: anthropic/claude-haiku-5-5
30
33
  channelMappings: "C01234567:engineering,C89ABCDEF:support"
31
34
  ```
32
35
 
33
- On cloud, `authMode: credits` uses your workspace credit balance. For BYOK (bring your own key), set `authMode: byok` and add `OPENAI_API_KEY` under workspace settings — no API key field in plugin config.
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
- 3. Point Slack **Event Subscriptions** request URL to:
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
- 4. Subscribe to **`app_mention`** for channel mentions. Add **`message.im`** only if you want DMs.
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/agent.js CHANGED
@@ -13,7 +13,7 @@ export async function* runSlackAgent(args) {
13
13
  }),
14
14
  },
15
15
  apiKey: args.botToken,
16
- model: args.model ?? "openai/gpt-6-luna",
16
+ model: args.model ?? "anthropic/claude-haiku-5-5",
17
17
  system: SYSTEM_PROMPT,
18
18
  prompt: args.prompt,
19
19
  maxSteps: 10,
package/dist/config.js CHANGED
@@ -1,18 +1,19 @@
1
- import { lookupSecret, modelConfigField, settingsVariablesPath, SETTINGS_VARIABLES_MARKDOWN, trimmedString, } from "@meetopenbot/plugin-sdk";
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
- providers: ["openai"],
7
+ providers: ["anthropic", "openai"],
7
8
  override: true,
8
- defaultValue: "openai/gpt-6-luna",
9
+ defaultValue: DEFAULT_SLACK_MODEL,
9
10
  });
10
11
  export const pluginConfigSchema = {
11
12
  type: "object",
12
13
  properties: {
13
14
  model: {
14
15
  ...modelField,
15
- description: "Outbound — OpenAI model for direct Slack agent invocations",
16
+ description: "Outbound — model for direct Slack agent invocations",
16
17
  },
17
18
  channelMappings: {
18
19
  type: "string",
@@ -53,37 +54,28 @@ export function readSlackConfig(config) {
53
54
  export function resolveSlackSigningSecret() {
54
55
  return lookupSecret({ envKeys: ["SLACK_SIGNING_SECRET"] });
55
56
  }
56
- export function formatMissingCredentials(missing) {
57
- const lines = [
58
- `Slack agent setup is incomplete. Set these workspace variables in ${SETTINGS_VARIABLES_MARKDOWN}:`,
59
- ];
60
- if (missing.includes("botToken")) {
61
- lines.push(`- [\`SLACK_BOT_TOKEN\`](${settingsVariablesPath("SLACK_BOT_TOKEN")}) — Slack bot OAuth token (\`xoxb-…\`). You can get one from https://api.slack.com/apps.`);
62
- }
63
- if (missing.includes("teamId")) {
64
- lines.push(`- [\`SLACK_TEAM_ID\`](${settingsVariablesPath("SLACK_TEAM_ID")}) — workspace team id (\`T…\`)`);
65
- }
66
- return lines.join("\n");
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 resolveSlackCredentials(config) {
69
- const signingSecret = lookupSecret({ envKeys: ["SLACK_SIGNING_SECRET"] }) ?? "";
70
- const botToken = lookupSecret({ envKeys: ["SLACK_BOT_TOKEN"] });
71
- const teamId = lookupSecret({ envKeys: ["SLACK_TEAM_ID"] });
72
- const model = trimmedString(config.model) ?? "openai/gpt-6-luna";
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
- config: slackConfig,
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
- import { agentOutput, creditsErrorMessage, hasLlmAuth, llmAuthNotConfiguredMessage, shouldHandleInvoke, toAgentTurnEvents, } from "@meetopenbot/plugin-sdk";
2
+ import { agentModelKeyEnv, agentModelProvider, agentOutput, creditsErrorMessage, hasLlmAuth, llmAuthNotConfiguredMessage, shouldHandleInvoke, toAgentTurnEvents, } from "@meetopenbot/plugin-sdk";
3
3
  import { runSlackAgent } from "./agent.js";
4
- import { formatMissingCredentials, resolveOpenBotChannelId, resolveSlackCredentials, ROUTING_AGENT_ID, SLACK_USER_DISPLAY_NAME, } from "./config.js";
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
- const auth = resolveSlackCredentials(args.config);
106
- if (!auth.ok) {
111
+ if (!credentials) {
107
112
  yield {
108
113
  type: "agent:output",
109
- data: { content: formatMissingCredentials(auth.missing) },
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: auth.credentials.botToken,
149
+ token: credentials.botToken,
145
150
  channel: slackMeta.channel,
146
151
  messageTs: slackMeta.ts,
147
152
  threadTs: slackMeta.threadTs,
@@ -177,31 +182,34 @@ export async function* handleSlackInvoke(args) {
177
182
  }
178
183
  return;
179
184
  }
180
- const auth = resolveSlackCredentials(args.config);
181
- if (!auth.ok) {
185
+ if (!credentials) {
182
186
  yield agentOutput({
183
187
  agentId: args.agentId,
184
- content: formatMissingCredentials(auth.missing),
185
- threadId,
186
- meta: args.event.meta,
187
- });
188
- return;
189
- }
190
- if (!hasLlmAuth("openai")) {
191
- yield agentOutput({
192
- agentId: args.agentId,
193
- content: llmAuthNotConfiguredMessage(),
188
+ content: SLACK_NEEDS_NEWER_RUNTIME,
194
189
  threadId,
195
190
  meta: args.event.meta,
196
191
  });
197
192
  return;
198
193
  }
194
+ const model = resolveSlackModel(args.config);
195
+ let provider;
199
196
  try {
197
+ const modelProvider = agentModelProvider(model);
198
+ provider = modelProvider;
199
+ if (!hasLlmAuth(modelProvider)) {
200
+ yield agentOutput({
201
+ agentId: args.agentId,
202
+ content: llmAuthNotConfiguredMessage(agentModelKeyEnv(modelProvider)),
203
+ threadId,
204
+ meta: args.event.meta,
205
+ });
206
+ return;
207
+ }
200
208
  for await (const item of runSlackAgent({
201
209
  prompt: userMessage,
202
- botToken: auth.credentials.botToken,
203
- teamId: auth.credentials.teamId,
204
- model: auth.credentials.model,
210
+ botToken: credentials.botToken,
211
+ teamId: credentials.teamId,
212
+ model,
205
213
  })) {
206
214
  yield* toAgentTurnEvents(item, args.agentId, threadId, args.event.meta);
207
215
  }
@@ -210,7 +218,7 @@ export async function* handleSlackInvoke(args) {
210
218
  const message = error instanceof Error ? error.message : String(error);
211
219
  yield agentOutput({
212
220
  agentId: args.agentId,
213
- content: creditsErrorMessage(message, { agentName: "Slack" }) ??
221
+ content: creditsErrorMessage(message, { agentName: "Slack", provider }) ??
214
222
  `Slack agent error: ${message}`,
215
223
  threadId,
216
224
  meta: args.event.meta,
@@ -223,14 +231,11 @@ export async function* handleSlackOutbound(args) {
223
231
  if (args.event.meta?.agentId !== ROUTING_AGENT_ID)
224
232
  return;
225
233
  const slack = getSlackThreadMeta(args.event.meta);
226
- if (!slack?.channel)
227
- return;
228
- const auth = resolveSlackCredentials(args.config);
229
- if (!auth.ok)
234
+ if (!slack?.channel || !args.credentials)
230
235
  return;
231
236
  try {
232
237
  await postSlackMessage({
233
- token: auth.credentials.botToken,
238
+ token: args.credentials.botToken,
234
239
  channel: slack.channel,
235
240
  text: args.event.data.content,
236
241
  threadTs: slack.threadTs ?? slack.ts,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetopenbot/slack",
3
- "version": "1.0.4",
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.7.0"
22
+ "@meetopenbot/plugin-sdk": "^2.8.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/node": "^20.10.1",