Add node script that sends a message to a slack channel
Change-Id: I7060bdbb3d73220e09465aac5051a49759b1ee3b
diff --git a/bin/slack.js b/bin/slack.js
new file mode 100755
index 0000000..6613df5
--- /dev/null
+++ b/bin/slack.js
@@ -0,0 +1,28 @@
+#!/usr/bin/env node
+const { WebClient } = require('@slack/web-api');
+const { Command } = require('commander');
+const program = new Command();
+
+program
+ .arguments('<message>')
+ .description( 'Sends a message to a slack channel.')
+ .option('-d, --debug', 'output extra debugging')
+ .option('-c, --channel <channel_id>', 'send message to slack channel', "dereko")
+ .parse(process.argv);
+
+const options = program.opts();
+if (options.debug) console.log(options);
+
+// An access token (from your Slack app or custom integration - xoxp, xoxb)
+const token = process.env.SLACK_TOKEN;
+
+const web = new WebClient(token);
+const conversationId = options.channel;
+
+(async () => {
+ // See: https://api.slack.com/methods/chat.postMessage
+ const res = await web.chat.postMessage({ channel: conversationId, text: program.args[0] });
+
+ // `res` contains information about the posted message
+ console.log('Message sent: ', res.ts);
+})();