@certik/skynet 0.8.9 → 0.8.10
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/CHANGELOG.md +1 -1
- package/package.json +1 -1
- package/slack.js +25 -5
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/slack.js
CHANGED
|
@@ -19,13 +19,26 @@ function getClient() {
|
|
|
19
19
|
async function findConversation(client, name) {
|
|
20
20
|
const { conversations } = client;
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
let channels = [];
|
|
23
|
+
|
|
23
24
|
let result = await conversations.list({
|
|
24
|
-
types: "public_channel,private_channel
|
|
25
|
+
types: "public_channel,private_channel",
|
|
25
26
|
limit: 1000,
|
|
26
27
|
});
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
channels = channels.concat(result.channels);
|
|
30
|
+
|
|
31
|
+
while (result.response_metadata.next_cursor) {
|
|
32
|
+
result = await conversations.list({
|
|
33
|
+
types: "public_channel,private_channel",
|
|
34
|
+
cursor: result.response_metadata.next_cursor,
|
|
35
|
+
limit: 1000,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
channels = channels.concat(result.channels);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
for (const channel of channels) {
|
|
29
42
|
if (channel.name === name) {
|
|
30
43
|
const conversationId = channel.id;
|
|
31
44
|
|
|
@@ -42,6 +55,12 @@ async function postMessage(channel, message, verbose) {
|
|
|
42
55
|
|
|
43
56
|
const conversationId = await findConversation(client, channel);
|
|
44
57
|
|
|
58
|
+
if (!conversationId) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`cannot find slack public/private channel: ${channel}, you may have to invite the @CertiK Skynet bot to the channel`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
45
64
|
let post = {};
|
|
46
65
|
|
|
47
66
|
if (typeof message === "string") {
|
|
@@ -59,9 +78,10 @@ async function postMessage(channel, message, verbose) {
|
|
|
59
78
|
...post,
|
|
60
79
|
});
|
|
61
80
|
} catch (error) {
|
|
62
|
-
// no blocking
|
|
63
81
|
console.error("failed to post slack message", error);
|
|
82
|
+
|
|
83
|
+
throw error;
|
|
64
84
|
}
|
|
65
85
|
}
|
|
66
86
|
|
|
67
|
-
module.exports = { postMessage };
|
|
87
|
+
module.exports = { getClient, findConversation, postMessage };
|