blob: 6613df569ca9279ebd46c7b9072804cd3a05a04b [file] [log] [blame]
Marc Kupietzea6dab22022-01-15 18:29:27 +01001#!/usr/bin/env node
2const { WebClient } = require('@slack/web-api');
3const { Command } = require('commander');
4const program = new Command();
5
6program
7 .arguments('<message>')
8 .description( 'Sends a message to a slack channel.')
9 .option('-d, --debug', 'output extra debugging')
10 .option('-c, --channel <channel_id>', 'send message to slack channel', "dereko")
11 .parse(process.argv);
12
13const options = program.opts();
14if (options.debug) console.log(options);
15
16// An access token (from your Slack app or custom integration - xoxp, xoxb)
17const token = process.env.SLACK_TOKEN;
18
19const web = new WebClient(token);
20const conversationId = options.channel;
21
22(async () => {
23 // See: https://api.slack.com/methods/chat.postMessage
24 const res = await web.chat.postMessage({ channel: conversationId, text: program.args[0] });
25
26 // `res` contains information about the posted message
27 console.log('Message sent: ', res.ts);
28})();