@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.
Files changed (3) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/package.json +1 -1
  3. package/slack.js +25 -5
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Changelog
2
2
 
3
- ## 0.8.9
3
+ ## 0.8.10
4
4
 
5
5
  - Improved `postMessage` in `slack` library to support private channels
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certik/skynet",
3
- "version": "0.8.9",
3
+ "version": "0.8.10",
4
4
  "description": "Skynet Shared JS library",
5
5
  "main": "index.js",
6
6
  "author": "CertiK Engineering",
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
- // Call the conversations.list method using the built-in WebClient
22
+ let channels = [];
23
+
23
24
  let result = await conversations.list({
24
- types: "public_channel,private_channel,mpim,im",
25
+ types: "public_channel,private_channel",
25
26
  limit: 1000,
26
27
  });
27
28
 
28
- for (const channel of result.channels) {
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 };