@hubot-friends/hubot-slack 0.0.0-development
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/.github/CODE_OF_CONDUCT.md +11 -0
- package/.github/contributing.md +60 -0
- package/.github/issue_template.md +48 -0
- package/.github/maintainers_guide.md +91 -0
- package/.github/pull_request_template.md +8 -0
- package/.github/workflows/ci-build.yml +74 -0
- package/LICENSE +22 -0
- package/README.md +29 -0
- package/docs/Gemfile +2 -0
- package/docs/README.md +15 -0
- package/docs/_config.yml +29 -0
- package/docs/_includes/analytics.html +7 -0
- package/docs/_includes/head.html +33 -0
- package/docs/_includes/page_header.html +20 -0
- package/docs/_includes/side_nav.html +22 -0
- package/docs/_includes/tag_manager.html +13 -0
- package/docs/_layouts/changelog.html +15 -0
- package/docs/_layouts/default.html +47 -0
- package/docs/_layouts/page.html +10 -0
- package/docs/_pages/FAQ.md +63 -0
- package/docs/_pages/about.md +16 -0
- package/docs/_pages/advanced_usage.md +102 -0
- package/docs/_pages/auth.md +44 -0
- package/docs/_pages/basic_usage.md +302 -0
- package/docs/_pages/changelog.html +17 -0
- package/docs/_pages/upgrading.md +49 -0
- package/docs/_posts/2016-07-15-v4.0.0.md +14 -0
- package/docs/_posts/2016-07-19-v4.0.1.md +5 -0
- package/docs/_posts/2016-08-03-v4.0.2.md +4 -0
- package/docs/_posts/2016-09-12-v4.0.3.md +8 -0
- package/docs/_posts/2016-09-12-v4.0.4.md +4 -0
- package/docs/_posts/2016-09-14-v4.0.5.md +4 -0
- package/docs/_posts/2016-09-21-v4.1.0.md +4 -0
- package/docs/_posts/2016-10-12-v4.2.0.md +4 -0
- package/docs/_posts/2016-10-12-v4.2.1.md +4 -0
- package/docs/_posts/2016-11-05-v4.2.2.md +8 -0
- package/docs/_posts/2017-01-05-v4.3.0.md +5 -0
- package/docs/_posts/2017-01-09-v4.3.1.md +5 -0
- package/docs/_posts/2017-02-15-v4.3.2.md +5 -0
- package/docs/_posts/2017-02-17-v4.3.3.md +4 -0
- package/docs/_posts/2017-03-29-v4.3.4.md +5 -0
- package/docs/_posts/2017-08-24-v4.4.0.md +7 -0
- package/docs/_posts/2018-06-08-v4.5.0.md +13 -0
- package/docs/_posts/2018-06-14-v4.5.1.md +4 -0
- package/docs/_posts/2018-07-03-v4.5.2.md +5 -0
- package/docs/_posts/2018-07-17-v4.5.3.md +12 -0
- package/docs/_posts/2018-08-10-v4.5.4.md +7 -0
- package/docs/_posts/2018-10-01-v4.5.5.md +7 -0
- package/docs/_posts/2018-12-21-v4.6.0.md +6 -0
- package/docs/_posts/2019-04-29-v4.7.0.md +6 -0
- package/docs/_posts/2019-04-30-v4.7.1.md +5 -0
- package/docs/_posts/2020-04-03-v4.7.2.md +6 -0
- package/docs/_posts/2020-05-19-v4.8.0.md +10 -0
- package/docs/_posts/2020-10-19-v4.8.1.md +7 -0
- package/docs/_posts/2021-01-26-v4.9.0.md +8 -0
- package/docs/_posts/2022-01-12-v4.10.0.md +8 -0
- package/docs/index.md +93 -0
- package/docs/styles/docs.css +37 -0
- package/package.json +50 -0
- package/slack.js +20 -0
- package/src/SlackAdapter.mjs +302 -0
- package/src/SlackAdapter.test.mjs +342 -0
- package/src/bot.js +526 -0
- package/src/client.js +445 -0
- package/src/extensions.js +82 -0
- package/src/mention.js +15 -0
- package/src/message.js +307 -0
- package/src/testing.mjs +24 -0
- package/test/bot.js +769 -0
- package/test/client.js +446 -0
- package/test/message.js +329 -0
- package/test/stubs.js +388 -0
package/test/message.js
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
const { describe, it, beforeEach } = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const Module = require('module');
|
|
4
|
+
|
|
5
|
+
const hookModuleToReturnMockFromRequire = (module, mock) => {
|
|
6
|
+
const originalRequire = Module.prototype.require;
|
|
7
|
+
Module.prototype.require = function() {
|
|
8
|
+
if (arguments[0] === module) {
|
|
9
|
+
return mock;
|
|
10
|
+
}
|
|
11
|
+
return originalRequire.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const hubotSlackMock = require('../slack.js');
|
|
16
|
+
const axiosMock = {
|
|
17
|
+
default: {
|
|
18
|
+
create() {
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
headers: {
|
|
23
|
+
post: {}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
hookModuleToReturnMockFromRequire('hubot-slack', hubotSlackMock);
|
|
27
|
+
hookModuleToReturnMockFromRequire('axios', axiosMock);
|
|
28
|
+
|
|
29
|
+
const SlackMention = require('../src/mention');
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
describe('buildText()', function() {
|
|
33
|
+
let stubs, client, slacktextmessage, slacktextmessage_invalid_conversation;
|
|
34
|
+
beforeEach(function() {
|
|
35
|
+
({ stubs, client, slacktextmessage, slacktextmessage_invalid_conversation } = require('./stubs.js')());
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('Should decode entities', function(t, done) {
|
|
39
|
+
const message = slacktextmessage;
|
|
40
|
+
message.rawMessage.text = 'foo > & < >&<';
|
|
41
|
+
message.buildText(client, () => {
|
|
42
|
+
assert.deepEqual(message.text, 'foo > & < >&<');
|
|
43
|
+
done();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('Should remove formatting around <http> links', function(t, done) {
|
|
48
|
+
const message = slacktextmessage;
|
|
49
|
+
message.rawMessage.text = 'foo <http://www.example.com> bar';
|
|
50
|
+
message.buildText(client, () => {
|
|
51
|
+
assert.deepEqual(message.text, 'foo http://www.example.com bar');
|
|
52
|
+
done();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('Should remove formatting around <https> links', function(t, done) {
|
|
57
|
+
const message = slacktextmessage;
|
|
58
|
+
message.rawMessage.text = 'foo <https://www.example.com> bar';
|
|
59
|
+
message.buildText(client, () => {
|
|
60
|
+
assert.deepEqual(message.text, 'foo https://www.example.com bar');
|
|
61
|
+
done();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('Should remove formatting around <skype> links', function(t, done) {
|
|
66
|
+
const message = slacktextmessage;
|
|
67
|
+
message.rawMessage.text = 'foo <skype:echo123?call> bar';
|
|
68
|
+
message.buildText(client, () => {
|
|
69
|
+
assert.deepEqual(message.text, 'foo skype:echo123?call bar');
|
|
70
|
+
done();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('Should remove formatting around <https> links with a label', function(t, done) {
|
|
75
|
+
const message = slacktextmessage;
|
|
76
|
+
message.rawMessage.text = 'foo <https://www.example.com|label> bar';
|
|
77
|
+
message.buildText(client, () => {
|
|
78
|
+
assert.deepEqual(message.text, 'foo label (https://www.example.com) bar');
|
|
79
|
+
done();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('Should remove formatting around <https> links with a substring label', function(t, done) {
|
|
84
|
+
const message = slacktextmessage;
|
|
85
|
+
message.rawMessage.text = 'foo <https://www.example.com|example.com> bar';
|
|
86
|
+
message.buildText(client, () => {
|
|
87
|
+
assert.deepEqual(message.text, 'foo https://www.example.com bar');
|
|
88
|
+
done();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('Should remove formatting around <https> links with a label containing entities', function(t, done) {
|
|
93
|
+
const message = slacktextmessage;
|
|
94
|
+
message.rawMessage.text = 'foo <https://www.example.com|label > & <> bar';
|
|
95
|
+
message.buildText(client, () => {
|
|
96
|
+
assert.deepEqual(message.text, 'foo label > & < (https://www.example.com) bar');
|
|
97
|
+
done();
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('Should remove formatting around <mailto> links', function(t, done) {
|
|
102
|
+
const message = slacktextmessage;
|
|
103
|
+
message.rawMessage.text = 'foo <mailto:name@example.com> bar';
|
|
104
|
+
message.buildText(client, () => {
|
|
105
|
+
assert.deepEqual(message.text, 'foo name@example.com bar');
|
|
106
|
+
done();
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('Should remove formatting around <mailto> links with an email label', function(t, done) {
|
|
111
|
+
const message = slacktextmessage;
|
|
112
|
+
message.rawMessage.text = 'foo <mailto:name@example.com|name@example.com> bar';
|
|
113
|
+
message.buildText(client, () => {
|
|
114
|
+
assert.deepEqual(message.text, 'foo name@example.com bar');
|
|
115
|
+
done();
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('Should handle empty text with attachments', function(t, done) {
|
|
120
|
+
const message = slacktextmessage;
|
|
121
|
+
message.rawMessage.text = undefined;
|
|
122
|
+
message.rawMessage.attachments = [
|
|
123
|
+
{ fallback: 'first' },
|
|
124
|
+
];
|
|
125
|
+
message.buildText(client, () => {
|
|
126
|
+
assert.deepEqual(message.text, '\nfirst');
|
|
127
|
+
done();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('Should handle an empty set of attachments', function(t, done) {
|
|
132
|
+
const message = slacktextmessage;
|
|
133
|
+
message.rawMessage.text = 'foo';
|
|
134
|
+
message.rawMessage.attachments = [];
|
|
135
|
+
message.buildText(client, () => {
|
|
136
|
+
assert.deepEqual(message.text, 'foo');
|
|
137
|
+
done();
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('Should change multiple links at once', function(t, done) {
|
|
142
|
+
const message = slacktextmessage;
|
|
143
|
+
message.rawMessage.text = 'foo <@U123|label> bar <#C123> <!channel> <https://www.example.com|label>';
|
|
144
|
+
message.buildText(client, () => {
|
|
145
|
+
assert.deepEqual(message.text, 'foo @label bar #general @channel label (https://www.example.com)');
|
|
146
|
+
done();
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('Should populate mentions with simple SlackMention object', function(t, done) {
|
|
151
|
+
const message = slacktextmessage;
|
|
152
|
+
message.rawMessage.text = 'foo <@U123> bar';
|
|
153
|
+
message.buildText(client, function() {
|
|
154
|
+
assert.deepEqual(message.mentions.length, 1);
|
|
155
|
+
assert.deepEqual(message.mentions[0].type, 'user');
|
|
156
|
+
assert.deepEqual(message.mentions[0].id, 'U123');
|
|
157
|
+
assert.deepEqual((message.mentions[0] instanceof SlackMention), true);
|
|
158
|
+
done();
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('Should populate mentions with simple SlackMention object with label', function(t, done) {
|
|
163
|
+
const message = slacktextmessage;
|
|
164
|
+
message.rawMessage.text = 'foo <@U123|label> bar';
|
|
165
|
+
message.buildText(client, function() {
|
|
166
|
+
assert.deepEqual(message.mentions.length, 1);
|
|
167
|
+
assert.deepEqual(message.mentions[0].type, 'user');
|
|
168
|
+
assert.deepEqual(message.mentions[0].id, 'U123');
|
|
169
|
+
assert.deepEqual(message.mentions[0].info, undefined);
|
|
170
|
+
assert.deepEqual((message.mentions[0] instanceof SlackMention), true);
|
|
171
|
+
done();
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('Should populate mentions with multiple SlackMention objects', function(t, done) {
|
|
176
|
+
const message = slacktextmessage;
|
|
177
|
+
message.rawMessage.text = 'foo <@U123> bar <#C123> baz <@U123|label> qux';
|
|
178
|
+
message.buildText(client, function() {
|
|
179
|
+
assert.deepEqual(message.mentions.length, 3);
|
|
180
|
+
assert.deepEqual((message.mentions[0] instanceof SlackMention), true);
|
|
181
|
+
assert.deepEqual((message.mentions[1] instanceof SlackMention), true);
|
|
182
|
+
assert.deepEqual((message.mentions[2] instanceof SlackMention), true);
|
|
183
|
+
done();
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('Should populate mentions with simple SlackMention object if user in brain', function(t, done) {
|
|
188
|
+
client.updateUserInBrain(stubs.user);
|
|
189
|
+
const message = slacktextmessage;
|
|
190
|
+
message.rawMessage.text = 'foo <@U123> bar';
|
|
191
|
+
message.buildText(client, function() {
|
|
192
|
+
assert.deepEqual(message.mentions.length, 1);
|
|
193
|
+
assert.deepEqual(message.mentions[0].type, 'user');
|
|
194
|
+
assert.deepEqual(message.mentions[0].id, 'U123');
|
|
195
|
+
assert.deepEqual((message.mentions[0] instanceof SlackMention), true);
|
|
196
|
+
done();
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('Should add conversation to cache', function(t, done) {
|
|
201
|
+
const message = slacktextmessage;
|
|
202
|
+
message.rawMessage.text = 'foo bar';
|
|
203
|
+
message.buildText(client, function() {
|
|
204
|
+
assert.deepEqual(message.text, 'foo bar');
|
|
205
|
+
assert.ok(Object.keys(client.channelData).includes('C123'));
|
|
206
|
+
done();
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('Should not modify conversation if it is not expired', function(t, done) {
|
|
211
|
+
const message = slacktextmessage;
|
|
212
|
+
client.channelData[stubs.channel.id] = {
|
|
213
|
+
channel: {id: stubs.channel.id, name: 'baz'},
|
|
214
|
+
updated: Date.now()
|
|
215
|
+
};
|
|
216
|
+
message.rawMessage.text = 'foo bar';
|
|
217
|
+
message.buildText(client, function() {
|
|
218
|
+
assert.deepEqual(message.text, 'foo bar');
|
|
219
|
+
assert.ok(Object.keys(client.channelData).includes('C123'));
|
|
220
|
+
assert.deepEqual(client.channelData['C123'].channel.name, 'baz');
|
|
221
|
+
done();
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('Should handle conversation errors', function(t, done) {
|
|
226
|
+
const message = slacktextmessage_invalid_conversation;
|
|
227
|
+
message.rawMessage.text = 'foo bar';
|
|
228
|
+
message.buildText(client, () => {
|
|
229
|
+
client.robot.logger.logs != null ? assert.deepEqual(client.robot.logger.logs.error.length, 1) : undefined;
|
|
230
|
+
done();
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('Should flatten attachments', function(t, done) {
|
|
235
|
+
const message = slacktextmessage;
|
|
236
|
+
message.rawMessage.text = 'foo bar';
|
|
237
|
+
message.rawMessage.attachments = [
|
|
238
|
+
{ fallback: 'first' },
|
|
239
|
+
{ fallback: 'second' }
|
|
240
|
+
];
|
|
241
|
+
message.buildText(client, () => {
|
|
242
|
+
assert.deepEqual(message.text, 'foo bar\nfirst\nsecond');
|
|
243
|
+
done();
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
describe('replaceLinks()', function() {
|
|
250
|
+
let stubs, client, slacktextmessage, slacktextmessage_invalid_conversation;
|
|
251
|
+
beforeEach(function() {
|
|
252
|
+
({ stubs, client, slacktextmessage, slacktextmessage_invalid_conversation } = require('./stubs.js')());
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('Should change <@U123> links to @name', async function() {
|
|
256
|
+
const text = await slacktextmessage.replaceLinks(client, 'foo <@U123> bar');
|
|
257
|
+
assert.deepEqual(text, 'foo @name bar');
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('Should change <@U123|label> links to @label', async function() {
|
|
261
|
+
const text = await slacktextmessage.replaceLinks(client, 'foo <@U123|label> bar');
|
|
262
|
+
assert.deepEqual(text, 'foo @label bar');
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('Should handle invalid User ID gracefully', async function() {
|
|
266
|
+
const text = await slacktextmessage.replaceLinks(client, 'foo <@U555> bar');
|
|
267
|
+
assert.deepEqual(text, 'foo <@U555> bar');
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('Should handle empty User API response', async function() {
|
|
271
|
+
const text = await slacktextmessage.replaceLinks(client, 'foo <@U789> bar');
|
|
272
|
+
assert.deepEqual(text, 'foo <@U789> bar');
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it('Should change <#C123> links to #general', async function() {
|
|
276
|
+
const text = await slacktextmessage.replaceLinks(client, 'foo <#C123> bar');
|
|
277
|
+
assert.deepEqual(text, 'foo #general bar');
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it('Should change <#C123|label> links to #label', async function() {
|
|
281
|
+
const text = await slacktextmessage.replaceLinks(client, 'foo <#C123|label> bar');
|
|
282
|
+
assert.deepEqual(text, 'foo #label bar');
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('Should handle invalid Conversation ID gracefully', async function() {
|
|
286
|
+
const text = await slacktextmessage.replaceLinks(client, 'foo <#C555> bar');
|
|
287
|
+
assert.deepEqual(text, 'foo <#C555> bar');
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it('Should handle empty Conversation API response', async function() {
|
|
291
|
+
const text = await slacktextmessage.replaceLinks(client, 'foo <#C789> bar');
|
|
292
|
+
assert.deepEqual(text, 'foo <#C789> bar');
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it('Should change <!everyone> links to @everyone', async function() {
|
|
296
|
+
const text = await slacktextmessage.replaceLinks(client, 'foo <!everyone> bar');
|
|
297
|
+
assert.deepEqual(text, 'foo @everyone bar');
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it('Should change <!channel> links to @channel', async function() {
|
|
301
|
+
const text = await slacktextmessage.replaceLinks(client, 'foo <!channel> bar');
|
|
302
|
+
assert.deepEqual(text, 'foo @channel bar');
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it('Should change <!group> links to @group', async function() {
|
|
306
|
+
const text = await slacktextmessage.replaceLinks(client, 'foo <!group> bar');
|
|
307
|
+
assert.deepEqual(text, 'foo @group bar');
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it('Should change <!here> links to @here', async function() {
|
|
311
|
+
const text = await slacktextmessage.replaceLinks(client, 'foo <!here> bar');
|
|
312
|
+
assert.deepEqual(text, 'foo @here bar');
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('Should change <!subteam^S123|@subteam> links to @subteam', async function() {
|
|
316
|
+
const text = await slacktextmessage.replaceLinks(client, 'foo <!subteam^S123|@subteam> bar');
|
|
317
|
+
assert.deepEqual(text, 'foo @subteam bar');
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it('Should change <!foobar|hello> links to hello', async function() {
|
|
321
|
+
const text = await slacktextmessage.replaceLinks(client, 'foo <!foobar|hello> bar');
|
|
322
|
+
assert.deepEqual(text, 'foo hello bar');
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it('Should leave <!foobar> links as-is when no label is provided', async function() {
|
|
326
|
+
const text = await slacktextmessage.replaceLinks(client, 'foo <!foobar> bar');
|
|
327
|
+
assert.deepEqual(text, 'foo <!foobar> bar');
|
|
328
|
+
});
|
|
329
|
+
});
|