UNPKG

1.05 kBPlain TextView Raw
1#!/usr/bin/env node
2
3import * as yargs from 'yargs'
4import { SlackService } from '..'
5import { runScript } from '../script'
6
7runScript(async () => {
8 const {
9 channel,
10 msg,
11 username,
12 emoji,
13 webhook: webhookUrl,
14 } = yargs.options({
15 channel: {
16 type: 'string',
17 demandOption: true,
18 },
19 msg: {
20 type: 'string',
21 demandOption: true,
22 },
23 username: {
24 type: 'string',
25 default: 'bot',
26 },
27 emoji: {
28 type: 'string',
29 default: ':spider_web:',
30 },
31 webhook: {
32 type: 'string',
33 default: process.env.SLACK_WEBHOOK_URL,
34 },
35 }).argv
36
37 if (!webhookUrl) {
38 console.log(`Slack webhook is required, either via env.SLACK_WEBHOOK_URL or --webhook`)
39 process.exit(1)
40 }
41
42 const slack = new SlackService({
43 webhookUrl,
44 })
45
46 await slack.send({
47 items: msg,
48 channel,
49 username,
50 icon_emoji: emoji,
51 throwOnError: true,
52 })
53})
54
55declare global {
56 namespace NodeJS {
57 interface ProcessEnv {
58 SLACK_WEBHOOK_URL?: string
59 }
60 }
61}