@im-more/dsh-slack 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/cordis.patch.yml +13 -0
- package/lib/index.js +2659 -0
- package/lib/index.js.map +1 -0
- package/lib/types/bot.d.ts +66 -0
- package/lib/types/bot.d.ts.map +1 -0
- package/lib/types/bot.js +165 -0
- package/lib/types/bot.js.map +1 -0
- package/lib/types/config.d.ts +49 -0
- package/lib/types/config.d.ts.map +1 -0
- package/lib/types/config.js +54 -0
- package/lib/types/config.js.map +1 -0
- package/lib/types/decode.d.ts +126 -0
- package/lib/types/decode.d.ts.map +1 -0
- package/lib/types/decode.js +396 -0
- package/lib/types/decode.js.map +1 -0
- package/lib/types/errors.d.ts +61 -0
- package/lib/types/errors.d.ts.map +1 -0
- package/lib/types/errors.js +196 -0
- package/lib/types/errors.js.map +1 -0
- package/lib/types/identity.d.ts +27 -0
- package/lib/types/identity.d.ts.map +1 -0
- package/lib/types/identity.js +35 -0
- package/lib/types/identity.js.map +1 -0
- package/lib/types/index.d.ts +14 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +14 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/modes/mrkdwn.d.ts +17 -0
- package/lib/types/modes/mrkdwn.d.ts.map +1 -0
- package/lib/types/modes/mrkdwn.js +123 -0
- package/lib/types/modes/mrkdwn.js.map +1 -0
- package/lib/types/modes/shared.d.ts +164 -0
- package/lib/types/modes/shared.d.ts.map +1 -0
- package/lib/types/modes/shared.js +411 -0
- package/lib/types/modes/shared.js.map +1 -0
- package/lib/types/mrkdwn.d.ts +41 -0
- package/lib/types/mrkdwn.d.ts.map +1 -0
- package/lib/types/mrkdwn.js +137 -0
- package/lib/types/mrkdwn.js.map +1 -0
- package/lib/types/request.d.ts +225 -0
- package/lib/types/request.d.ts.map +1 -0
- package/lib/types/request.js +330 -0
- package/lib/types/request.js.map +1 -0
- package/lib/types/send.d.ts +74 -0
- package/lib/types/send.d.ts.map +1 -0
- package/lib/types/send.js +200 -0
- package/lib/types/send.js.map +1 -0
- package/lib/types/transport/socket.d.ts +58 -0
- package/lib/types/transport/socket.d.ts.map +1 -0
- package/lib/types/transport/socket.js +297 -0
- package/lib/types/transport/socket.js.map +1 -0
- package/lib/types/transport/webhook.d.ts +48 -0
- package/lib/types/transport/webhook.d.ts.map +1 -0
- package/lib/types/transport/webhook.js +210 -0
- package/lib/types/transport/webhook.js.map +1 -0
- package/lib/types/types/admin.d.ts +682 -0
- package/lib/types/types/admin.d.ts.map +1 -0
- package/lib/types/types/admin.js +172 -0
- package/lib/types/types/admin.js.map +1 -0
- package/lib/types/types/api.d.ts +20 -0
- package/lib/types/types/api.d.ts.map +1 -0
- package/lib/types/types/api.js +7 -0
- package/lib/types/types/api.js.map +1 -0
- package/lib/types/types/apps.d.ts +138 -0
- package/lib/types/types/apps.d.ts.map +1 -0
- package/lib/types/types/apps.js +28 -0
- package/lib/types/types/apps.js.map +1 -0
- package/lib/types/types/auth.d.ts +36 -0
- package/lib/types/types/auth.d.ts.map +1 -0
- package/lib/types/types/auth.js +10 -0
- package/lib/types/types/auth.js.map +1 -0
- package/lib/types/types/bots.d.ts +32 -0
- package/lib/types/types/bots.d.ts.map +1 -0
- package/lib/types/types/bots.js +7 -0
- package/lib/types/types/bots.js.map +1 -0
- package/lib/types/types/calls.d.ts +82 -0
- package/lib/types/types/calls.d.ts.map +1 -0
- package/lib/types/types/calls.js +22 -0
- package/lib/types/types/calls.js.map +1 -0
- package/lib/types/types/chat.d.ts +208 -0
- package/lib/types/types/chat.d.ts.map +1 -0
- package/lib/types/types/chat.js +34 -0
- package/lib/types/types/chat.js.map +1 -0
- package/lib/types/types/conversations.d.ts +266 -0
- package/lib/types/types/conversations.d.ts.map +1 -0
- package/lib/types/types/conversations.js +58 -0
- package/lib/types/types/conversations.js.map +1 -0
- package/lib/types/types/definition.d.ts +505 -0
- package/lib/types/types/definition.d.ts.map +1 -0
- package/lib/types/types/definition.js +2 -0
- package/lib/types/types/definition.js.map +1 -0
- package/lib/types/types/dialog.d.ts +20 -0
- package/lib/types/types/dialog.d.ts.map +1 -0
- package/lib/types/types/dialog.js +7 -0
- package/lib/types/types/dialog.js.map +1 -0
- package/lib/types/types/dnd.d.ts +70 -0
- package/lib/types/types/dnd.d.ts.map +1 -0
- package/lib/types/types/dnd.js +19 -0
- package/lib/types/types/dnd.js.map +1 -0
- package/lib/types/types/emoji.d.ts +18 -0
- package/lib/types/types/emoji.d.ts.map +1 -0
- package/lib/types/types/emoji.js +7 -0
- package/lib/types/types/emoji.js.map +1 -0
- package/lib/types/types/events/base-events.d.ts +235 -0
- package/lib/types/types/events/base-events.d.ts.map +1 -0
- package/lib/types/types/events/base-events.js +3 -0
- package/lib/types/types/events/base-events.js.map +1 -0
- package/lib/types/types/events/index.d.ts +97 -0
- package/lib/types/types/events/index.d.ts.map +1 -0
- package/lib/types/types/events/index.js +3 -0
- package/lib/types/types/events/index.js.map +1 -0
- package/lib/types/types/events/message-events.d.ts +215 -0
- package/lib/types/types/events/message-events.d.ts.map +1 -0
- package/lib/types/types/events/message-events.js +3 -0
- package/lib/types/types/events/message-events.js.map +1 -0
- package/lib/types/types/files.d.ts +189 -0
- package/lib/types/types/files.d.ts.map +1 -0
- package/lib/types/types/files.js +43 -0
- package/lib/types/types/files.js.map +1 -0
- package/lib/types/types/index.d.ts +82 -0
- package/lib/types/types/index.d.ts.map +1 -0
- package/lib/types/types/index.js +29 -0
- package/lib/types/types/index.js.map +1 -0
- package/lib/types/types/internal.d.ts +17 -0
- package/lib/types/types/internal.d.ts.map +1 -0
- package/lib/types/types/internal.js +60 -0
- package/lib/types/types/internal.js.map +1 -0
- package/lib/types/types/migration.d.ts +25 -0
- package/lib/types/types/migration.d.ts.map +1 -0
- package/lib/types/types/migration.js +7 -0
- package/lib/types/types/migration.js.map +1 -0
- package/lib/types/types/oauth.d.ts +50 -0
- package/lib/types/types/oauth.d.ts.map +1 -0
- package/lib/types/types/oauth.js +13 -0
- package/lib/types/types/oauth.js.map +1 -0
- package/lib/types/types/pins.d.ts +39 -0
- package/lib/types/types/pins.d.ts.map +1 -0
- package/lib/types/types/pins.js +13 -0
- package/lib/types/types/pins.js.map +1 -0
- package/lib/types/types/reactions.d.ts +75 -0
- package/lib/types/types/reactions.d.ts.map +1 -0
- package/lib/types/types/reactions.js +16 -0
- package/lib/types/types/reactions.js.map +1 -0
- package/lib/types/types/reminders.d.ts +64 -0
- package/lib/types/types/reminders.d.ts.map +1 -0
- package/lib/types/types/reminders.js +19 -0
- package/lib/types/types/reminders.js.map +1 -0
- package/lib/types/types/rtm.d.ts +30 -0
- package/lib/types/types/rtm.d.ts.map +1 -0
- package/lib/types/types/rtm.js +7 -0
- package/lib/types/types/rtm.js.map +1 -0
- package/lib/types/types/search.d.ts +24 -0
- package/lib/types/types/search.d.ts.map +1 -0
- package/lib/types/types/search.js +7 -0
- package/lib/types/types/search.js.map +1 -0
- package/lib/types/types/stars.d.ts +56 -0
- package/lib/types/types/stars.d.ts.map +1 -0
- package/lib/types/types/stars.js +13 -0
- package/lib/types/types/stars.js.map +1 -0
- package/lib/types/types/team.d.ts +98 -0
- package/lib/types/types/team.d.ts.map +1 -0
- package/lib/types/types/team.js +19 -0
- package/lib/types/types/team.js.map +1 -0
- package/lib/types/types/usergroups.d.ts +103 -0
- package/lib/types/types/usergroups.d.ts.map +1 -0
- package/lib/types/types/usergroups.js +25 -0
- package/lib/types/types/usergroups.js.map +1 -0
- package/lib/types/types/users.d.ts +169 -0
- package/lib/types/types/users.d.ts.map +1 -0
- package/lib/types/types/users.js +40 -0
- package/lib/types/types/users.js.map +1 -0
- package/lib/types/types/views.d.ts +56 -0
- package/lib/types/types/views.d.ts.map +1 -0
- package/lib/types/types/views.js +16 -0
- package/lib/types/types/views.js.map +1 -0
- package/lib/types/types/workflows.d.ts +45 -0
- package/lib/types/types/workflows.d.ts.map +1 -0
- package/lib/types/types/workflows.js +13 -0
- package/lib/types/types/workflows.js.map +1 -0
- package/package.json +65 -3
- package/src/bot.ts +273 -0
- package/src/config.ts +92 -0
- package/src/decode.ts +489 -0
- package/src/errors.ts +230 -0
- package/src/identity.ts +59 -0
- package/src/index.ts +64 -0
- package/src/modes/mrkdwn.ts +159 -0
- package/src/modes/shared.ts +515 -0
- package/src/mrkdwn.ts +146 -0
- package/src/request.ts +449 -0
- package/src/send.ts +300 -0
- package/src/transport/socket.ts +393 -0
- package/src/transport/webhook.ts +269 -0
- package/src/types/admin.ts +910 -0
- package/src/types/api.ts +28 -0
- package/src/types/apps.ts +175 -0
- package/src/types/auth.ts +49 -0
- package/src/types/bots.ts +40 -0
- package/src/types/calls.ts +110 -0
- package/src/types/chat.ts +255 -0
- package/src/types/conversations.ts +342 -0
- package/src/types/definition.ts +530 -0
- package/src/types/dialog.ts +28 -0
- package/src/types/dnd.ts +94 -0
- package/src/types/emoji.ts +26 -0
- package/src/types/events/base-events.ts +281 -0
- package/src/types/events/index.ts +125 -0
- package/src/types/events/message-events.ts +253 -0
- package/src/types/files.ts +245 -0
- package/src/types/index.ts +84 -0
- package/src/types/internal.ts +60 -0
- package/src/types/migration.ts +34 -0
- package/src/types/oauth.ts +66 -0
- package/src/types/pins.ts +55 -0
- package/src/types/reactions.ts +95 -0
- package/src/types/reminders.ts +88 -0
- package/src/types/rtm.ts +38 -0
- package/src/types/search.ts +32 -0
- package/src/types/stars.ts +72 -0
- package/src/types/team.ts +122 -0
- package/src/types/usergroups.ts +135 -0
- package/src/types/users.ts +221 -0
- package/src/types/views.ts +76 -0
- package/src/types/workflows.ts +61 -0
- package/README.md +0 -3
package/lib/types/bot.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { Adapter } from '@deepseek-ai/cordis-plugin-im-core';
|
|
2
|
+
import { configError, Config } from "./config.js";
|
|
3
|
+
import { classifySlackError } from "./errors.js";
|
|
4
|
+
import { verifyIdentity } from "./identity.js";
|
|
5
|
+
import { createMrkdwnMode } from "./modes/mrkdwn.js";
|
|
6
|
+
import { fileName } from "./modes/shared.js";
|
|
7
|
+
import { callApi, createSlackApi, downloadFile, putUploadBytes, startUpload, } from "./request.js";
|
|
8
|
+
import { createReaction, deletePart, deleteReaction, getMessage, members, sendPayload, } from "./send.js";
|
|
9
|
+
import { SlackSocketMode } from "./transport/socket.js";
|
|
10
|
+
import { SlackWebhook } from "./transport/webhook.js";
|
|
11
|
+
// The migrated declarations install every documented method on `Internal` when they are imported.
|
|
12
|
+
import "./types/index.js";
|
|
13
|
+
import { Internal } from "./types/internal.js";
|
|
14
|
+
/** Message of any caught value, for a log line. */
|
|
15
|
+
function messageOf(error) {
|
|
16
|
+
return error instanceof Error ? error.message : String(error);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Name of an attachment whose element declared none.
|
|
20
|
+
* @param ref - the unresolved resource.
|
|
21
|
+
* @returns the source's file name, else one naming the kind.
|
|
22
|
+
*/
|
|
23
|
+
function uploadName(ref) {
|
|
24
|
+
const named = fileName(undefined, ref.src);
|
|
25
|
+
return named === 'file' ? `slack-${ref.kind}` : named;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Slack adapter.
|
|
29
|
+
*
|
|
30
|
+
* Identity is the configured `selfId`, checked against `auth.test` on connect; Socket Mode and the Events API are the
|
|
31
|
+
* two transports; `mrkdwn` is the only mode, because Slack message text is the only way the upstream adapter ever
|
|
32
|
+
* rendered content. Inbound media is served from the bot's own `satori:` route, because `url_private` needs the bot
|
|
33
|
+
* token and the host does not have it.
|
|
34
|
+
*/
|
|
35
|
+
export class SlackBot extends Adapter {
|
|
36
|
+
/** The adapter needs the Satori service and the isolated `http` service. */
|
|
37
|
+
static inject = ['satori', 'http'];
|
|
38
|
+
/** The Loader applies this schema to a profile row's `config` before the constructor runs. */
|
|
39
|
+
static Config = Config;
|
|
40
|
+
modes;
|
|
41
|
+
modeOrder = ['mrkdwn'];
|
|
42
|
+
/** Endpoints shared by every Web API call of this bot. */
|
|
43
|
+
api;
|
|
44
|
+
/** Full typed Slack Web API surface registered by the migrated declarations. */
|
|
45
|
+
internal;
|
|
46
|
+
/** `team_id` of the installation, once `auth.test` answered. */
|
|
47
|
+
teamId;
|
|
48
|
+
transport;
|
|
49
|
+
constructor(ctx, config) {
|
|
50
|
+
// A profile whose protocol lacks its credential cannot work at all; refusing it here fails at load instead of at
|
|
51
|
+
// the first dial or the first callback.
|
|
52
|
+
const invalid = configError(config);
|
|
53
|
+
if (invalid !== undefined)
|
|
54
|
+
throw invalid;
|
|
55
|
+
super(ctx, config, {
|
|
56
|
+
id: `slack:${config.selfId}`,
|
|
57
|
+
platform: 'slack',
|
|
58
|
+
adapter: 'slack',
|
|
59
|
+
});
|
|
60
|
+
this.selfId = config.selfId;
|
|
61
|
+
this.api = createSlackApi(ctx, config);
|
|
62
|
+
// The migrated client addresses the API root with absolute paths, so the http service it uses carries the root as
|
|
63
|
+
// its base URL (the upstream adapter injected the same base).
|
|
64
|
+
this.internal = new Internal(this, this.ctx.http.extend({ baseUrl: `${this.api.base}/` }));
|
|
65
|
+
this.modes = { mrkdwn: createMrkdwnMode(config.replyBroadcast) };
|
|
66
|
+
this.defineInternalRoute('/files/:fileId', async ({ params }) => this.serveFile(params.fileId));
|
|
67
|
+
}
|
|
68
|
+
async connect() {
|
|
69
|
+
try {
|
|
70
|
+
const identity = await verifyIdentity(this.api, this.config.selfId);
|
|
71
|
+
this.selfId = identity.userId;
|
|
72
|
+
this.teamId = identity.teamId;
|
|
73
|
+
this.user = {
|
|
74
|
+
id: identity.userId,
|
|
75
|
+
name: identity.userName === '' ? identity.userId : identity.userName,
|
|
76
|
+
isBot: true,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
// `Bot.start` only stores a connect failure on `bot.error`, so log it here.
|
|
81
|
+
this.ctx.logger.error('slack: connect failed: %s', messageOf(error));
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
this.transport =
|
|
85
|
+
this.config.protocol === 'http'
|
|
86
|
+
? new SlackWebhook(this)
|
|
87
|
+
: new SlackSocketMode(this);
|
|
88
|
+
await this.transport.start();
|
|
89
|
+
}
|
|
90
|
+
async disconnect() {
|
|
91
|
+
const transport = this.transport;
|
|
92
|
+
this.transport = undefined;
|
|
93
|
+
await transport?.stop();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Upload one outbound attachment through the two-step file API.
|
|
97
|
+
*
|
|
98
|
+
* `files.upload` is retired, so the bytes go to a pre-signed URL and the returned file id is what
|
|
99
|
+
* `files.completeUploadExternal` shares into the channel.
|
|
100
|
+
*/
|
|
101
|
+
async upload(ref, _scope, ctx) {
|
|
102
|
+
const fetched = await ctx.fetch(ref.src, ctx.signal);
|
|
103
|
+
const name = ref.meta.name ?? fetched.name ?? uploadName(ref);
|
|
104
|
+
const ticket = await startUpload(this.api, { name, length: fetched.data.byteLength }, ctx.signal);
|
|
105
|
+
await putUploadBytes(this.api, ticket, fetched.data, ctx.signal);
|
|
106
|
+
return { key: ticket.fileId, extra: { name } };
|
|
107
|
+
}
|
|
108
|
+
resourceScope(_target, _kind) {
|
|
109
|
+
return this.id;
|
|
110
|
+
}
|
|
111
|
+
async sendPayload(payload, target, ctx) {
|
|
112
|
+
return await sendPayload(this.sendDeps(), payload, target, ctx);
|
|
113
|
+
}
|
|
114
|
+
async deletePart(part, handle) {
|
|
115
|
+
await deletePart(this.sendDeps(), part, handle);
|
|
116
|
+
}
|
|
117
|
+
async members(chat, cursor, limit) {
|
|
118
|
+
return await members(this.sendDeps(), chat, cursor, limit);
|
|
119
|
+
}
|
|
120
|
+
async getMessage(chat, id) {
|
|
121
|
+
return await getMessage(this.sendDeps(), this, chat, id);
|
|
122
|
+
}
|
|
123
|
+
async createReaction(message, emoji) {
|
|
124
|
+
await createReaction(this.sendDeps(), message, emoji);
|
|
125
|
+
}
|
|
126
|
+
async deleteReaction(message, emoji) {
|
|
127
|
+
await deleteReaction(this.sendDeps(), message, emoji);
|
|
128
|
+
}
|
|
129
|
+
classify(error) {
|
|
130
|
+
return classifySlackError(error);
|
|
131
|
+
}
|
|
132
|
+
sendDeps() {
|
|
133
|
+
return { api: this.api, teamId: this.teamId };
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Resolve one `satori:` file route.
|
|
137
|
+
*
|
|
138
|
+
* `files.info` names the download URL, which is fetched with the bot token only when its host belongs to Slack; the
|
|
139
|
+
* bytes are streamed back to the host without buffering.
|
|
140
|
+
*/
|
|
141
|
+
async serveFile(fileId) {
|
|
142
|
+
try {
|
|
143
|
+
const answer = await callApi(this.api, 'filesInfo', {
|
|
144
|
+
file: fileId,
|
|
145
|
+
});
|
|
146
|
+
const src = answer.file?.url_private;
|
|
147
|
+
if (src === undefined || src === '') {
|
|
148
|
+
return new Response(null, { status: 404 });
|
|
149
|
+
}
|
|
150
|
+
const response = await downloadFile(this.api, src);
|
|
151
|
+
const headers = new Headers();
|
|
152
|
+
const mime = response.headers.get('content-type');
|
|
153
|
+
if (mime !== null)
|
|
154
|
+
headers.set('content-type', mime);
|
|
155
|
+
return new Response(response.body, { status: response.status, headers });
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
this.ctx.logger.warn('slack: file %s could not be served: %s', fileId, messageOf(error));
|
|
159
|
+
return new Response(null, { status: 502 });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export { Config };
|
|
164
|
+
export default SlackBot;
|
|
165
|
+
//# sourceMappingURL=bot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bot.js","sourceRoot":"","sources":["../../src/bot.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAA;AAe5D,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AACh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AO,EAAE,CAAC,CAAA;QAC1E,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAClB,wCAAwC,EACxC,MAAM,EACN,SAAS,CAAC,KAAK,CAAC,CACjB,CAAA;YACD,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;QAC5C,CAAC;IACH,CAAC;;AAGH,OAAO,EAAE,MAAM,EAAE,CAAA;AAEjB,eAAe,QAAQ,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import z from '@deepseek-ai/schemastery';
|
|
2
|
+
/** How the adapter carries Slack events: Socket Mode (outbound) or the Events API (inbound HTTP). */
|
|
3
|
+
export type SlackProtocol = 'ws' | 'http';
|
|
4
|
+
/** One Slack workspace installation. */
|
|
5
|
+
export interface Config {
|
|
6
|
+
/** Bot user id (`U…`), checked against `auth.test` on connect. */
|
|
7
|
+
selfId: string;
|
|
8
|
+
/** Bot token (`xoxb-…`); every Web API call and the file download present it. */
|
|
9
|
+
botToken: string;
|
|
10
|
+
/** App-level token (`xapp-…`); only `apps.connections.open` uses it. Required by `protocol: 'ws'`. */
|
|
11
|
+
token: string;
|
|
12
|
+
/** Events API signing secret. Required by `protocol: 'http'`. */
|
|
13
|
+
signing: string;
|
|
14
|
+
protocol: SlackProtocol;
|
|
15
|
+
/** Inbound route of `protocol: 'http'`: absolute, no trailing slash. */
|
|
16
|
+
path: string;
|
|
17
|
+
/** Web API root. */
|
|
18
|
+
apiBaseUrl: string;
|
|
19
|
+
/** Post a thread reply to the channel as well (`chat.postMessage`'s `reply_broadcast`). */
|
|
20
|
+
replyBroadcast: boolean;
|
|
21
|
+
ws: {
|
|
22
|
+
/** Fast-retry budget of the Socket Mode reconnect loop; it never gives up. */
|
|
23
|
+
retryTimes: number;
|
|
24
|
+
/** Delay between dials while the fast-retry budget lasts. */
|
|
25
|
+
retryInterval: number;
|
|
26
|
+
/** Delay between dials once the fast-retry budget is spent. */
|
|
27
|
+
retryLazy: number;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Validated Slack adapter configuration. */
|
|
31
|
+
export declare const Config: z<Config>;
|
|
32
|
+
/**
|
|
33
|
+
* The configuration the selected protocol cannot work from.
|
|
34
|
+
*
|
|
35
|
+
* The two transports need different credentials: Socket Mode dials with the app-level token, the Events API verifies
|
|
36
|
+
* with the signing secret. A profile that leaves the needed one out is refused when the plugin loads, not when the
|
|
37
|
+
* first dial or the first callback fails.
|
|
38
|
+
*
|
|
39
|
+
* @param config - the validated configuration.
|
|
40
|
+
* @returns the configuration error, or undefined when the selection is complete.
|
|
41
|
+
*/
|
|
42
|
+
export declare function configError(config: Config): Error | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Normalize an inbound route path: absolute, no trailing slash.
|
|
45
|
+
* @param path - the configured `path`.
|
|
46
|
+
* @returns the pathname to register.
|
|
47
|
+
*/
|
|
48
|
+
export declare function routePath(path: string): string;
|
|
49
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAExC,qGAAqG;AACrG,MAAM,MAAM,aAAa,GAAG,IAAI,GAAG,MAAM,CAAA;AAEzC,wCAAwC;AACxC,MAAM,WAAW,MAAM;IACrB,kEAAkE;IAClE,MAAM,EAAE,MAAM,CAAA;IACd,iFAAiF;IACjF,QAAQ,EAAE,MAAM,CAAA;IAChB,sGAAsG;IACtG,KAAK,EAAE,MAAM,CAAA;IACb,iEAAiE;IACjE,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,aAAa,CAAA;IACvB,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAA;IACZ,oBAAoB;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,2FAA2F;IAC3F,cAAc,EAAE,OAAO,CAAA;IACvB,EAAE,EAAE;QACF,8EAA8E;QAC9E,UAAU,EAAE,MAAM,CAAA;QAClB,6DAA6D;QAC7D,aAAa,EAAE,MAAM,CAAA;QACrB,+DAA+D;QAC/D,SAAS,EAAE,MAAM,CAAA;KAClB,CAAA;CACF;AAED,6CAA6C;AAC7C,eAAO,MAAM,MAAM,EAAE,CAAC,CAAC,MAAM,CAgB3B,CAAA;AAEF;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAoB7D;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG9C"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import z from '@deepseek-ai/schemastery';
|
|
2
|
+
/** Validated Slack adapter configuration. */
|
|
3
|
+
export const Config = z.object({
|
|
4
|
+
selfId: z.string().required(),
|
|
5
|
+
botToken: z.string().role('secret').required(),
|
|
6
|
+
token: z.string().role('secret').default(''),
|
|
7
|
+
signing: z.string().role('secret').default(''),
|
|
8
|
+
protocol: z.union(['ws', 'http']).required(),
|
|
9
|
+
path: z.string().default('/slack'),
|
|
10
|
+
apiBaseUrl: z.string().role('url').default('https://slack.com/api'),
|
|
11
|
+
replyBroadcast: z.boolean().default(false),
|
|
12
|
+
ws: z
|
|
13
|
+
.object({
|
|
14
|
+
retryTimes: z.natural().default(6),
|
|
15
|
+
retryInterval: z.natural().role('ms').default(5_000),
|
|
16
|
+
retryLazy: z.natural().role('ms').default(60_000),
|
|
17
|
+
})
|
|
18
|
+
.default({}),
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* The configuration the selected protocol cannot work from.
|
|
22
|
+
*
|
|
23
|
+
* The two transports need different credentials: Socket Mode dials with the app-level token, the Events API verifies
|
|
24
|
+
* with the signing secret. A profile that leaves the needed one out is refused when the plugin loads, not when the
|
|
25
|
+
* first dial or the first callback fails.
|
|
26
|
+
*
|
|
27
|
+
* @param config - the validated configuration.
|
|
28
|
+
* @returns the configuration error, or undefined when the selection is complete.
|
|
29
|
+
*/
|
|
30
|
+
export function configError(config) {
|
|
31
|
+
if (config.selfId === '') {
|
|
32
|
+
return new Error('slack: selfId is required (the bot user id "U…"; read it from auth.test)');
|
|
33
|
+
}
|
|
34
|
+
if (config.botToken === '') {
|
|
35
|
+
return new Error('slack: botToken is required (the "xoxb-…" bot token)');
|
|
36
|
+
}
|
|
37
|
+
if (config.protocol === 'ws' && config.token === '') {
|
|
38
|
+
return new Error('slack: protocol "ws" needs token (the "xapp-…" app-level token for apps.connections.open)');
|
|
39
|
+
}
|
|
40
|
+
if (config.protocol === 'http' && config.signing === '') {
|
|
41
|
+
return new Error('slack: protocol "http" needs signing (the Events API signing secret)');
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Normalize an inbound route path: absolute, no trailing slash.
|
|
47
|
+
* @param path - the configured `path`.
|
|
48
|
+
* @returns the pathname to register.
|
|
49
|
+
*/
|
|
50
|
+
export function routePath(path) {
|
|
51
|
+
const withSlash = path.startsWith('/') ? path : `/${path}`;
|
|
52
|
+
return withSlash.length > 1 ? withSlash.replace(/\/+$/, '') : withSlash;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAgCxC,6CAA6C;AAC7C,MAAM,CAAC,MAAM,MAAM,GAAc,CAAC,CAAC,MAAM,CAAC;IACxC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE;IAC9C,K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M,CAAC,QAAQ,KAAK,IAAI,IAAI,MAAM,CAAC,KAAK,KAAK,EAAE,EAAE,CAAC;QACpD,OAAO,IAAI,KAAK,CACd,2FAA2F,CAC5F,CAAA;IACH,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,KAAK,MAAM,IAAI,MAAM,CAAC,OAAO,KAAK,EAAE,EAAE,CAAC;QACxD,OAAO,IAAI,KAAK,CACd,sEAAsE,CACvE,CAAA;IACH,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAA;IAC1D,OAAO,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AACzE,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inbound decoding: one Slack event becomes an intake `Session`, and one message object becomes an `InboundMessage`.
|
|
3
|
+
*
|
|
4
|
+
* The event kinds the vocabulary can carry are messages (the plain kind plus `file_share` and `thread_broadcast`),
|
|
5
|
+
* message deletions and reactions; everything else is dropped. Message content is decoded from `blocks` when the
|
|
6
|
+
* message has any, and from the `text` field otherwise, so a plain-text message is not lost.
|
|
7
|
+
*/
|
|
8
|
+
import type { ChatRef, Element, InboundMessage, Session } from '@deepseek-ai/cordis-plugin-im-core';
|
|
9
|
+
import type { SlackBot } from './bot.ts';
|
|
10
|
+
/** Adapter-private context carried through `Target.referrer`. */
|
|
11
|
+
export interface SlackReferrer {
|
|
12
|
+
/** Channel the message appeared in. */
|
|
13
|
+
channel: string;
|
|
14
|
+
/** Message timestamp. */
|
|
15
|
+
ts: string;
|
|
16
|
+
/** Thread root, when the message is a thread reply. */
|
|
17
|
+
threadTs?: string;
|
|
18
|
+
team?: string;
|
|
19
|
+
}
|
|
20
|
+
/** A file attachment of one message. */
|
|
21
|
+
export interface SlackFile {
|
|
22
|
+
id: string;
|
|
23
|
+
mimetype?: string;
|
|
24
|
+
name?: string | null;
|
|
25
|
+
title?: string | null;
|
|
26
|
+
created?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The message fields decoding reads.
|
|
30
|
+
*
|
|
31
|
+
* Every field is optional: the message arrives as an event (whose subtypes carry different fields), as a
|
|
32
|
+
* `conversations.history` row, or as the `message` of a `chat.postMessage` answer. The fields are read structurally
|
|
33
|
+
* because this is the wire.
|
|
34
|
+
*/
|
|
35
|
+
export interface SlackMessageLike {
|
|
36
|
+
ts?: string;
|
|
37
|
+
event_ts?: string;
|
|
38
|
+
text?: string;
|
|
39
|
+
blocks?: readonly unknown[];
|
|
40
|
+
files?: readonly SlackFile[];
|
|
41
|
+
user?: string;
|
|
42
|
+
bot_id?: string;
|
|
43
|
+
username?: string;
|
|
44
|
+
channel?: string;
|
|
45
|
+
channel_type?: string;
|
|
46
|
+
thread_ts?: string;
|
|
47
|
+
team?: string;
|
|
48
|
+
subtype?: string;
|
|
49
|
+
previous_message?: SlackMessageLike;
|
|
50
|
+
deleted_ts?: string;
|
|
51
|
+
reaction?: string;
|
|
52
|
+
item?: {
|
|
53
|
+
type?: string;
|
|
54
|
+
channel?: string;
|
|
55
|
+
ts?: string;
|
|
56
|
+
};
|
|
57
|
+
type?: string;
|
|
58
|
+
}
|
|
59
|
+
/** The envelope of one received event; the Events API body is the same object as the Socket Mode payload. */
|
|
60
|
+
export interface SlackEnvelopeLike {
|
|
61
|
+
type?: string;
|
|
62
|
+
event?: SlackMessageLike;
|
|
63
|
+
event_id?: string;
|
|
64
|
+
event_ts?: string;
|
|
65
|
+
team_id?: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Chat type of one Slack conversation.
|
|
69
|
+
*
|
|
70
|
+
* The event's `channel_type` is authoritative when it is present; an id prefix is the fallback, because the read
|
|
71
|
+
* endpoints answer without a type.
|
|
72
|
+
*
|
|
73
|
+
* @param id - the conversation id (`C…`, `G…`, `D…`).
|
|
74
|
+
* @param channelType - `channel_type` of the event, when it carried one.
|
|
75
|
+
* @returns the DSH chat type.
|
|
76
|
+
*/
|
|
77
|
+
export declare function chatTypeOf(id: string, channelType: string | undefined): ChatRef['type'];
|
|
78
|
+
/**
|
|
79
|
+
* Decode the inline nodes of one `rich_text*` node.
|
|
80
|
+
* @param raw - the node's `elements` array.
|
|
81
|
+
* @returns the content nodes.
|
|
82
|
+
*/
|
|
83
|
+
export declare function decodeRichText(raw: unknown): Element[];
|
|
84
|
+
/**
|
|
85
|
+
* Decode the `blocks` of one message.
|
|
86
|
+
*
|
|
87
|
+
* Only the two block kinds that carry content are decoded: `rich_text` (sections, lists, preformatted and quoted runs)
|
|
88
|
+
* and `section` (its mrkdwn text). The rest — `header`, `divider`, `context`, `image`, `actions`, `file` — are left to
|
|
89
|
+
* the message's `text` field, which Slack keeps as the notification fallback of a blocks message.
|
|
90
|
+
*
|
|
91
|
+
* @param raw - the message's `blocks`.
|
|
92
|
+
* @returns the content nodes; empty when the blocks carried nothing decodable.
|
|
93
|
+
*/
|
|
94
|
+
export declare function decodeBlocks(raw: readonly unknown[]): Element[];
|
|
95
|
+
/**
|
|
96
|
+
* Decode one attachment into the element that names it.
|
|
97
|
+
*
|
|
98
|
+
* The element's source is the bot's own `satori:` route rather than `url_private`: that URL needs the bot token, which
|
|
99
|
+
* the host does not have.
|
|
100
|
+
*
|
|
101
|
+
* @param bot - the receiving adapter, whose route serves the bytes.
|
|
102
|
+
* @param file - one `files[]` entry of the message.
|
|
103
|
+
* @returns the media element, typed by the file's MIME type.
|
|
104
|
+
*/
|
|
105
|
+
export declare function decodeFile(bot: SlackBot, file: SlackFile): Element;
|
|
106
|
+
/**
|
|
107
|
+
* Decode one message object into an inbound message.
|
|
108
|
+
*
|
|
109
|
+
* @param bot - the receiving adapter.
|
|
110
|
+
* @param data - a message event, a `conversations.history` row, or the `message` of a send answer.
|
|
111
|
+
* @param chat - the chat to report; defaults to the one the message names.
|
|
112
|
+
* @returns the decoded message, whose `content` is never empty.
|
|
113
|
+
*/
|
|
114
|
+
export declare function decodeMessage(bot: SlackBot, data: SlackMessageLike, chat?: ChatRef): InboundMessage;
|
|
115
|
+
/** The envelope id of one event: global, and the key the host deduplicates on. */
|
|
116
|
+
export declare function eventIdOf(envelope: SlackEnvelopeLike, event: SlackMessageLike): string;
|
|
117
|
+
/**
|
|
118
|
+
* Decode one received event.
|
|
119
|
+
*
|
|
120
|
+
* @param bot - the receiving adapter (its `selfId` marks its own messages, which are dropped because the host stores
|
|
121
|
+
* them from the `send` event instead).
|
|
122
|
+
* @param envelope - the event envelope of either transport.
|
|
123
|
+
* @returns the session to publish, or undefined for an event this adapter does not carry.
|
|
124
|
+
*/
|
|
125
|
+
export declare function decodeEvent(bot: SlackBot, envelope: SlackEnvelopeLike): Session | undefined;
|
|
126
|
+
//# sourceMappingURL=decode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../src/decode.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EACV,OAAO,EACP,OAAO,EACP,cAAc,EACd,OAAO,EAER,MAAM,oCAAoC,CAAA;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAGxC,iEAAiE;AACjE,MAAM,WAAW,aAAa;IAC5B,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAA;IACf,yBAAyB;IACzB,EAAE,EAAE,MAAM,CAAA;IACV,uDAAuD;IACvD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,wCAAwC;AACxC,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAA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