@meetopenbot/slack 1.2.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 +5 -1
- package/dist/index.js +3 -10
- package/dist/invoke.js +29 -30
- package/dist/webhook.js +6 -3
- package/package.json +2 -2
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
|
|
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
|
|
@@ -52,6 +52,10 @@ 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.
|
|
56
|
+
|
|
57
|
+
A **self-hosted** app sends its events straight to the runtime:
|
|
58
|
+
|
|
55
59
|
1. Set `SLACK_SIGNING_SECRET` to the app's signing secret.
|
|
56
60
|
|
|
57
61
|
2. Point Slack **Event Subscriptions** request URL to:
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { definePlugin
|
|
1
|
+
import { definePlugin } from "@meetopenbot/plugin-sdk";
|
|
2
2
|
import { pluginConfigSchema, readSlackConfig, SLACK_BOT_SCOPES, slackCredentials, } from "./config.js";
|
|
3
|
-
import { handleSlackInvoke
|
|
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 (
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
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,
|
|
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;
|
|
@@ -58,9 +58,12 @@ export async function* handleSlackWebhook(args) {
|
|
|
58
58
|
yield webhookHttpResponse({ status: 200, body: { challenge: payload.challenge } });
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
|
+
// On OpenBot Cloud the shared app's events arrive through the cloud, which checked the
|
|
62
|
+
// signature with the secret only it holds. A self-hosted app is checked here.
|
|
61
63
|
const timestamp = getWebhookHeader(args.event, "x-slack-request-timestamp");
|
|
62
64
|
const signature = getWebhookHeader(args.event, "x-slack-signature");
|
|
63
|
-
if (!
|
|
65
|
+
if (!args.event.data.verified &&
|
|
66
|
+
!verifySlackSignature(signingSecret, rawBody, timestamp, signature)) {
|
|
64
67
|
yield webhookHttpResponse({ status: 401, body: { error: "invalid signature" } });
|
|
65
68
|
return;
|
|
66
69
|
}
|
|
@@ -96,7 +99,7 @@ export async function* handleSlackWebhook(args) {
|
|
|
96
99
|
yield {
|
|
97
100
|
type: "agent:invoke",
|
|
98
101
|
data: {
|
|
99
|
-
agentId:
|
|
102
|
+
agentId: args.agentId,
|
|
100
103
|
role: "user",
|
|
101
104
|
content: text,
|
|
102
105
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meetopenbot/slack",
|
|
3
|
-
"version": "1.
|
|
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",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@meetopenbot/plugin-sdk": "^2.
|
|
22
|
+
"@meetopenbot/plugin-sdk": "^2.9.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^20.10.1",
|