@meetopenbot/slack 1.3.1 → 1.4.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
@@ -15,7 +15,7 @@ Slack specialist agent for OpenBot: Events API ingress, simple LLM replies, and
15
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:
16
16
 
17
17
  - `app_mentions:read`, `im:history`: mentions and DMs
18
- - `channels:read`, `channels:history`, `users:read`, `users.profile:read`: reading channels, threads and people
18
+ - `channels:read`, `channels:history`, `groups:history`, `users:read`, `users.profile:read`: reading channels, threads (public and private) and people
19
19
  - `chat:write`, `reactions:write`: replying and reacting
20
20
 
21
21
  On **OpenBot Cloud** this works as is. A **self-hosted** runtime brings its own Slack app:
@@ -52,7 +52,9 @@ This applies only to **webhook ingress delegation**, not Slack MCP tools.
52
52
 
53
53
  ### Events (inbound mentions)
54
54
 
55
- On **OpenBot Cloud**, mentions and DMs arrive on their own once the workspace connects Slack. OpenBot's Slack app sends every event to OpenBot Cloud. The cloud checks Slack's signature and forwards the event to the workspace that connected that Slack team, marked `verified`. Disconnecting stops the events. So does removing the app from Slack.
55
+ The bot answers when it is tagged and in DMs. Once tagged in a thread, it also answers later replies in that thread without a tag. It stays quiet on replies that tag someone else, and never joins threads it wasn't tagged in.
56
+
57
+ On **OpenBot Cloud**, mentions, DMs and thread replies arrive on their own once the workspace connects Slack. OpenBot's Slack app sends every event to OpenBot Cloud. The cloud checks Slack's signature and forwards the event to the workspace that connected that Slack team, marked `verified`. Disconnecting stops the events. So does removing the app from Slack.
56
58
 
57
59
  A **self-hosted** app sends its events straight to the runtime:
58
60
 
@@ -64,9 +66,7 @@ A **self-hosted** app sends its events straight to the runtime:
64
66
  https://<your-host>/api/webhooks/slack
65
67
  ```
66
68
 
67
- 3. Subscribe to **`app_mention`** for channel mentions. Add **`message.im`** only if you want DMs.
68
-
69
- Do **not** subscribe to `message.channels` or `message.groups` — that causes duplicate replies alongside `app_mention`.
69
+ 3. Subscribe the bot to **`app_mention`** for mentions, **`message.im`** for DMs, and **`message.channels`** / **`message.groups`** for untagged replies in threads the bot is in (public / private channels). The plugin handles a tagged reply once, even though Slack sends it as both `app_mention` and `message`.
70
70
 
71
71
  ## Build
72
72
 
package/dist/config.js CHANGED
@@ -54,12 +54,17 @@ export function readSlackConfig(config) {
54
54
  export function resolveSlackSigningSecret() {
55
55
  return lookupSecret({ envKeys: ["SLACK_SIGNING_SECRET"] });
56
56
  }
57
- /** Bot scopes asked for at sign-in: the MCP tools plus mention and DM ingress. */
57
+ /**
58
+ * Bot scopes asked for at sign-in: the MCP tools plus mention, DM and thread-reply ingress.
59
+ * `channels:history` and `groups:history` let the bot read replies in public and private
60
+ * channel threads it is in.
61
+ */
58
62
  export const SLACK_BOT_SCOPES = [
59
63
  "app_mentions:read",
60
64
  "channels:history",
61
65
  "channels:read",
62
66
  "chat:write",
67
+ "groups:history",
63
68
  "im:history",
64
69
  "reactions:write",
65
70
  "users:read",
package/dist/index.js CHANGED
@@ -24,6 +24,13 @@ export const plugin = definePlugin({
24
24
  ctx: { state },
25
25
  config: slackConfig,
26
26
  agentId: context.agentId,
27
+ hasThread: async (channelId, threadId) => {
28
+ const details = await context.storage
29
+ .getThreadDetails({ channelId, threadId })
30
+ .catch(() => null);
31
+ const state = details?.state;
32
+ return !!state && typeof state === "object" && Object.keys(state).length > 0;
33
+ },
27
34
  });
28
35
  },
29
36
  async *run({ event, handlerCtx, context }) {
@@ -0,0 +1,19 @@
1
+ /** Someone tagged in the text: a person (`<@U…>`) or a user group (`<!subteam^…>`). */
2
+ const MENTION = /<@[^>]+>|<!subteam\^[^>]+>/;
3
+ export function slackMessageKind(slackEvent) {
4
+ if (slackEvent.bot_id)
5
+ return null;
6
+ // "Also send to channel" replies carry a subtype but are still replies.
7
+ if (slackEvent.subtype && slackEvent.subtype !== "thread_broadcast")
8
+ return null;
9
+ if (slackEvent.type === "app_mention")
10
+ return "mention";
11
+ if (slackEvent.type !== "message")
12
+ return null;
13
+ if (slackEvent.channel_type === "im")
14
+ return "direct";
15
+ const inThread = !!slackEvent.thread_ts && slackEvent.thread_ts !== slackEvent.ts;
16
+ if (inThread && !MENTION.test(slackEvent.text ?? ""))
17
+ return "threadReply";
18
+ return null;
19
+ }
package/dist/webhook.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { decodeWebhookRawBody, getWebhookHeader, webhookHttpResponse, } from "@meetopenbot/plugin-sdk";
2
2
  import { DEFAULT_OPENBOT_CHANNEL_ID, SLACK_USER_DISPLAY_NAME, resolveOpenBotChannelId, resolveSlackSigningSecret, } from "./config.js";
3
+ import { slackMessageKind } from "./message-kind.js";
3
4
  import { verifySlackSignature } from "./verify.js";
4
5
  const seenSlackEvents = new Map();
5
6
  const SLACK_EVENT_DEDUP_MS = 5 * 60 * 1000;
@@ -17,17 +18,14 @@ function markSlackEventSeen(dedupKey) {
17
18
  seenSlackEvents.set(dedupKey, now);
18
19
  return false;
19
20
  }
21
+ /**
22
+ * One key per Slack message. A mention inside a thread arrives twice, as `app_mention`
23
+ * and as `message`, with different event ids.
24
+ */
20
25
  function slackEventDedupKey(payload, slackEvent) {
21
- if (payload.event_id)
22
- return payload.event_id;
23
- return `${slackEvent.channel}:${slackEvent.ts}`;
24
- }
25
- function shouldProcessSlackEvent(slackEvent) {
26
- if (slackEvent.bot_id || slackEvent.subtype)
27
- return false;
28
- if (slackEvent.type === "app_mention")
29
- return true;
30
- return slackEvent.type === "message" && slackEvent.channel_type === "im";
26
+ if (slackEvent.channel && slackEvent.ts)
27
+ return `${slackEvent.channel}:${slackEvent.ts}`;
28
+ return payload.event_id ?? "";
31
29
  }
32
30
  function normalizeSlackText(text) {
33
31
  return text.replace(/<@[^>]+>/g, "").replace(/\s+/g, " ").trim();
@@ -68,7 +66,16 @@ export async function* handleSlackWebhook(args) {
68
66
  return;
69
67
  }
70
68
  const slackEvent = payload.type === "event_callback" ? payload.event : undefined;
71
- if (!slackEvent || !shouldProcessSlackEvent(slackEvent)) {
69
+ const kind = slackEvent ? slackMessageKind(slackEvent) : null;
70
+ if (!slackEvent || !kind) {
71
+ yield webhookHttpResponse({ status: 200, body: {} });
72
+ return;
73
+ }
74
+ const openBotChannelId = slackEvent.channel
75
+ ? resolveOpenBotChannelId(slackEvent.channel, args.config)
76
+ : DEFAULT_OPENBOT_CHANNEL_ID;
77
+ if (kind === "threadReply" &&
78
+ !(await args.hasThread(openBotChannelId, slackEvent.thread_ts))) {
72
79
  yield webhookHttpResponse({ status: 200, body: {} });
73
80
  return;
74
81
  }
@@ -91,9 +98,6 @@ export async function* handleSlackWebhook(args) {
91
98
  ts: slackEvent.ts,
92
99
  threadTs: slackEvent.thread_ts,
93
100
  };
94
- const openBotChannelId = slackEvent.channel
95
- ? resolveOpenBotChannelId(slackEvent.channel, args.config)
96
- : DEFAULT_OPENBOT_CHANNEL_ID;
97
101
  args.ctx.state.channelId = openBotChannelId;
98
102
  yield webhookHttpResponse({ status: 200, body: {} });
99
103
  yield {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetopenbot/slack",
3
- "version": "1.3.1",
3
+ "version": "1.4.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",
@@ -28,6 +28,7 @@
28
28
  "scripts": {
29
29
  "build": "tsc && node ../../scripts/write-plugin-declaration.mjs",
30
30
  "dev": "tsc --watch --preserveWatchOutput",
31
- "typecheck": "tsc --noEmit"
31
+ "typecheck": "tsc --noEmit",
32
+ "test": "node --experimental-strip-types --test src/*.test.ts"
32
33
  }
33
34
  }