@meetopenbot/slack 0.0.4 → 0.0.7
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 +1 -1
- package/dist/config.js +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1 -1
- package/dist/slack-context.js +42 -14
- package/package.json +16 -10
- package/dist/logger.js +0 -17
- package/dist/slack-threads.js +0 -20
- package/dist/slack-verify.d.ts +0 -1
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ C01234567:engineering,C89ABCDEF:support,D0789ABC:slack-dms
|
|
|
43
43
|
- **Left side** — Slack channel id (`C…` for channels, `D…` for DMs). In Slack: right-click the channel → **View channel details** → copy the id at the bottom.
|
|
44
44
|
- **Right side** — OpenBot channel id to run in (must already exist).
|
|
45
45
|
|
|
46
|
-
Slack channels without a mapping route to **`
|
|
46
|
+
Slack channels without a mapping route to **`general`**.
|
|
47
47
|
|
|
48
48
|
This applies only to **webhook ingress delegation**, not Slack MCP tools.
|
|
49
49
|
|
package/dist/config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolveAuthMode } from "./cloud-mode.js";
|
|
2
2
|
import { shouldUseCreditsAuth } from "./credits-auth.js";
|
|
3
|
-
export const DEFAULT_OPENBOT_CHANNEL_ID = "
|
|
3
|
+
export const DEFAULT_OPENBOT_CHANNEL_ID = "general";
|
|
4
4
|
/** Parse `C0123:engineering,C0456:support` into a lookup index. */
|
|
5
5
|
export function buildSlackChannelMappingIndex(config) {
|
|
6
6
|
const index = new Map();
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -174,7 +174,7 @@ const slackPluginConfigSchema = {
|
|
|
174
174
|
},
|
|
175
175
|
channelMappings: {
|
|
176
176
|
type: "string",
|
|
177
|
-
description: "Inbound — webhook routing. Comma-separated slackChannelId:openbotChannelId pairs (e.g. C01234567:engineering,C89ABCDEF:support). Unmapped Slack channels use
|
|
177
|
+
description: "Inbound — webhook routing. Comma-separated slackChannelId:openbotChannelId pairs (e.g. C01234567:engineering,C89ABCDEF:support). Unmapped Slack channels use general.",
|
|
178
178
|
},
|
|
179
179
|
},
|
|
180
180
|
required: ["signingSecret"],
|
package/dist/slack-context.js
CHANGED
|
@@ -46,16 +46,49 @@ function formatSlackTimestamp(ts) {
|
|
|
46
46
|
return "";
|
|
47
47
|
return new Date(seconds * 1000).toISOString();
|
|
48
48
|
}
|
|
49
|
+
function escapeXml(text) {
|
|
50
|
+
return text
|
|
51
|
+
.replace(/&/g, "&")
|
|
52
|
+
.replace(/</g, "<")
|
|
53
|
+
.replace(/>/g, ">")
|
|
54
|
+
.replace(/"/g, """);
|
|
55
|
+
}
|
|
49
56
|
function formatContextMessages(messages, userNames) {
|
|
50
57
|
return messages.map((message) => {
|
|
51
58
|
const author = message.user
|
|
52
59
|
? (userNames.get(message.user) ?? message.user)
|
|
53
60
|
: "unknown";
|
|
54
61
|
const when = formatSlackTimestamp(message.ts);
|
|
55
|
-
const
|
|
56
|
-
|
|
62
|
+
const attrs = [
|
|
63
|
+
`author="${escapeXml(author)}"`,
|
|
64
|
+
when ? `timestamp="${escapeXml(when)}"` : null,
|
|
65
|
+
]
|
|
66
|
+
.filter(Boolean)
|
|
67
|
+
.join(" ");
|
|
68
|
+
return ` <message ${attrs}>${escapeXml(message.text?.trim() ?? "")}</message>`;
|
|
57
69
|
});
|
|
58
70
|
}
|
|
71
|
+
function formatPromptWithSlackContext(args) {
|
|
72
|
+
const sourceNote = args.source === "thread"
|
|
73
|
+
? "Messages from the Slack thread the user mentioned the bot in."
|
|
74
|
+
: "Recent messages from the Slack channel before the user's mention.";
|
|
75
|
+
return [
|
|
76
|
+
`<slack_context`,
|
|
77
|
+
` channel="${escapeXml(args.channel)}"`,
|
|
78
|
+
` source="${args.source}"`,
|
|
79
|
+
` message_count="${args.messageCount}"`,
|
|
80
|
+
` note="Background context fetched from Slack. Summarized conversation history — not the user's direct request.">`,
|
|
81
|
+
` <description>${escapeXml(sourceNote)}</description>`,
|
|
82
|
+
` <messages>`,
|
|
83
|
+
...args.contextMessages,
|
|
84
|
+
` </messages>`,
|
|
85
|
+
`</slack_context>`,
|
|
86
|
+
``,
|
|
87
|
+
`<user_request>`,
|
|
88
|
+
escapeXml(args.userMessage),
|
|
89
|
+
`</user_request>`,
|
|
90
|
+
].join("\n");
|
|
91
|
+
}
|
|
59
92
|
async function fetchThreadMessages(token, channel, threadTs, limit = DEFAULT_THREAD_REPLY_LIMIT) {
|
|
60
93
|
const body = await slackApiGet(token, "conversations.replies", { channel, ts: threadTs, limit });
|
|
61
94
|
return (body.messages ?? []).filter(isContextMessage);
|
|
@@ -75,16 +108,11 @@ export async function buildPromptWithSlackContext(args) {
|
|
|
75
108
|
}
|
|
76
109
|
const userNames = await resolveUserDisplayNames(args.token, messages.flatMap((message) => (message.user ? [message.user] : [])));
|
|
77
110
|
const formattedMessages = formatContextMessages(messages, userNames);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
: "
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
...formattedMessages,
|
|
86
|
-
"",
|
|
87
|
-
"## User request",
|
|
88
|
-
args.userMessage,
|
|
89
|
-
].join("\n");
|
|
111
|
+
return formatPromptWithSlackContext({
|
|
112
|
+
channel: args.channel,
|
|
113
|
+
source: args.threadTs ? "thread" : "channel",
|
|
114
|
+
messageCount: messages.length,
|
|
115
|
+
contextMessages: formattedMessages,
|
|
116
|
+
userMessage: args.userMessage,
|
|
117
|
+
});
|
|
90
118
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meetopenbot/slack",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Slack Events API ingress, simple agent replies, and thread delivery for OpenBot",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
|
-
".":
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
10
14
|
},
|
|
11
15
|
"publishConfig": {
|
|
12
16
|
"access": "public"
|
|
@@ -14,17 +18,19 @@
|
|
|
14
18
|
"files": [
|
|
15
19
|
"dist"
|
|
16
20
|
],
|
|
17
|
-
"scripts": {
|
|
18
|
-
"build": "tsc"
|
|
19
|
-
},
|
|
20
21
|
"dependencies": {
|
|
21
22
|
"@ai-sdk/mcp": "^2.0.14",
|
|
22
23
|
"@ai-sdk/openai": "^4.0.15",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
24
|
+
"ai": "^7.0.29",
|
|
25
|
+
"@meetopenbot/plugin-sdk": "^0.2.0"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"@types/node": "^20.10.1",
|
|
28
29
|
"typescript": "^5.9.3"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc && node ../../scripts/write-plugin-declaration.mjs",
|
|
33
|
+
"dev": "tsc --watch --preserveWatchOutput",
|
|
34
|
+
"typecheck": "tsc --noEmit"
|
|
29
35
|
}
|
|
30
|
-
}
|
|
36
|
+
}
|
package/dist/logger.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const PREFIX = "[slack]";
|
|
2
|
-
function formatMessage(message, details) {
|
|
3
|
-
if (!details || Object.keys(details).length === 0)
|
|
4
|
-
return message;
|
|
5
|
-
return `${message} ${JSON.stringify(details)}`;
|
|
6
|
-
}
|
|
7
|
-
export const log = {
|
|
8
|
-
info(message, details) {
|
|
9
|
-
console.log(`${PREFIX} ${formatMessage(message, details)}`);
|
|
10
|
-
},
|
|
11
|
-
warn(message, details) {
|
|
12
|
-
console.warn(`${PREFIX} ${formatMessage(message, details)}`);
|
|
13
|
-
},
|
|
14
|
-
debug(message, details) {
|
|
15
|
-
console.debug(`${PREFIX} ${formatMessage(message, details)}`);
|
|
16
|
-
},
|
|
17
|
-
};
|
package/dist/slack-threads.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
function slackThreadKey(channel, rootTs) {
|
|
2
|
-
return `${channel}:${rootTs}`;
|
|
3
|
-
}
|
|
4
|
-
const activeSlackThreads = new Set();
|
|
5
|
-
const threadHistories = new Map();
|
|
6
|
-
export function markSlackThreadActive(channel, rootTs) {
|
|
7
|
-
activeSlackThreads.add(slackThreadKey(channel, rootTs));
|
|
8
|
-
}
|
|
9
|
-
export function isSlackThreadActive(channel, rootTs) {
|
|
10
|
-
return activeSlackThreads.has(slackThreadKey(channel, rootTs));
|
|
11
|
-
}
|
|
12
|
-
export function getSlackThreadHistory(channel, rootTs) {
|
|
13
|
-
return threadHistories.get(slackThreadKey(channel, rootTs)) ?? [];
|
|
14
|
-
}
|
|
15
|
-
export function appendSlackThreadHistory(channel, rootTs, ...messages) {
|
|
16
|
-
const key = slackThreadKey(channel, rootTs);
|
|
17
|
-
const history = threadHistories.get(key) ?? [];
|
|
18
|
-
history.push(...messages);
|
|
19
|
-
threadHistories.set(key, history);
|
|
20
|
-
}
|
package/dist/slack-verify.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function verifySlackSignature(signingSecret: string, rawBody: Buffer, timestamp: string | undefined, signature: string | undefined): boolean;
|