@hubot-friends/hubot-slack 1.0.4 → 1.0.6
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/workflows/ci-build.yml +2 -2
- package/package.json +2 -2
- package/src/bot.js +9 -8
- package/src/client.js +3 -3
- package/src/message.js +0 -11
- package/test/bot.js +1 -1
- package/test/data/topic-message.json +49 -0
- package/test/stubs.js +4 -4
|
@@ -29,7 +29,7 @@ jobs:
|
|
|
29
29
|
- name: Install dependencies
|
|
30
30
|
run: npm ci
|
|
31
31
|
- name: Install hubot
|
|
32
|
-
run: npm i hubot
|
|
32
|
+
run: npm i hubot
|
|
33
33
|
- name: Verify the integrity of provenance attestations and registry signatures for installed dependencies
|
|
34
34
|
run: npm audit signatures
|
|
35
35
|
test:
|
|
@@ -50,7 +50,7 @@ jobs:
|
|
|
50
50
|
node-version: ${{ matrix.node-version }}
|
|
51
51
|
cache: 'npm'
|
|
52
52
|
- run: npm ci
|
|
53
|
-
- run: npm i hubot
|
|
53
|
+
- run: npm i hubot
|
|
54
54
|
- run: npm test
|
|
55
55
|
release:
|
|
56
56
|
needs: [build, test]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubot-friends/hubot-slack",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "A new Slack adapter for Hubot",
|
|
5
5
|
"homepage": "https://github.com/hubot-friends/hubot-slack#readme",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@slack/web-api": "^6.8.1"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"hubot": "^
|
|
30
|
+
"hubot": "^7.x.x"
|
|
31
31
|
},
|
|
32
32
|
"engines": {
|
|
33
33
|
"node": ">= 18.16.0",
|
package/src/bot.js
CHANGED
|
@@ -60,11 +60,11 @@ class SlackClient {
|
|
|
60
60
|
|
|
61
61
|
setTopic(conversationId, topic) {
|
|
62
62
|
this.robot.logger.debug(`SlackClient#setTopic() with topic ${topic}`);
|
|
63
|
-
return this.web.conversations.info(conversationId)
|
|
63
|
+
return this.web.conversations.info({channel: conversationId})
|
|
64
64
|
.then(res => {
|
|
65
65
|
const conversation = res.channel;
|
|
66
66
|
if (!conversation.is_im && !conversation.is_mpim) {
|
|
67
|
-
return this.web.conversations.setTopic(conversationId, topic);
|
|
67
|
+
return this.web.conversations.setTopic({channel: conversationId, topic});
|
|
68
68
|
} else {
|
|
69
69
|
return this.robot.logger.debug(`Conversation ${conversationId} is a DM or MPDM. ` +
|
|
70
70
|
"These conversation types do not have topics."
|
|
@@ -116,7 +116,7 @@ class SlackClient {
|
|
|
116
116
|
|
|
117
117
|
async fetchUser(userId) {
|
|
118
118
|
if (this.robot.brain.data.users[userId] != null) { return Promise.resolve(this.robot.brain.data.users[userId]); }
|
|
119
|
-
const r = await this.web.users.info(userId);
|
|
119
|
+
const r = await this.web.users.info({user: userId});
|
|
120
120
|
this.updateUserInBrain(r.user);
|
|
121
121
|
return r.user;
|
|
122
122
|
}
|
|
@@ -125,7 +125,7 @@ class SlackClient {
|
|
|
125
125
|
if (((this.channelData[conversationId] != null ? this.channelData[conversationId].channel : undefined) != null) &&
|
|
126
126
|
(expiration < (this.channelData[conversationId] != null ? this.channelData[conversationId].updated : undefined))) { return Promise.resolve(this.channelData[conversationId].channel); }
|
|
127
127
|
if (this.channelData[conversationId] != null) { delete this.channelData[conversationId]; }
|
|
128
|
-
return this.web.conversations.info(conversationId).then(r => {
|
|
128
|
+
return this.web.conversations.info({channel: conversationId}).then(r => {
|
|
129
129
|
if (r.channel != null) {
|
|
130
130
|
this.channelData[conversationId] = {
|
|
131
131
|
channel: r.channel,
|
|
@@ -165,8 +165,7 @@ class SlackClient {
|
|
|
165
165
|
try {
|
|
166
166
|
await this.eventHandler(event);
|
|
167
167
|
} catch (error) {
|
|
168
|
-
|
|
169
|
-
this.robot.logger.error(`An error occurred while processing an event from SlackBot's SlackClient: ${error.message}.`);
|
|
168
|
+
this.robot.logger.error(`bot.js: eventWrapper: An error occurred while processing an event from SlackBot's SlackClient: ${error.message}.`);
|
|
170
169
|
}
|
|
171
170
|
}
|
|
172
171
|
}
|
|
@@ -408,6 +407,7 @@ class SlackBot extends Adapter {
|
|
|
408
407
|
* @param {SlackBotInfo} [event.bot] - the description of the bot creating this event as returned by `bots.info`
|
|
409
408
|
*/
|
|
410
409
|
async eventHandler(message) {
|
|
410
|
+
this.robot.logger.debug(`eventHandler ${JSON.stringify(message, null, 2)}`);
|
|
411
411
|
if(!message?.body?.event?.user) {
|
|
412
412
|
if (message?.ack) {
|
|
413
413
|
return await message?.ack();
|
|
@@ -431,7 +431,9 @@ class SlackBot extends Adapter {
|
|
|
431
431
|
|
|
432
432
|
// Ignore anything we sent
|
|
433
433
|
if (from?.id === this.self.user_id) {
|
|
434
|
-
|
|
434
|
+
if (message?.ack) {
|
|
435
|
+
return await message?.ack();
|
|
436
|
+
}
|
|
435
437
|
}
|
|
436
438
|
|
|
437
439
|
this.robot.logger.debug(`event ${JSON.stringify(message, null, 2)} user = ${user}`);
|
|
@@ -453,7 +455,6 @@ class SlackBot extends Adapter {
|
|
|
453
455
|
from.name = from.profile.display_name;
|
|
454
456
|
|
|
455
457
|
// add the bot id to the message if it's a direct message
|
|
456
|
-
|
|
457
458
|
message.body.event.text = this.addBotIdToMessage(message.body.event);
|
|
458
459
|
message.body.event.text = this.replaceBotIdWithName(message.body.event);
|
|
459
460
|
this.robot.logger.debug(`Text = ${message.body.event.text}`);
|
package/src/client.js
CHANGED
|
@@ -131,10 +131,10 @@ class SlackClient extends EventEmitter {
|
|
|
131
131
|
// topic is made regardless of the conversation type. If the conversation type is not compatible, the call would
|
|
132
132
|
// fail, which is exactly the outcome in this implementation.
|
|
133
133
|
try {
|
|
134
|
-
const res = await this.web.conversations.info(conversationId)
|
|
134
|
+
const res = await this.web.conversations.info({channel: conversationId})
|
|
135
135
|
const conversation = res.channel;
|
|
136
136
|
if (!conversation.is_im && !conversation.is_mpim) {
|
|
137
|
-
return await this.web.conversations.setTopic(conversationId, topic);
|
|
137
|
+
return await this.web.conversations.setTopic({channel: conversationId, topic});
|
|
138
138
|
} else {
|
|
139
139
|
return this.robot.logger.debug(`Conversation ${conversationId} is a DM or MPDM. These conversation types do not have topics.`);
|
|
140
140
|
}
|
|
@@ -287,7 +287,7 @@ class SlackClient extends EventEmitter {
|
|
|
287
287
|
if (this.channelData[conversationId] != null) { delete this.channelData[conversationId]; }
|
|
288
288
|
|
|
289
289
|
// Return conversations.info promise
|
|
290
|
-
const r = await this.web.conversations.info(conversationId)
|
|
290
|
+
const r = await this.web.conversations.info({channel: conversationId})
|
|
291
291
|
if (r.channel != null) {
|
|
292
292
|
this.channelData[conversationId] = {
|
|
293
293
|
channel: r.channel,
|
package/src/message.js
CHANGED
|
@@ -135,17 +135,6 @@ class SlackTextMessage extends TextMessage {
|
|
|
135
135
|
text = text.replace(/</g, "<");
|
|
136
136
|
text = text.replace(/>/g, ">");
|
|
137
137
|
text = text.replace(/&/g, "&");
|
|
138
|
-
|
|
139
|
-
// special handling for message text when inside a DM conversation
|
|
140
|
-
if (conversationInfo.is_im) {
|
|
141
|
-
const startOfText = text.indexOf("@") === 0 ? 1 : 0;
|
|
142
|
-
const robotIsNamed = (text.indexOf(this._robot_name) === startOfText) || (text.indexOf(this._robot_alias) === startOfText);
|
|
143
|
-
// Assume it was addressed to us even if it wasn't
|
|
144
|
-
if (!robotIsNamed) {
|
|
145
|
-
text = `${this._robot_name} ${text}`; // If this is a DM, pretend it was addressed to us
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
138
|
this.text = text;
|
|
150
139
|
return cb();
|
|
151
140
|
}).catch(error => {
|
package/test/bot.js
CHANGED
|
@@ -33,7 +33,7 @@ describe('Adapter', function() {
|
|
|
33
33
|
process.env.HUBOT_SLACK_APP_TOKEN = 'xapp-faketoken';
|
|
34
34
|
process.env.HUBOT_SLACK_BOT_TOKEN = 'xoxb-faketoken';
|
|
35
35
|
|
|
36
|
-
const loadedRobot = loadBot('slack', false, 'Hubot');
|
|
36
|
+
const loadedRobot = loadBot('hubot-slack', false, 'Hubot');
|
|
37
37
|
await loadedRobot.loadAdapter();
|
|
38
38
|
|
|
39
39
|
assert.ok(loadedRobot.hearReaction instanceof Function);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"envelope_id": "asasdfsdfdf-cf4a-4aab-a3d4-80cb02209ff2",
|
|
3
|
+
"body": {
|
|
4
|
+
"token": "shgretafdasdfasd",
|
|
5
|
+
"team_id": "T0asfdasdfasdf",
|
|
6
|
+
"context_team_id": "T0asfdasdfasdf",
|
|
7
|
+
"context_enterprise_id": null,
|
|
8
|
+
"api_app_id": "asdfasdfasd",
|
|
9
|
+
"event": {
|
|
10
|
+
"type": "message",
|
|
11
|
+
"subtype": "channel_topic",
|
|
12
|
+
"ts": "1690670214.666729",
|
|
13
|
+
"user": "U3fasdfasdsd",
|
|
14
|
+
"text": "set the channel topic: indeed! It did work.",
|
|
15
|
+
"topic": "indeed! It did work.",
|
|
16
|
+
"channel": "CDasdfasdfsd",
|
|
17
|
+
"event_ts": "1690670214.666729",
|
|
18
|
+
"channel_type": "channel"
|
|
19
|
+
},
|
|
20
|
+
"type": "event_callback",
|
|
21
|
+
"event_id": "Ev05KDEERU2E",
|
|
22
|
+
"event_time": 1690670214,
|
|
23
|
+
"authorizations": [
|
|
24
|
+
{
|
|
25
|
+
"enterprise_id": null,
|
|
26
|
+
"team_id": "T0asfdasdfasdf",
|
|
27
|
+
"user_id": "U3fasdfasdsd",
|
|
28
|
+
"is_bot": true,
|
|
29
|
+
"is_enterprise_install": false
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"is_ext_shared_channel": false,
|
|
33
|
+
"event_context": "4-asdfasdfasd"
|
|
34
|
+
},
|
|
35
|
+
"event": {
|
|
36
|
+
"type": "message",
|
|
37
|
+
"subtype": "channel_topic",
|
|
38
|
+
"ts": "1690670214.666729",
|
|
39
|
+
"user": "U3fasdfasdsd",
|
|
40
|
+
"text": "set the channel topic: indeed! It did work.",
|
|
41
|
+
"topic": "indeed! It did work.",
|
|
42
|
+
"channel": "CDasdfasdfsd",
|
|
43
|
+
"event_ts": "1690670214.666729",
|
|
44
|
+
"channel_type": "channel"
|
|
45
|
+
},
|
|
46
|
+
"retry_num": 0,
|
|
47
|
+
"retry_reason": "",
|
|
48
|
+
"accepts_response_payload": false
|
|
49
|
+
}
|
package/test/stubs.js
CHANGED
|
@@ -239,7 +239,7 @@ module.exports = function() {
|
|
|
239
239
|
}
|
|
240
240
|
};
|
|
241
241
|
stubs.conversationsMock = {
|
|
242
|
-
setTopic: (
|
|
242
|
+
setTopic: ({channel, topic}) => {
|
|
243
243
|
stubs._topic = topic;
|
|
244
244
|
if (stubs.receiveMock.onTopic != null) {
|
|
245
245
|
stubs.receiveMock.onTopic(stubs._topic);
|
|
@@ -247,11 +247,11 @@ module.exports = function() {
|
|
|
247
247
|
return Promise.resolve();
|
|
248
248
|
},
|
|
249
249
|
info: conversationId => {
|
|
250
|
-
if (conversationId === stubs.channel.id) {
|
|
250
|
+
if (conversationId.channel === stubs.channel.id) {
|
|
251
251
|
return Promise.resolve({ok: true, channel: stubs.channel});
|
|
252
|
-
} else if (conversationId === stubs.DM.id) {
|
|
252
|
+
} else if (conversationId.channel === stubs.DM.id) {
|
|
253
253
|
return Promise.resolve({ok: true, channel: stubs.DM});
|
|
254
|
-
} else if (conversationId === 'C789') {
|
|
254
|
+
} else if (conversationId.channel === 'C789') {
|
|
255
255
|
return Promise.resolve();
|
|
256
256
|
} else {
|
|
257
257
|
return Promise.reject(new Error('conversationsMock could not match conversation ID'));
|