@meetopenbot/slack 1.3.0 → 1.3.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 CHANGED
@@ -37,7 +37,7 @@ On cloud, the model runs on your workspace credits by default. For BYOK, add `AN
37
37
 
38
38
  ### Channel routing (webhook ingress)
39
39
 
40
- When a Slack message arrives via the Events API webhook, the plugin delegates to the OpenBot **system** agent in a target channel. Set `channelMappings` as comma-separated `slackChannelId:openbotChannelId` pairs:
40
+ When a Slack message arrives via the Events API webhook, the runtime answers Slack at once and opens an OpenBot thread for the Slack thread. The Slack agent hands the message to the OpenBot **system** agent there and posts each reply back into the Slack thread. Set `channelMappings` as comma-separated `slackChannelId:openbotChannelId` pairs to pick the OpenBot channel:
41
41
 
42
42
  ```
43
43
  C01234567:engineering,C89ABCDEF:support,D0789ABC:slack-dms
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { definePlugin, } from "@meetopenbot/plugin-sdk";
1
+ import { definePlugin } from "@meetopenbot/plugin-sdk";
2
2
  import { pluginConfigSchema, readSlackConfig, SLACK_BOT_SCOPES, slackCredentials, } from "./config.js";
3
- import { handleSlackInvoke, handleSlackOutbound } from "./invoke.js";
3
+ import { handleSlackInvoke } from "./invoke.js";
4
4
  import { handleSlackWebhook } from "./webhook.js";
5
5
  export const plugin = definePlugin({
6
6
  name: "Slack",
@@ -23,6 +23,7 @@ export const plugin = definePlugin({
23
23
  event: event,
24
24
  ctx: { state },
25
25
  config: slackConfig,
26
+ agentId: context.agentId,
26
27
  });
27
28
  },
28
29
  async *run({ event, handlerCtx, context }) {
@@ -37,13 +38,5 @@ export const plugin = definePlugin({
37
38
  publicBaseUrl: context.publicBaseUrl,
38
39
  });
39
40
  },
40
- async *onEvent(event, context) {
41
- if (event.type !== "agent:output")
42
- return;
43
- yield* handleSlackOutbound({
44
- event: event,
45
- credentials: slackCredentials(context),
46
- });
47
- },
48
41
  });
49
42
  export default plugin;
package/dist/invoke.js CHANGED
@@ -92,13 +92,8 @@ async function* bridgeSystemAgentRun(args) {
92
92
  }
93
93
  export async function* handleSlackInvoke(args) {
94
94
  const fromWebhook = isSlackWebhookIngress(args.event.meta);
95
- if (fromWebhook) {
96
- if (!shouldHandleInvoke(args.event, ROUTING_AGENT_ID))
97
- return;
98
- }
99
- else if (!shouldHandleInvoke(args.event, args.agentId)) {
95
+ if (!shouldHandleInvoke(args.event, args.agentId))
100
96
  return;
101
- }
102
97
  if (args.event.meta?.threadId) {
103
98
  args.ctx.state.threadId = args.event.meta.threadId;
104
99
  }
@@ -157,28 +152,52 @@ export async function* handleSlackInvoke(args) {
157
152
  // Fall back to the raw mention if Slack history is unavailable.
158
153
  }
159
154
  }
155
+ // Each reply shows in the OpenBot thread and is posted to the Slack thread it answers.
156
+ const reply = async (output) => {
157
+ if (!slackMeta?.channel || !output.data.content?.trim())
158
+ return;
159
+ try {
160
+ await postSlackMessage({
161
+ token: credentials.botToken,
162
+ channel: slackMeta.channel,
163
+ text: output.data.content,
164
+ threadTs: slackMeta.threadTs ?? slackMeta.ts,
165
+ });
166
+ }
167
+ catch (error) {
168
+ console.warn("[slack] could not post reply", {
169
+ channel: slackMeta.channel,
170
+ error: error instanceof Error ? error.message : String(error),
171
+ });
172
+ }
173
+ };
160
174
  try {
161
- yield* bridgeSystemAgentRun({
175
+ for await (const output of bridgeSystemAgentRun({
162
176
  host: args.host,
163
177
  channelId,
164
178
  threadId,
165
179
  userMessage: prompt,
166
180
  meta: args.event.meta,
167
181
  publicBaseUrl: args.publicBaseUrl,
168
- });
182
+ })) {
183
+ yield output;
184
+ await reply(output);
185
+ }
169
186
  }
170
187
  catch (error) {
171
188
  const message = error instanceof Error ? error.message : String(error);
172
- yield {
189
+ const output = {
173
190
  type: "agent:output",
174
191
  data: { content: `Slack agent error: ${message}` },
175
192
  meta: {
176
193
  agentId: ROUTING_AGENT_ID,
177
194
  threadId,
178
195
  source: "slack",
179
- slack: getSlackThreadMeta(args.event.meta),
196
+ slack: slackMeta,
180
197
  },
181
198
  };
199
+ yield output;
200
+ await reply(output);
182
201
  }
183
202
  return;
184
203
  }
@@ -225,23 +244,3 @@ export async function* handleSlackInvoke(args) {
225
244
  });
226
245
  }
227
246
  }
228
- export async function* handleSlackOutbound(args) {
229
- if (args.event.meta?.source !== "slack")
230
- return;
231
- if (args.event.meta?.agentId !== ROUTING_AGENT_ID)
232
- return;
233
- const slack = getSlackThreadMeta(args.event.meta);
234
- if (!slack?.channel || !args.credentials)
235
- return;
236
- try {
237
- await postSlackMessage({
238
- token: args.credentials.botToken,
239
- channel: slack.channel,
240
- text: args.event.data.content,
241
- threadTs: slack.threadTs ?? slack.ts,
242
- });
243
- }
244
- catch {
245
- // Avoid failing the bus run if Slack delivery fails.
246
- }
247
- }
package/dist/webhook.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { decodeWebhookRawBody, getWebhookHeader, webhookHttpResponse, } from "@meetopenbot/plugin-sdk";
2
- import { DEFAULT_OPENBOT_CHANNEL_ID, ROUTING_AGENT_ID, SLACK_USER_DISPLAY_NAME, resolveOpenBotChannelId, resolveSlackSigningSecret, } from "./config.js";
2
+ import { DEFAULT_OPENBOT_CHANNEL_ID, SLACK_USER_DISPLAY_NAME, resolveOpenBotChannelId, resolveSlackSigningSecret, } from "./config.js";
3
3
  import { verifySlackSignature } from "./verify.js";
4
4
  const seenSlackEvents = new Map();
5
5
  const SLACK_EVENT_DEDUP_MS = 5 * 60 * 1000;
@@ -99,7 +99,7 @@ export async function* handleSlackWebhook(args) {
99
99
  yield {
100
100
  type: "agent:invoke",
101
101
  data: {
102
- agentId: ROUTING_AGENT_ID,
102
+ agentId: args.agentId,
103
103
  role: "user",
104
104
  content: text,
105
105
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetopenbot/slack",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
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",