@hubot-friends/hubot-slack 3.7.0 → 3.7.2

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.
@@ -11,8 +11,8 @@ Describe your issue here.
11
11
  - [ ] discussion
12
12
 
13
13
  ### Requirements (place an `x` in each of the `[ ]`)
14
- * [ ] I've read and understood the [Contributing guidelines](./contributing.md) and have done my best effort to follow them.
15
- * [ ] I've read and agree to the [Code of Conduct](./CODE_OF_CONDUCT.md).
14
+ * [ ] I've read and understood the [Contributing guidelines](./.github/contributing.md) and have done my best effort to follow them.
15
+ * [ ] I've read and agree to the [Code of Conduct](./.github/CODE_OF_CONDUCT.md).
16
16
  * [ ] I've searched for any related issues and avoided creating a duplicate issue.
17
17
 
18
18
  ---
@@ -4,4 +4,4 @@ Describe the goal of this PR. Mention any related Issue numbers.
4
4
 
5
5
  ### Requirements (place an `x` in each `[ ]`)
6
6
 
7
- * [ ] I've read and understood the [Contributing Guidelines](./contributing.md) and have done my best effort to follow them.
7
+ * [ ] I've read and understood the [Contributing Guidelines](./.github/contributing.md) and have done my best effort to follow them.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubot-friends/hubot-slack",
3
- "version": "3.7.0",
3
+ "version": "3.7.2",
4
4
  "description": "A new Slack adapter for Hubot",
5
5
  "homepage": "https://github.com/hubot-friends/hubot-slack#readme",
6
6
  "main": "./index.mjs",
@@ -8,7 +8,7 @@
8
8
  "test": "node --test",
9
9
  "test:watch": "node --test --watch",
10
10
  "test:integration": "node --test --env-file=.env",
11
- "start:local": "node --watch --env-file=.env node_modules/hubot/bin/hubot --adapter ../../../index.mjs --name gbot"
11
+ "start:local": "node --watch --env-file=.env node_modules/hubot/bin/hubot --adapter ../../../index.mjs --name jbot"
12
12
  },
13
13
  "keywords": [
14
14
  "hubot",
@@ -32,7 +32,7 @@
32
32
  "node": ">= 18"
33
33
  },
34
34
  "peerDependencies": {
35
- "hubot": "^12.0.0"
35
+ "hubot": "^13.0.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "pino-pretty": "^10.0.1"
package/src/Bot.mjs CHANGED
@@ -78,12 +78,19 @@ class SlackClient {
78
78
  return;
79
79
  }
80
80
  this.robot.logger.debug(`SlackClient#send() room: ${room}, message: ${message}`);
81
- const messageOptions = {
81
+ let messageOptions = {
82
82
  channel: room,
83
83
  text: typeof message === "string" ? message : message.text,
84
84
  thread_ts, // Include thread_ts if it's defined
85
- ...message, // Spread other properties from the message if it's an object
86
85
  };
86
+ if (typeof message === "object") {
87
+ Object.assign(messageOptions, message);
88
+ // Ensure channel and text are not overwritten
89
+ messageOptions.channel = room;
90
+ if (message.text == null) {
91
+ messageOptions.text = '';
92
+ }
93
+ }
87
94
 
88
95
  try {
89
96
  const result = await this.web.chat.postMessage(messageOptions);
@@ -179,10 +186,9 @@ class SlackBot extends Adapter {
179
186
  super(robot);
180
187
  this.options = options;
181
188
  this.robot.logger.info(`hubot-slack adapter v${pkg.version}`);
182
- this.socket = new SocketModeClient({ appToken: options.appToken, ...options.socketModeOptions });
183
- this.web = new WebClient(options.botToken, { agent: robot.config?.agent ?? undefined, maxRequestConcurrency: 1, logLevel: 'error'});
184
- this.client = new SlackClient(this.options, this.robot, this.socket, this.web);
185
- this.seenMessages = new Set();
189
+ this.socket = options.socket ?? new SocketModeClient({ appToken: options.appToken, ...options.socketModeOptions });
190
+ const web = options.web ?? new WebClient(options.botToken, { agent: robot.config?.agent ?? undefined, maxRequestConcurrency: 1, logLevel: 'error'});
191
+ this.client = new SlackClient(this.options, this.robot, this.socket, web);
186
192
  }
187
193
 
188
194
  async run() {
@@ -489,14 +495,6 @@ class SlackBot extends Adapter {
489
495
  this.robot.logger.debug(`Text = ${message.body.event.text}`);
490
496
  this.robot.logger.debug(`Event subtype = ${message.body.event?.subtype}`);
491
497
 
492
- // Ignore messages we've already seen
493
- if (this.seenMessages.has(message.body.event.client_msg_id)) {
494
- this.robot.logger.debug(`Ignoring message ${message.body.event.client_msg_id}`);
495
- return;
496
- }
497
-
498
- this.seenMessages.add(message.body.event.client_msg_id);
499
-
500
498
  try {
501
499
  switch (message.event.type) {
502
500
  case "member_joined_channel":
@@ -542,9 +540,6 @@ class SlackBot extends Adapter {
542
540
  }
543
541
  } catch (e) {
544
542
  this.robot.logger.error(e);
545
- } finally {
546
- this.robot.logger.debug(`Removing message ${message.body.event.client_msg_id}`);
547
- this.seenMessages.delete(message.body.event.client_msg_id);
548
543
  }
549
544
  }
550
545
 
package/test/Bot.mjs CHANGED
@@ -4,13 +4,14 @@ import { SlackBot } from '../src/Bot.mjs'
4
4
  import hubotSlackMock from '../index.mjs'
5
5
  import { loadBot } from 'hubot'
6
6
  import { SlackTextMessage, ReactionMessage, FileSharedMessage } from '../src/Message.mjs'
7
+ import { EventEmitter } from 'node:events'
7
8
 
8
9
  describe('Adapter', () => {
9
10
  let stubs, slackbot
10
11
  beforeEach(async () => {
11
- ({stubs, slackbot} = (await import('./Stubs.mjs')).default())
12
+ ({ stubs, slackbot } = (await import('./Stubs.mjs')).default())
12
13
  })
13
-
14
+
14
15
  it('Should initialize with a robot', () => {
15
16
  assert.deepEqual(slackbot.robot, stubs.robot)
16
17
  })
@@ -20,7 +21,7 @@ describe('Adapter', () => {
20
21
  process.env.HUBOT_SLACK_BOT_TOKEN = 'xoxb-faketoken'
21
22
 
22
23
  const loadedRobot = loadBot(hubotSlackMock, false, 'Hubot')
23
- await loadedRobot.loadAdapter()
24
+ await loadedRobot.loadAdapter()
24
25
 
25
26
  assert.ok(loadedRobot.hearReaction instanceof Function)
26
27
  assert.deepEqual(loadedRobot.hearReaction.length, 3)
@@ -34,7 +35,7 @@ describe('Adapter', () => {
34
35
  describe('Connect', () => {
35
36
  let stubs, slackbot
36
37
  beforeEach(async () => {
37
- ({stubs, slackbot} = (await import('./Stubs.mjs')).default())
38
+ ({ stubs, slackbot } = (await import('./Stubs.mjs')).default())
38
39
  })
39
40
 
40
41
  it('Should connect successfully', (t, done) => {
@@ -49,11 +50,11 @@ describe('Connect', () => {
49
50
  describe('Authenticate', () => {
50
51
  let stubs, slackbot
51
52
  beforeEach(async () => {
52
- ({stubs, slackbot} = (await import('./Stubs.mjs')).default())
53
+ ({ stubs, slackbot } = (await import('./Stubs.mjs')).default())
53
54
  })
54
55
 
55
56
  it('Should authenticate successfully', async () => {
56
- const {logger} = slackbot.robot
57
+ const { logger } = slackbot.robot
57
58
  const start = {
58
59
  self: {
59
60
  id: stubs.self.id,
@@ -79,7 +80,7 @@ describe('Authenticate', () => {
79
80
  describe('Socket', () => {
80
81
  let stubs, slackbot
81
82
  beforeEach(async () => {
82
- ({stubs, slackbot} = (await import('./Stubs.mjs')).default())
83
+ ({ stubs, slackbot } = (await import('./Stubs.mjs')).default())
83
84
  slackbot.socket.disconnect = mock.fn(() => {
84
85
  slackbot.socket.shuttingDown = true
85
86
  slackbot.socket.emit('close')
@@ -96,7 +97,7 @@ describe('Socket', () => {
96
97
 
97
98
  it('Should log socket close event when we call socket.disconnect()', async () => {
98
99
  const { logger } = slackbot.robot
99
-
100
+
100
101
  slackbot.socket.autoReconnectEnabled = true
101
102
 
102
103
  await slackbot.run()
@@ -138,11 +139,11 @@ describe('Socket', () => {
138
139
  describe('Logger', () => {
139
140
  let stubs, slackbot
140
141
  beforeEach(async () => {
141
- ({stubs, slackbot} = (await import('./Stubs.mjs')).default())
142
+ ({ stubs, slackbot } = (await import('./Stubs.mjs')).default())
142
143
  })
143
144
 
144
145
  it('It should log invalid botToken error', (t, done) => {
145
- const {logger} = slackbot.robot
146
+ const { logger } = slackbot.robot
146
147
  logger.error = message => {
147
148
  assert.deepEqual(message, 'Invalid botToken provided, please follow the upgrade instructions')
148
149
  done()
@@ -153,7 +154,7 @@ describe('Logger', () => {
153
154
  })
154
155
 
155
156
  it('It should log invalid appToken error', (t, done) => {
156
- const {logger} = slackbot.robot
157
+ const { logger } = slackbot.robot
157
158
  logger.error = message => {
158
159
  assert.deepEqual(message, 'Invalid appToken provided, please follow the upgrade instructions')
159
160
  done()
@@ -167,12 +168,12 @@ describe('Logger', () => {
167
168
  describe('Disable Sync', () => {
168
169
  let stubs, slackbot
169
170
  beforeEach(async () => {
170
- ({stubs, slackbot} = (await import('./Stubs.mjs')).default())
171
+ ({ stubs, slackbot } = (await import('./Stubs.mjs')).default())
171
172
  })
172
173
 
173
174
  it('Should sync users by default', () => {
174
175
  slackbot.run()
175
- assert.deepEqual(Object.keys(slackbot.robot.brain.data.users), ['1','2','3','4'])
176
+ assert.deepEqual(Object.keys(slackbot.robot.brain.data.users), ['1', '2', '3', '4'])
176
177
  })
177
178
 
178
179
  it('Should not sync users when disabled', () => {
@@ -184,18 +185,74 @@ describe('Disable Sync', () => {
184
185
 
185
186
  describe('Send Messages', () => {
186
187
  let stubs, slackbot
188
+ let bot
187
189
  beforeEach(async () => {
188
- ({stubs, slackbot} = (await import('./Stubs.mjs')).default())
190
+ bot = new SlackBot({
191
+ alias: '!', logger: { info() { }, debug() { }, error(e) { throw e } }
192
+ }, {
193
+ appToken: '',
194
+ socket: new EventEmitter(),
195
+ web: {
196
+ users: {
197
+ list: () => Promise.resolve(stubs.responseUsersList)
198
+ },
199
+ conversations: {
200
+ open: ({ users }) => {
201
+ const user = users.split(',')[0]
202
+ return Promise.resolve({ ok: true, channel: { id: `D${user.substring(1)}` } })
203
+ }
204
+ },
205
+ chat: {
206
+ postMessage: (options) => {
207
+ stubs._topic = options.topic
208
+ return Promise.resolve({ ok: true })
209
+ }
210
+ }
211
+ }
212
+ })
213
+
214
+ bot.self = {
215
+ user_id: '1234'
216
+ };
217
+ ({ stubs, slackbot } = (await import('./Stubs.mjs')).default())
189
218
  })
190
219
 
191
- it('Should send a message', () => {
192
- slackbot.client.send = (envelope, message) => {
193
- stubs._sendCount++
194
- stubs._msg = message
220
+ it('Send a message and message options has thread_ts and text, but not indexed properties due to the message being spread out to it', async () => {
221
+ const envelope = {
222
+ room: 'D1234',
223
+ message: {
224
+ room: 'D1234',
225
+ thread_ts: '1234567890.123456'
226
+ }
195
227
  }
196
- slackbot.send({room: stubs.channel.id}, 'message')
197
- assert.deepEqual(stubs._sendCount, 1)
198
- assert.deepEqual(stubs._msg, 'message')
228
+
229
+ bot.client.web = {
230
+ chat: {
231
+ async postMessage(options) {
232
+ assert.deepEqual(options[0], undefined)
233
+ assert.deepEqual(options.channel, 'D1234')
234
+ assert.deepEqual(options.text, 'test message')
235
+ assert.deepEqual(options.thread_ts, '1234567890.123456')
236
+ return Promise.resolve({ ok: true })
237
+ }
238
+ }
239
+ }
240
+ await bot.send(envelope, 'test message')
241
+ })
242
+
243
+ it('Should send a message that is an object', async () => {
244
+ const envelope = { room: 'D1234' }
245
+ bot.client.web = {
246
+ chat: {
247
+ async postMessage(options) {
248
+ assert.deepEqual(options.channel, 'D1234')
249
+ assert.deepEqual(options.text, 'test message')
250
+ assert.deepEqual(options.thread_ts, '1234567890.123456')
251
+ return Promise.resolve({ ok: true })
252
+ }
253
+ }
254
+ }
255
+ await bot.send(envelope, { text: 'test message', thread_ts: '1234567890.123456' })
199
256
  })
200
257
 
201
258
  it('Should send multiple messages', () => {
@@ -203,7 +260,7 @@ describe('Send Messages', () => {
203
260
  stubs._sendCount++
204
261
  }
205
262
 
206
- slackbot.send({room: stubs.channel.id}, 'one', 'two', 'three')
263
+ slackbot.send({ room: stubs.channel.id }, 'one', 'two', 'three')
207
264
  assert.deepEqual(stubs._sendCount, 3)
208
265
  })
209
266
 
@@ -211,12 +268,12 @@ describe('Send Messages', () => {
211
268
  slackbot.client.send = (envelope, message) => {
212
269
  stubs._sendCount++
213
270
  }
214
- slackbot.send({room: stubs.channel.id}, 'Hello', '', '', 'world!')
271
+ slackbot.send({ room: stubs.channel.id }, 'Hello', '', '', 'world!')
215
272
  assert.deepEqual(stubs._sendCount, 2)
216
273
  })
217
274
 
218
275
  it('Should not fail for inexistant user', () => {
219
- assert.doesNotThrow(() => slackbot.send({room: 'U987'}, 'Hello'))
276
+ assert.doesNotThrow(() => slackbot.send({ room: 'U987' }, 'Hello'))
220
277
  })
221
278
 
222
279
  it('Should open a DM channel if needed', () => {
@@ -224,7 +281,7 @@ describe('Send Messages', () => {
224
281
  slackbot.client.send = (envelope, message) => {
225
282
  stubs._dmmsg = message
226
283
  }
227
- slackbot.send({room: stubs.user.id}, msg)
284
+ slackbot.send({ room: stubs.user.id }, msg)
228
285
  assert.deepEqual(stubs._dmmsg, msg)
229
286
  })
230
287
 
@@ -233,17 +290,17 @@ describe('Send Messages', () => {
233
290
  stubs._dmmsg = message
234
291
  stubs._room = envelope.room
235
292
  }
236
- slackbot.send({room: stubs.user.id}, 'message')
293
+ slackbot.send({ room: stubs.user.id }, 'message')
237
294
  assert.deepEqual(stubs._dmmsg, 'message')
238
295
  assert.deepEqual(stubs._room, stubs.user.id)
239
296
  })
240
297
 
241
- it('Should send a message with a callback', function(t, done) {
298
+ it('Should send a message with a callback', function (t, done) {
242
299
  slackbot.client.send = (envelope, message) => {
243
300
  stubs._msg = message
244
301
  stubs._sendCount++
245
302
  }
246
- slackbot.send({room: stubs.channel.id}, 'message with a callback', () => {
303
+ slackbot.send({ room: stubs.channel.id }, 'message with a callback', () => {
247
304
  assert.ok(true)
248
305
  done()
249
306
  })
@@ -293,7 +350,7 @@ describe('Send Messages', () => {
293
350
  describe('Reply to Messages', () => {
294
351
  let stubs, slackbot
295
352
  beforeEach(async () => {
296
- ({stubs, slackbot} = (await import('./Stubs.mjs')).default())
353
+ ({ stubs, slackbot } = (await import('./Stubs.mjs')).default())
297
354
  })
298
355
 
299
356
  it('Should mention the user in a reply sent in a channel', () => {
@@ -301,7 +358,7 @@ describe('Reply to Messages', () => {
301
358
  stubs._sendCount++
302
359
  stubs._msg = message
303
360
  }
304
- slackbot.reply({user: stubs.user, room: stubs.channel.id}, 'message')
361
+ slackbot.reply({ user: stubs.user, room: stubs.channel.id }, 'message')
305
362
  assert.deepEqual(stubs._sendCount, 1)
306
363
  assert.deepEqual(stubs._msg, `<@${stubs.user.id}>: message`)
307
364
  })
@@ -311,7 +368,7 @@ describe('Reply to Messages', () => {
311
368
  stubs._sendCount++
312
369
  stubs._msg = message
313
370
  }
314
- slackbot.reply({user: stubs.user, room: stubs.channel.id}, 'one', 'two', 'three')
371
+ slackbot.reply({ user: stubs.user, room: stubs.channel.id }, 'one', 'two', 'three')
315
372
  assert.deepEqual(stubs._sendCount, 3)
316
373
  assert.deepEqual(stubs._msg, `<@${stubs.user.id}>: three`)
317
374
  })
@@ -321,7 +378,7 @@ describe('Reply to Messages', () => {
321
378
  stubs._sendCount++
322
379
  stubs._msg = message
323
380
  }
324
- slackbot.reply({user: stubs.user, room: stubs.channel.id}, '')
381
+ slackbot.reply({ user: stubs.user, room: stubs.channel.id }, '')
325
382
  assert.deepEqual(stubs._sendCount, 0)
326
383
  })
327
384
 
@@ -330,17 +387,17 @@ describe('Reply to Messages', () => {
330
387
  stubs._sendCount++
331
388
  stubs._dmmsg = message
332
389
  }
333
- slackbot.reply({user: stubs.user, room: stubs.DM.id }, 'message')
390
+ slackbot.reply({ user: stubs.user, room: stubs.DM.id }, 'message')
334
391
  assert.deepEqual(stubs._sendCount, 1)
335
392
  assert.deepEqual(stubs._dmmsg, 'message')
336
393
  })
337
394
 
338
- it('Should call the callback', function(t, done) {
395
+ it('Should call the callback', function (t, done) {
339
396
  slackbot.client.send = (envelope, message) => {
340
397
  stubs._sendCount++
341
398
  stubs._msg = message
342
399
  }
343
- slackbot.reply({user: stubs.user, room: stubs.channel.id}, 'message', () => {
400
+ slackbot.reply({ user: stubs.user, room: stubs.channel.id }, 'message', () => {
344
401
  assert.ok(true)
345
402
  done()
346
403
  })
@@ -352,21 +409,21 @@ describe('Reply to Messages', () => {
352
409
  describe('Setting the channel topic', () => {
353
410
  let stubs, slackbot
354
411
  beforeEach(async () => {
355
- ({stubs, slackbot} = (await import('./Stubs.mjs')).default())
412
+ ({ stubs, slackbot } = (await import('./Stubs.mjs')).default())
356
413
  })
357
414
 
358
415
  it('Should set the topic in channels', async () => {
359
416
  let wasCalled = false
360
- stubs.receiveMock.onTopic = function(topic) {
417
+ stubs.receiveMock.onTopic = function (topic) {
361
418
  assert.deepEqual(topic, 'channel')
362
419
  wasCalled = true
363
420
  }
364
- await slackbot.setTopic({room: stubs.channel.id}, 'channel')
421
+ await slackbot.setTopic({ room: stubs.channel.id }, 'channel')
365
422
  assert.deepEqual(wasCalled, true)
366
423
  })
367
424
 
368
425
  it('Should NOT set the topic in DMs', async () => {
369
- await slackbot.setTopic({room: 'D1232'}, 'DM')
426
+ await slackbot.setTopic({ room: 'D1232' }, 'DM')
370
427
  assert.equal(stubs._topic, undefined)
371
428
  })
372
429
  })
@@ -374,7 +431,7 @@ describe('Setting the channel topic', () => {
374
431
  describe('Receiving an error event', () => {
375
432
  let stubs, slackbot
376
433
  beforeEach(async () => {
377
- ({stubs, slackbot} = (await import('./Stubs.mjs')).default())
434
+ ({ stubs, slackbot } = (await import('./Stubs.mjs')).default())
378
435
  })
379
436
  it('Should propagate that error', () => {
380
437
  let hit = false
@@ -383,13 +440,13 @@ describe('Receiving an error event', () => {
383
440
  hit = true
384
441
  })
385
442
  assert.ok(!hit)
386
- slackbot.error({msg: 'ohno', code: -2})
443
+ slackbot.error({ msg: 'ohno', code: -2 })
387
444
  assert.ok(hit)
388
445
  })
389
446
 
390
447
  it('Should handle rate limit errors', () => {
391
- const {logger} = slackbot.robot
392
- slackbot.error({msg: 'ratelimit', code: -1})
448
+ const { logger } = slackbot.robot
449
+ slackbot.error({ msg: 'ratelimit', code: -1 })
393
450
  assert.ok(logger.logs["error"].length > 0)
394
451
  })
395
452
  })
@@ -397,48 +454,48 @@ describe('Receiving an error event', () => {
397
454
  describe('Handling incoming messages', () => {
398
455
  let stubs, slackbot
399
456
  beforeEach(async () => {
400
- ({stubs, slackbot} = (await import('./Stubs.mjs')).default())
457
+ ({ stubs, slackbot } = (await import('./Stubs.mjs')).default())
401
458
  })
402
459
 
403
- it('Should handle regular messages as hoped and dreamed', function(t, done) {
404
- stubs.receiveMock.onReceived = function(msg) {
460
+ it('Should handle regular messages as hoped and dreamed', function (t, done) {
461
+ stubs.receiveMock.onReceived = function (msg) {
405
462
  assert.deepEqual(msg.text, 'foo')
406
463
  done()
407
464
  }
408
- slackbot.eventHandler({body: { event: { text: 'foo', type: 'message', user: stubs.user.id }}, event: { text: 'foo', type: 'message', user: stubs.user.id, channel: stubs.channel.id }})
465
+ slackbot.eventHandler({ body: { event: { text: 'foo', type: 'message', user: stubs.user.id } }, event: { text: 'foo', type: 'message', user: stubs.user.id, channel: stubs.channel.id } })
409
466
  })
410
467
 
411
- it('Should prepend our name to a name-lacking message addressed to us in a DM', function(t, done) {
468
+ it('Should prepend our name to a name-lacking message addressed to us in a DM', function (t, done) {
412
469
  const bot_name = slackbot.robot.name
413
- stubs.receiveMock.onReceived = function(msg) {
470
+ stubs.receiveMock.onReceived = function (msg) {
414
471
  assert.deepEqual(msg.text, `@${bot_name} foo`)
415
472
  done()
416
473
  }
417
- slackbot.eventHandler({body: { event: { text: 'foo', type: 'message', user: stubs.user.id, channel_type: 'im' }}, event: { text: 'foo', type: 'message', user: stubs.user.id, channel_type: 'im', channel:stubs.DM.id }})
474
+ slackbot.eventHandler({ body: { event: { text: 'foo', type: 'message', user: stubs.user.id, channel_type: 'im' } }, event: { text: 'foo', type: 'message', user: stubs.user.id, channel_type: 'im', channel: stubs.DM.id } })
418
475
  })
419
476
 
420
- it('Should preprend our alias to a name-lacking message addressed to us in a DM', function(t, done) {
421
- const bot = new SlackBot({alias: '!', logger: {info(){}, debug(){}}}, {appToken: ''})
422
- bot.self = {
423
- user_id: '1234'
424
- }
425
- const text = bot.replaceBotIdWithName({
477
+ it('Should preprend our alias to a name-lacking message addressed to us in a DM', function (t, done) {
478
+ const bot = new SlackBot({ alias: '!', logger: { info() { }, debug() { } } }, { appToken: '', socket: new EventEmitter() })
479
+ bot.self = {
480
+ user_id: '1234'
481
+ }
482
+ const text = bot.replaceBotIdWithName({
426
483
  text: '<@1234> foo',
427
- })
484
+ })
428
485
  assert.deepEqual(text, '! foo')
429
486
  done()
430
487
  })
431
488
 
432
- it('Should NOT prepend our name to a name-containing message addressed to us in a DM', function(t, done) {
489
+ it('Should NOT prepend our name to a name-containing message addressed to us in a DM', function (t, done) {
433
490
  const bot_name = slackbot.robot.name
434
- stubs.receiveMock.onReceived = function(msg) {
491
+ stubs.receiveMock.onReceived = function (msg) {
435
492
  assert.deepEqual(msg.text, `@${bot_name} foo`)
436
493
  done()
437
494
  }
438
- slackbot.eventHandler({body: { event: { text: `@${bot_name} foo`, type: 'message', user: stubs.user.id }}, event: { text: 'foo', type: 'message', user: stubs.user.id, channel:stubs.DM.id }})
495
+ slackbot.eventHandler({ body: { event: { text: `@${bot_name} foo`, type: 'message', user: stubs.user.id } }, event: { text: 'foo', type: 'message', user: stubs.user.id, channel: stubs.DM.id } })
439
496
  })
440
497
 
441
- it('Should return a message object with raw text and message', function(t, done) {
498
+ it('Should return a message object with raw text and message', function (t, done) {
442
499
  //the shape of this data is an RTM message event passed through SlackClient#messageWrapper
443
500
  //see: https://api.slack.com/events/message
444
501
  const messageData = {
@@ -457,7 +514,7 @@ describe('Handling incoming messages', () => {
457
514
  channel: stubs.channel.id,
458
515
  }
459
516
  }
460
- stubs.receiveMock.onReceived = function(msg) {
517
+ stubs.receiveMock.onReceived = function (msg) {
461
518
  assert.deepEqual((msg instanceof SlackTextMessage), true)
462
519
  assert.deepEqual(msg.text, "foo http://www.example.com bar")
463
520
  assert.deepEqual(msg.rawText, "foo <http://www.example.com> bar")
@@ -468,7 +525,7 @@ describe('Handling incoming messages', () => {
468
525
  })
469
526
 
470
527
  it('Should handle member_joined_channel events as envisioned', () => {
471
- stubs.receiveMock.onReceived = function(msg) {
528
+ stubs.receiveMock.onReceived = function (msg) {
472
529
  assert.deepEqual(msg.constructor.name, "EnterMessage")
473
530
  assert.deepEqual(msg.ts, stubs.event_timestamp)
474
531
  assert.deepEqual(msg.user.id, stubs.user.id)
@@ -493,7 +550,7 @@ describe('Handling incoming messages', () => {
493
550
  })
494
551
 
495
552
  it('Should handle member_left_channel events as envisioned', () => {
496
- stubs.receiveMock.onReceived = function(msg) {
553
+ stubs.receiveMock.onReceived = function (msg) {
497
554
  assert.deepEqual(msg.constructor.name, "LeaveMessage")
498
555
  assert.deepEqual(msg.ts, stubs.event_timestamp)
499
556
  assert.deepEqual(msg.user.id, stubs.user.id)
@@ -533,7 +590,7 @@ describe('Handling incoming messages', () => {
533
590
  },
534
591
  reaction: 'thumbsup',
535
592
  event_ts: '1360782804.083113'
536
-
593
+
537
594
  }
538
595
  },
539
596
  event: {
@@ -552,7 +609,7 @@ describe('Handling incoming messages', () => {
552
609
  }
553
610
  }
554
611
 
555
- stubs.receiveMock.onReceived = function(msg) {
612
+ stubs.receiveMock.onReceived = function (msg) {
556
613
  assert.deepEqual((msg instanceof ReactionMessage), true)
557
614
  assert.deepEqual(msg.user.id, stubs.user.id)
558
615
  assert.deepEqual(msg.user.room, stubs.channel.id)
@@ -580,7 +637,7 @@ describe('Handling incoming messages', () => {
580
637
  },
581
638
  reaction: 'thumbsup',
582
639
  event_ts: '1360782804.083113'
583
-
640
+
584
641
  }
585
642
  },
586
643
  event: {
@@ -598,7 +655,7 @@ describe('Handling incoming messages', () => {
598
655
  event_ts: '1360782804.083113'
599
656
  }
600
657
  }
601
- stubs.receiveMock.onReceived = function(msg) {
658
+ stubs.receiveMock.onReceived = function (msg) {
602
659
  assert.deepEqual((msg instanceof ReactionMessage), true)
603
660
  assert.deepEqual(msg.user.id, stubs.user.id)
604
661
  assert.deepEqual(msg.user.room, stubs.channel.id)
@@ -611,7 +668,7 @@ describe('Handling incoming messages', () => {
611
668
  })
612
669
 
613
670
  it('Should ignore messages it sent itself', (t, done) => {
614
- stubs.receiveMock.onReceived = function(msg) {
671
+ stubs.receiveMock.onReceived = function (msg) {
615
672
  assert.fail('Should not have received a message')
616
673
  }
617
674
 
@@ -622,7 +679,7 @@ describe('Handling incoming messages', () => {
622
679
  text: 'Ignore me',
623
680
  user: stubs.self.id,
624
681
  channel: stubs.channel.id,
625
- ts: stubs.event_timestamp
682
+ ts: stubs.event_timestamp
626
683
  }
627
684
  },
628
685
  event: {
@@ -630,14 +687,14 @@ describe('Handling incoming messages', () => {
630
687
  text: 'Ignore me',
631
688
  user: stubs.self.id,
632
689
  channel: stubs.channel.id,
633
- ts: stubs.event_timestamp
690
+ ts: stubs.event_timestamp
634
691
  }
635
692
  })
636
693
  done()
637
694
  })
638
695
 
639
- it('Should handle empty users as envisioned', function(t, done){
640
- stubs.receiveMock.onReceived = function(msg) {
696
+ it('Should handle empty users as envisioned', function (t, done) {
697
+ stubs.receiveMock.onReceived = function (msg) {
641
698
  assert.fail('Should not have received a message')
642
699
  }
643
700
  slackbot.eventHandler({
@@ -647,7 +704,7 @@ describe('Handling incoming messages', () => {
647
704
  text: 'Foo',
648
705
  user: '',
649
706
  channel: stubs.channel.id,
650
- ts: stubs.event_timestamp
707
+ ts: stubs.event_timestamp
651
708
  }
652
709
  },
653
710
  event: {
@@ -655,7 +712,7 @@ describe('Handling incoming messages', () => {
655
712
  text: 'Foo',
656
713
  user: '',
657
714
  channel: stubs.channel.id,
658
- ts: stubs.event_timestamp
715
+ ts: stubs.event_timestamp
659
716
  }
660
717
  })
661
718
  done()
@@ -684,7 +741,7 @@ describe('Handling incoming messages', () => {
684
741
  event_ts: stubs.event_timestamp
685
742
  }
686
743
  }
687
- stubs.receiveMock.onReceived = function(msg) {
744
+ stubs.receiveMock.onReceived = function (msg) {
688
745
  assert.deepEqual((msg instanceof FileSharedMessage), true)
689
746
  assert.deepEqual(msg.user.id, stubs.user.id)
690
747
  assert.deepEqual(msg.user.room, stubs.channel.id)
@@ -693,13 +750,13 @@ describe('Handling incoming messages', () => {
693
750
  slackbot.eventHandler(fileMessage)
694
751
  })
695
752
  })
696
-
753
+
697
754
  describe('Robot.fileShared', () => {
698
755
  let stubs, slackbot, fileSharedMessage
699
756
  const handleFileShared = msg => `${msg.file_id} shared`
700
757
 
701
758
  beforeEach(async () => {
702
- ({stubs, slackbot} = (await import('./Stubs.mjs')).default())
759
+ ({ stubs, slackbot } = (await import('./Stubs.mjs')).default())
703
760
  const user = { id: stubs.user.id, room: stubs.channel.id }
704
761
  fileSharedMessage = new FileSharedMessage(user, "F2147483862", '1360782804.083113')
705
762
  })
@@ -708,15 +765,15 @@ describe('Robot.fileShared', () => {
708
765
  slackbot.robot.fileShared(handleFileShared)
709
766
  const listener = slackbot.robot.listeners.shift()
710
767
  assert.ok(listener.matcher(fileSharedMessage))
711
- assert.deepEqual(listener.options, {id: null})
768
+ assert.deepEqual(listener.options, { id: null })
712
769
  assert.deepEqual(listener.callback(fileSharedMessage), 'F2147483862 shared')
713
770
  })
714
-
771
+
715
772
  it('Should register a Listener with opts and callback', () => {
716
- slackbot.robot.fileShared({id: 'foobar'}, handleFileShared)
773
+ slackbot.robot.fileShared({ id: 'foobar' }, handleFileShared)
717
774
  const listener = slackbot.robot.listeners.shift()
718
775
  assert.ok(listener.matcher(fileSharedMessage))
719
- assert.deepEqual(listener.options, {id: 'foobar'})
776
+ assert.deepEqual(listener.options, { id: 'foobar' })
720
777
  assert.deepEqual(listener.callback(fileSharedMessage), 'F2147483862 shared')
721
778
  })
722
779
 
@@ -725,16 +782,16 @@ describe('Robot.fileShared', () => {
725
782
  slackbot.robot.fileShared(matcher, handleFileShared)
726
783
  const listener = slackbot.robot.listeners.shift()
727
784
  assert.ok(listener.matcher(fileSharedMessage))
728
- assert.deepEqual(listener.options, {id: null})
785
+ assert.deepEqual(listener.options, { id: null })
729
786
  assert.deepEqual(listener.callback(fileSharedMessage), 'F2147483862 shared')
730
787
  })
731
788
 
732
789
  it('Should register a Listener with matcher, opts, and callback', () => {
733
790
  const matcher = msg => msg.file_id === 'F2147483862'
734
- slackbot.robot.fileShared(matcher, {id: 'foobar'}, handleFileShared)
791
+ slackbot.robot.fileShared(matcher, { id: 'foobar' }, handleFileShared)
735
792
  const listener = slackbot.robot.listeners.shift()
736
793
  assert.ok(listener.matcher(fileSharedMessage))
737
- assert.deepEqual(listener.options, {id: 'foobar'})
794
+ assert.deepEqual(listener.options, { id: 'foobar' })
738
795
  assert.deepEqual(listener.callback(fileSharedMessage), 'F2147483862 shared')
739
796
  })
740
797
 
@@ -750,7 +807,7 @@ describe('Robot.hearReaction', () => {
750
807
  let stubs, slackbot, reactionMessage
751
808
  const handleReaction = msg => `${msg.reaction} handled`
752
809
  beforeEach(async () => {
753
- ({stubs, slackbot} = (await import('./Stubs.mjs')).default())
810
+ ({ stubs, slackbot } = (await import('./Stubs.mjs')).default())
754
811
  const user = { id: stubs.user.id, room: stubs.channel.id }
755
812
  const item = {
756
813
  type: 'message', channel: stubs.channel.id, ts: '1360782804.083113'
@@ -764,15 +821,15 @@ describe('Robot.hearReaction', () => {
764
821
  slackbot.robot.hearReaction(handleReaction)
765
822
  const listener = slackbot.robot.listeners.shift()
766
823
  assert.ok(listener.matcher(reactionMessage))
767
- assert.deepEqual(listener.options, {id: null})
824
+ assert.deepEqual(listener.options, { id: null })
768
825
  assert.deepEqual(listener.callback(reactionMessage), 'thumbsup handled')
769
826
  })
770
827
 
771
828
  it('Should register a Listener with opts and callback', () => {
772
- slackbot.robot.hearReaction({id: 'foobar'}, handleReaction)
829
+ slackbot.robot.hearReaction({ id: 'foobar' }, handleReaction)
773
830
  const listener = slackbot.robot.listeners.shift()
774
831
  assert.ok(listener.matcher(reactionMessage))
775
- assert.deepEqual(listener.options, {id: 'foobar'})
832
+ assert.deepEqual(listener.options, { id: 'foobar' })
776
833
  assert.deepEqual(listener.callback(reactionMessage), 'thumbsup handled')
777
834
  })
778
835
 
@@ -781,16 +838,16 @@ describe('Robot.hearReaction', () => {
781
838
  slackbot.robot.hearReaction(matcher, handleReaction)
782
839
  const listener = slackbot.robot.listeners.shift()
783
840
  assert.ok(listener.matcher(reactionMessage))
784
- assert.deepEqual(listener.options, {id: null})
841
+ assert.deepEqual(listener.options, { id: null })
785
842
  assert.deepEqual(listener.callback(reactionMessage), 'thumbsup handled')
786
843
  })
787
844
 
788
845
  it('Should register a Listener with matcher, opts, and callback', () => {
789
846
  const matcher = msg => (msg.type === 'removed') || (msg.reaction === 'thumbsup')
790
- slackbot.robot.hearReaction(matcher, {id: 'foobar'}, handleReaction)
847
+ slackbot.robot.hearReaction(matcher, { id: 'foobar' }, handleReaction)
791
848
  const listener = slackbot.robot.listeners.shift()
792
849
  assert.ok(listener.matcher(reactionMessage))
793
- assert.deepEqual(listener.options, {id: 'foobar'})
850
+ assert.deepEqual(listener.options, { id: 'foobar' })
794
851
  assert.deepEqual(listener.callback(reactionMessage), 'thumbsup handled')
795
852
  })
796
853
 
@@ -805,7 +862,7 @@ describe('Robot.hearReaction', () => {
805
862
  describe('Users data', () => {
806
863
  let stubs, slackbot
807
864
  beforeEach(async () => {
808
- ({stubs, slackbot} = (await import('./Stubs.mjs')).default())
865
+ ({ stubs, slackbot } = (await import('./Stubs.mjs')).default())
809
866
  })
810
867
  it('Should load users data from web api', () => {
811
868
  slackbot.usersLoaded(null, stubs.responseUsersList)
@@ -826,7 +883,7 @@ describe('Users data', () => {
826
883
 
827
884
  it('Should merge with user data which is stored by other program', () => {
828
885
  const originalUser =
829
- {something: 'something'}
886
+ { something: 'something' }
830
887
 
831
888
  slackbot.robot.brain.userForId(stubs.user.id, originalUser)
832
889
  slackbot.usersLoaded(null, stubs.responseUsersList)
@@ -1,8 +0,0 @@
1
- // If you want to use this, you have to `npm install proxy-agent` and uncomment the import statement below
2
- // import { ProxyAgent } from 'proxy-agent'
3
- export default async robot => {
4
- robot.logger.info(`This is an example showing how to configure a proxy for the Slack Adapter's Web Client to use.`)
5
- robot.config = {
6
- // agent: new ProxyAgent(),
7
- }
8
- }