Skip to content

Commit a314c90

Browse files
committed
Create send-slack-action
0 parents  commit a314c90

File tree

7 files changed

+319
-0
lines changed

7 files changed

+319
-0
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
lib

Diff for: README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Send Slack Message
2+
3+
This is a GitHub action to send a Slack message using a Slack bot token.
4+
5+
## Set up
6+
7+
See https://api.slack.com/bot-users for information on setting up and installing a Slack Bot.
8+
9+
## Inputs
10+
11+
- `message`: The Slack message to send
12+
13+
- `slack-token`: The Slack bot user access token
14+
15+
- `channel`: The Slack channel ID to send the message to
16+
17+
## Example Usage
18+
19+
20+
```yaml
21+
- name: Post message
22+
uses: joshmgross/send-slack-message@main
23+
with:
24+
message: 'Hello world'
25+
channel: ${{ secrets.SLACK_CHANNEL_ID }}
26+
slack-token: ${{ secrets.SLACK_BOT_TOKEN }}
27+
```

Diff for: action.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: 'Send Slack Message'
2+
description: 'Sends a slack message'
3+
author: 'joshmgross'
4+
inputs:
5+
message:
6+
required: true
7+
description: 'The Slack message to send'
8+
slack-token:
9+
required: true
10+
description: 'A bot user access token, see https://api.slack.com/bot-users'
11+
channel:
12+
required: true
13+
description: 'The Slack channel ID'
14+
runs:
15+
using: 'node12'
16+
main: 'dist/index.js'

Diff for: package-lock.json

+196
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "send-slack-message",
3+
"version": "1.0.0",
4+
"description": "A GitHub action to send a Slack message",
5+
"main": "dist/index.js",
6+
"private": true,
7+
"scripts": {
8+
"build": "tsc",
9+
"pack": "ncc build src/index.ts"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/joshmgross/send-slack-message.git"
14+
},
15+
"keywords": [
16+
"Actions",
17+
"node"
18+
],
19+
"author": "joshmgross",
20+
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/joshmgross/send-slack-message.git"
23+
},
24+
"homepage": "https://github.com/joshmgross/send-slack-message.git",
25+
"dependencies": {
26+
"@actions/core": "^1.2.6",
27+
"@slack/web-api": "^5.13.0"
28+
},
29+
"devDependencies": {
30+
"@types/node": "^12.12.47",
31+
"@zeit/ncc": "^0.22.3",
32+
"typescript": "^3.9.5"
33+
}
34+
}

Diff for: src/index.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { WebClient } from '@slack/web-api';
2+
import * as core from "@actions/core";
3+
4+
async function run(): Promise<void> {
5+
try {
6+
// Inputs and validation
7+
const slackToken = core.getInput("slack-token", { required: true });
8+
const channel = core.getInput("channel", { required: true });
9+
const message = core.getInput("message", { required: true });
10+
11+
// Send slack message
12+
const slackWebClient = new WebClient(slackToken);
13+
const result = await slackWebClient.chat.postMessage({
14+
text: message,
15+
channel: channel
16+
});
17+
18+
if (result.ok) {
19+
core.info('Slack message sent 🚀')
20+
} else {
21+
core.setFailed(`❌ Unable to send Slack message: ${result.error}`);
22+
}
23+
24+
} catch (error) {
25+
core.setFailed(`❌ Action failed with error: ${error}`)
26+
}
27+
}
28+
29+
run();

Diff for: tsconfig.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
/* Basic Options */
4+
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
5+
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
6+
"outDir": "./lib", /* Redirect output structure to the directory. */
7+
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
8+
9+
/* Strict Type-Checking Options */
10+
"strict": true, /* Enable all strict type-checking options. */
11+
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
12+
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
13+
},
14+
"exclude": ["node_modules"]
15+
}

0 commit comments

Comments
 (0)