@zelkovajs/adapter-slack 0.0.0-stage → 0.8.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 +202 -0
- package/NOTICE +5 -0
- package/dist/adapter.d.ts +101 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +188 -0
- package/dist/adapter.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +3 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +12 -0
- package/dist/main.js.map +1 -0
- package/package.json +43 -3
- package/slack-app-manifest.yaml +31 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
package/NOTICE
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { ConversationalAdapter } from '@zelkovajs/adapter-kit';
|
|
2
|
+
import type { KitOptions, OutgoingMessage } from '@zelkovajs/adapter-kit';
|
|
3
|
+
/** One envelope of Socket Mode, as `@slack/socket-mode` emits it with `slack_event`. */
|
|
4
|
+
export interface SlackEnvelope {
|
|
5
|
+
type: string;
|
|
6
|
+
body: SlackBody;
|
|
7
|
+
ack: () => Promise<void>;
|
|
8
|
+
retry_num?: number;
|
|
9
|
+
}
|
|
10
|
+
/** The fields of an envelope body that the adapter reads. */
|
|
11
|
+
export interface SlackBody {
|
|
12
|
+
event_id?: string;
|
|
13
|
+
event?: {
|
|
14
|
+
type?: string;
|
|
15
|
+
channel?: string;
|
|
16
|
+
channel_type?: string;
|
|
17
|
+
user?: string;
|
|
18
|
+
text?: string;
|
|
19
|
+
ts?: string;
|
|
20
|
+
thread_ts?: string;
|
|
21
|
+
bot_id?: string;
|
|
22
|
+
subtype?: string;
|
|
23
|
+
};
|
|
24
|
+
type?: string;
|
|
25
|
+
user?: {
|
|
26
|
+
id?: string;
|
|
27
|
+
};
|
|
28
|
+
actions?: Array<{
|
|
29
|
+
block_id?: string;
|
|
30
|
+
value?: string;
|
|
31
|
+
}>;
|
|
32
|
+
}
|
|
33
|
+
/** The parts of the two Slack clients that the adapter uses. A test gives fakes. */
|
|
34
|
+
export interface SlackClients {
|
|
35
|
+
socket: {
|
|
36
|
+
on(event: 'slack_event', listener: (envelope: SlackEnvelope) => void): unknown;
|
|
37
|
+
start(): Promise<unknown>;
|
|
38
|
+
disconnect(): Promise<void>;
|
|
39
|
+
};
|
|
40
|
+
web: {
|
|
41
|
+
auth: {
|
|
42
|
+
test(): Promise<{
|
|
43
|
+
user_id?: string;
|
|
44
|
+
}>;
|
|
45
|
+
};
|
|
46
|
+
chat: {
|
|
47
|
+
postMessage(args: {
|
|
48
|
+
channel: string;
|
|
49
|
+
thread_ts?: string;
|
|
50
|
+
text: string;
|
|
51
|
+
blocks?: object[];
|
|
52
|
+
}): Promise<unknown>;
|
|
53
|
+
};
|
|
54
|
+
users: {
|
|
55
|
+
info(args: {
|
|
56
|
+
user: string;
|
|
57
|
+
}): Promise<{
|
|
58
|
+
user?: {
|
|
59
|
+
is_email_confirmed?: boolean;
|
|
60
|
+
profile?: {
|
|
61
|
+
email?: string;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
}>;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export interface SlackAdapterOptions extends KitOptions {
|
|
69
|
+
/** The bot token, `xoxb-...`. The default is `SLACK_BOT_TOKEN`. */
|
|
70
|
+
botToken?: string;
|
|
71
|
+
/** The app-level token with `connections:write`, `xapp-...`. The default is `SLACK_APP_TOKEN`. */
|
|
72
|
+
appToken?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Read the email of each Slack user, and send it as `verifiedEmail` if Slack confirmed it.
|
|
75
|
+
* Set it when the registration has `autoLinkByEmail`. The default is true if
|
|
76
|
+
* `SLACK_AUTO_LINK_BY_EMAIL` is `true`.
|
|
77
|
+
*/
|
|
78
|
+
autoLinkByEmail?: boolean;
|
|
79
|
+
/** Makes the two Slack clients. The default makes the real clients from the two tokens. */
|
|
80
|
+
clients?: (tokens: {
|
|
81
|
+
botToken: string;
|
|
82
|
+
appToken: string;
|
|
83
|
+
}) => SlackClients;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The Slack adapter. It connects one Slack workspace to Zelkova in Socket Mode, so it needs no
|
|
87
|
+
* public URL. It answers direct messages and mentions.
|
|
88
|
+
*/
|
|
89
|
+
export declare class SlackAdapter extends ConversationalAdapter {
|
|
90
|
+
#private;
|
|
91
|
+
constructor(options?: SlackAdapterOptions);
|
|
92
|
+
start(): Promise<void>;
|
|
93
|
+
send(thread: string, text: string): Promise<void>;
|
|
94
|
+
sendRich(thread: string, message: OutgoingMessage): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Disconnects from Slack, waits for the email lookups, and then stops the kit. Slack has an
|
|
97
|
+
* acknowledgement for each event in a lookup already, so the kit must get it.
|
|
98
|
+
*/
|
|
99
|
+
stop(): Promise<void>;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAiB,UAAU,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzF,wFAAwF;AACxF,MA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;OAGG;IACY,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAuErC"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { LogLevel, SocketModeClient } from '@slack/socket-mode';
|
|
2
|
+
import { WebClient } from '@slack/web-api';
|
|
3
|
+
import { ConversationalAdapter } from '@zelkovajs/adapter-kit';
|
|
4
|
+
/** The `block_id` of the buttons holds the thread, so a press goes back to the same thread. */
|
|
5
|
+
const BLOCK_PREFIX = 'zelkova:';
|
|
6
|
+
/** Slack retries an event within minutes. The adapter keeps each event ID this long. */
|
|
7
|
+
const SEEN_MS = 10 * 60_000;
|
|
8
|
+
const EMAIL_CACHE_MS = 10 * 60_000;
|
|
9
|
+
const SECTION_CHARS = 3_000;
|
|
10
|
+
const BUTTON_LABEL_CHARS = 75;
|
|
11
|
+
const WEB_TIMEOUT_MS = 10_000;
|
|
12
|
+
function realClients({ botToken, appToken }) {
|
|
13
|
+
if (!botToken)
|
|
14
|
+
throw new Error('Set SLACK_BOT_TOKEN, or give the botToken option.');
|
|
15
|
+
if (!appToken)
|
|
16
|
+
throw new Error('Set SLACK_APP_TOKEN, or give the appToken option.');
|
|
17
|
+
return {
|
|
18
|
+
socket: new SocketModeClient({ appToken, logLevel: LogLevel.ERROR }),
|
|
19
|
+
// The default client tries again for about 30 minutes, with no timeout. That would hold
|
|
20
|
+
// back the outbox loop of the kit, which has its own tries.
|
|
21
|
+
web: new WebClient(botToken, { logLevel: LogLevel.ERROR, timeout: WEB_TIMEOUT_MS, retryConfig: { retries: 2 } }),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** Slack reads `&`, `<` and `>` as control characters in a message text. */
|
|
25
|
+
const escape = (text) => text.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>');
|
|
26
|
+
const unescape = (text) => text.replaceAll('<', '<').replaceAll('>', '>').replaceAll('&', '&');
|
|
27
|
+
/** Splits a text into section texts of at most 3000 characters, and does not cut an entity such as `&`. */
|
|
28
|
+
function sections(text) {
|
|
29
|
+
const blocks = [];
|
|
30
|
+
let rest = text;
|
|
31
|
+
while (rest.length > SECTION_CHARS) {
|
|
32
|
+
let cut = SECTION_CHARS;
|
|
33
|
+
const amp = rest.lastIndexOf('&', cut - 1);
|
|
34
|
+
if (amp > cut - 5)
|
|
35
|
+
cut = amp;
|
|
36
|
+
blocks.push({ type: 'section', text: { type: 'mrkdwn', text: rest.slice(0, cut) } });
|
|
37
|
+
rest = rest.slice(cut);
|
|
38
|
+
}
|
|
39
|
+
blocks.push({ type: 'section', text: { type: 'mrkdwn', text: rest } });
|
|
40
|
+
return blocks;
|
|
41
|
+
}
|
|
42
|
+
/** `<channel>:<thread timestamp>`, or the channel alone for a direct message without a thread. */
|
|
43
|
+
function place(thread) {
|
|
44
|
+
const colon = thread.indexOf(':');
|
|
45
|
+
return colon === -1 ? { channel: thread } : { channel: thread.slice(0, colon), thread_ts: thread.slice(colon + 1) };
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The Slack adapter. It connects one Slack workspace to Zelkova in Socket Mode, so it needs no
|
|
49
|
+
* public URL. It answers direct messages and mentions.
|
|
50
|
+
*/
|
|
51
|
+
export class SlackAdapter extends ConversationalAdapter {
|
|
52
|
+
#socket;
|
|
53
|
+
#web;
|
|
54
|
+
#autoLink;
|
|
55
|
+
/** The event ID of each recent event, with the time of its first delivery. */
|
|
56
|
+
#seen = new Map();
|
|
57
|
+
#emails = new Map();
|
|
58
|
+
/** The last email lookup of each thread. The lookups of one thread run in order, so its events keep their order. */
|
|
59
|
+
#lookups = new Map();
|
|
60
|
+
#botUser;
|
|
61
|
+
#disconnect = null;
|
|
62
|
+
constructor(options = {}) {
|
|
63
|
+
super(options);
|
|
64
|
+
const tokens = { botToken: options.botToken ?? process.env['SLACK_BOT_TOKEN'] ?? '', appToken: options.appToken ?? process.env['SLACK_APP_TOKEN'] ?? '' };
|
|
65
|
+
const clients = (options.clients ?? realClients)(tokens);
|
|
66
|
+
this.#socket = clients.socket;
|
|
67
|
+
this.#web = clients.web;
|
|
68
|
+
this.#autoLink = options.autoLinkByEmail ?? process.env['SLACK_AUTO_LINK_BY_EMAIL'] === 'true';
|
|
69
|
+
}
|
|
70
|
+
async start() {
|
|
71
|
+
this.#botUser = (await this.#web.auth.test()).user_id;
|
|
72
|
+
this.#socket.on('slack_event', (envelope) => this.#onEnvelope(envelope));
|
|
73
|
+
await this.#socket.start();
|
|
74
|
+
}
|
|
75
|
+
async send(thread, text) {
|
|
76
|
+
await this.#web.chat.postMessage({ ...place(thread), text: escape(text) });
|
|
77
|
+
}
|
|
78
|
+
async sendRich(thread, message) {
|
|
79
|
+
let text = escape(message.text);
|
|
80
|
+
const blocks = sections(text);
|
|
81
|
+
const link = message.link;
|
|
82
|
+
if (link !== undefined && !message.text.includes(link.url)) {
|
|
83
|
+
// The link gets a section of its own, so the split of a long text cannot cut it.
|
|
84
|
+
const mrkdwn = `<${escape(link.url)}|${escape(link.label)}>`;
|
|
85
|
+
text += `\n${mrkdwn}`;
|
|
86
|
+
blocks.push({ type: 'section', text: { type: 'mrkdwn', text: mrkdwn } });
|
|
87
|
+
}
|
|
88
|
+
if (message.buttons !== undefined && message.buttons.length > 0) {
|
|
89
|
+
blocks.push({
|
|
90
|
+
type: 'actions',
|
|
91
|
+
block_id: `${BLOCK_PREFIX}${thread}`,
|
|
92
|
+
elements: message.buttons.map((button, i) => ({
|
|
93
|
+
type: 'button',
|
|
94
|
+
action_id: `zelkova-${i}`,
|
|
95
|
+
text: { type: 'plain_text', text: button.label.slice(0, BUTTON_LABEL_CHARS) },
|
|
96
|
+
value: button.action,
|
|
97
|
+
...(button.style && { style: button.style }),
|
|
98
|
+
})),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
await this.#web.chat.postMessage({ ...place(thread), text, blocks });
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Disconnects from Slack, waits for the email lookups, and then stops the kit. Slack has an
|
|
105
|
+
* acknowledgement for each event in a lookup already, so the kit must get it.
|
|
106
|
+
*/
|
|
107
|
+
async stop() {
|
|
108
|
+
this.#disconnect ??= this.#socket.disconnect().catch((error) => this.log(`The disconnect from Slack failed: ${String(error)}`));
|
|
109
|
+
while (this.#lookups.size > 0)
|
|
110
|
+
await Promise.all(this.#lookups.values());
|
|
111
|
+
await Promise.all([super.stop(), this.#disconnect]);
|
|
112
|
+
}
|
|
113
|
+
#onEnvelope({ type, body, ack }) {
|
|
114
|
+
// Acknowledge at once. Slack sends an event again about 3 seconds after an unacknowledged delivery.
|
|
115
|
+
ack().catch((error) => this.log(`The acknowledgement to Slack failed: ${String(error)}`));
|
|
116
|
+
if (type === 'events_api') {
|
|
117
|
+
const event = body.event;
|
|
118
|
+
if (body.event_id === undefined || this.#isDuplicate(body.event_id) || event?.user === undefined || event.channel === undefined)
|
|
119
|
+
return;
|
|
120
|
+
// The posts of a bot, this app too, have bot_id. An edit or a join has a subtype.
|
|
121
|
+
if (event.bot_id !== undefined || event.subtype !== undefined)
|
|
122
|
+
return;
|
|
123
|
+
let thread;
|
|
124
|
+
if (event.type === 'app_mention')
|
|
125
|
+
thread = `${event.channel}:${event.thread_ts ?? event.ts}`;
|
|
126
|
+
else if (event.type === 'message' && event.channel_type === 'im')
|
|
127
|
+
thread = event.thread_ts === undefined ? event.channel : `${event.channel}:${event.thread_ts}`;
|
|
128
|
+
else
|
|
129
|
+
return;
|
|
130
|
+
this.#forward({ thread, platformUser: event.user, text: this.#clean(event.text ?? '') });
|
|
131
|
+
}
|
|
132
|
+
else if (type === 'interactive' && body.type === 'block_actions') {
|
|
133
|
+
const action = body.actions?.[0];
|
|
134
|
+
const user = body.user?.id;
|
|
135
|
+
if (user === undefined || action?.value === undefined || !action.block_id?.startsWith(BLOCK_PREFIX))
|
|
136
|
+
return;
|
|
137
|
+
this.#forward({ thread: action.block_id.slice(BLOCK_PREFIX.length), platformUser: user, action: action.value });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/** A retry has a new envelope ID but the same event ID. */
|
|
141
|
+
#isDuplicate(eventId) {
|
|
142
|
+
const now = Date.now();
|
|
143
|
+
for (const [id, at] of this.#seen) {
|
|
144
|
+
if (now - at < SEEN_MS)
|
|
145
|
+
break;
|
|
146
|
+
this.#seen.delete(id);
|
|
147
|
+
}
|
|
148
|
+
if (this.#seen.has(eventId))
|
|
149
|
+
return true;
|
|
150
|
+
this.#seen.set(eventId, now);
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
/** Removes the mention of the bot, and reads the escaped control characters. */
|
|
154
|
+
#clean(text) {
|
|
155
|
+
const withoutMention = this.#botUser === undefined ? text : text.replaceAll(`<@${this.#botUser}>`, '');
|
|
156
|
+
return unescape(withoutMention).trim();
|
|
157
|
+
}
|
|
158
|
+
#forward(event) {
|
|
159
|
+
if (!this.#autoLink)
|
|
160
|
+
return this.receive(event);
|
|
161
|
+
const next = (this.#lookups.get(event.thread) ?? Promise.resolve()).then(async () => {
|
|
162
|
+
const verifiedEmail = await this.#email(event.platformUser);
|
|
163
|
+
this.receive(verifiedEmail === undefined ? event : { ...event, verifiedEmail });
|
|
164
|
+
});
|
|
165
|
+
this.#lookups.set(event.thread, next);
|
|
166
|
+
void next.then(() => {
|
|
167
|
+
if (this.#lookups.get(event.thread) === next)
|
|
168
|
+
this.#lookups.delete(event.thread);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
/** The email of a Slack user, only if Slack confirmed it (`is_email_confirmed`). */
|
|
172
|
+
async #email(user) {
|
|
173
|
+
const cached = this.#emails.get(user);
|
|
174
|
+
if (cached !== undefined && cached.until > Date.now())
|
|
175
|
+
return cached.email;
|
|
176
|
+
try {
|
|
177
|
+
const info = await this.#web.users.info({ user });
|
|
178
|
+
const email = info.user?.is_email_confirmed === true ? info.user.profile?.email || undefined : undefined;
|
|
179
|
+
this.#emails.set(user, { email, until: Date.now() + EMAIL_CACHE_MS });
|
|
180
|
+
return email;
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
this.log(`users.info failed for the Slack user ${user}: ${String(error)}`);
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AA2D/D,+FAA+F;AAC/F,MAAM,YAAY,GAAG,UAAU,CAAC;AAChC,wFAAwF;AACxF,MAAM,OAAO,GAAG,EAAE,GAAG,MAAM,CAAC;AAC5B,MAAM,cAAc,GAAG,EAAE,GAAG,MAAM,CAAC;AACnC,MAAM,aAAa,GAAG,KAAK,CAAC;AAC5B,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,cAAc,GAAG,MAAM,CAAC;AAE9B,SAAS,WAAW,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAA0C;IACjF,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACpF,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACpF,OAAO;QACL,MAAM,EAAE,IAAI,gBAAgB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;QACpE,wFAAwF;QACxF,4DAA4D;QAC5D,GAAG,EAAE,IAAI,SAAS,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAA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CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE;YAAE,OAAO,MAAM,CAAC,KAAK,CAAC;QAC3E,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;YAClD,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,kBAAkB,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,IAAI,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;YACzG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,cAAc,EAAE,CAAC,CAAC;YACtE,OAAO,KAAK,CAAC;QACf,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,GAAG,CAAC,wCAAwC,IAAI,KAAK,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC3E,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,YAAY,EAAE,mBAAmB,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":""}
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The command `zelkova-slack`. It reads SLACK_BOT_TOKEN, SLACK_APP_TOKEN,
|
|
3
|
+
// SLACK_AUTO_LINK_BY_EMAIL, ZELKOVA_URL and ZELKOVA_ADAPTER_CREDENTIAL.
|
|
4
|
+
import { SlackAdapter } from './adapter.js';
|
|
5
|
+
// #region main
|
|
6
|
+
const adapter = new SlackAdapter();
|
|
7
|
+
process.on('SIGTERM', () => void adapter.stop());
|
|
8
|
+
process.on('SIGINT', () => void adapter.stop());
|
|
9
|
+
// Do not catch the error of run(). After a 401, Node.js then exits with a non-zero code.
|
|
10
|
+
await adapter.run();
|
|
11
|
+
// #endregion main
|
|
12
|
+
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";AACA,0EAA0E;AAC1E,wEAAwE;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,eAAe;AACf,MAAM,OAAO,GAAG,IAAI,YAAY,EAAE,CAAC;AACnC,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AACjD,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AAChD,yFAAyF;AACzF,MAAM,OAAO,CAAC,GAAG,EAAE,CAAC;AACpB,kBAAkB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zelkovajs/adapter-slack",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"description": "The Slack adapter of Zelkova: a service that connects one Slack workspace to Zelkova in Socket Mode.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/zelkovajs/zelkova.git",
|
|
9
|
+
"directory": "packages/adapter-slack"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/zelkovajs/zelkova/tree/main/packages/adapter-slack#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/zelkovajs/zelkova/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"slack-app-manifest.yaml",
|
|
19
|
+
"LICENSE",
|
|
20
|
+
"NOTICE"
|
|
21
|
+
],
|
|
22
|
+
"bin": {
|
|
23
|
+
"zelkova-slack": "dist/main.js"
|
|
24
|
+
},
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@slack/socket-mode": "3.2.0",
|
|
33
|
+
"@slack/web-api": "8.5.0",
|
|
34
|
+
"@zelkovajs/adapter-kit": "^0.8.0"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=24"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsc -p tsconfig.build.json",
|
|
44
|
+
"typecheck": "tsc -p tsconfig.json"
|
|
45
|
+
}
|
|
6
46
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# The Slack app of @zelkovajs/adapter-slack. The guide "Connect Slack" states how to
|
|
2
|
+
# create the app from this manifest. The app uses Socket Mode, so it has no request URL.
|
|
3
|
+
display_information:
|
|
4
|
+
name: Zelkova
|
|
5
|
+
description: A Zelkova instance in Slack
|
|
6
|
+
features:
|
|
7
|
+
bot_user:
|
|
8
|
+
display_name: zelkova
|
|
9
|
+
always_online: true
|
|
10
|
+
app_home:
|
|
11
|
+
messages_tab_enabled: true
|
|
12
|
+
messages_tab_read_only_enabled: false
|
|
13
|
+
oauth_config:
|
|
14
|
+
scopes:
|
|
15
|
+
bot:
|
|
16
|
+
- app_mentions:read # the app_mention event
|
|
17
|
+
- chat:write # replies, buttons and questions
|
|
18
|
+
- im:history # the message.im event
|
|
19
|
+
- im:write # conversations.open, for a question to a person in a direct message
|
|
20
|
+
- users:read # users.info
|
|
21
|
+
- users:read.email # the email of the person, for the automatic link
|
|
22
|
+
settings:
|
|
23
|
+
event_subscriptions:
|
|
24
|
+
bot_events:
|
|
25
|
+
- app_mention
|
|
26
|
+
- message.im
|
|
27
|
+
interactivity:
|
|
28
|
+
is_enabled: true
|
|
29
|
+
org_deploy_enabled: false
|
|
30
|
+
socket_mode_enabled: true
|
|
31
|
+
token_rotation_enabled: false
|
package/README.md
DELETED