Skip to content

Commit

Permalink
Create send-slack-action
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmgross committed Nov 9, 2020
0 parents commit a314c90
Show file tree
Hide file tree
Showing 7 changed files with 319 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
lib
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Send Slack Message

This comment has been minimized.

Copy link
@bambajabbi

bambajabbi Apr 10, 2022

this make me confeuse

This comment has been minimized.

Copy link
@bambajabbi

bambajabbi Apr 10, 2022

i am living in the Gambia, we are not Deverlop about website, i need help to teach me more and more


This is a GitHub action to send a Slack message using a Slack bot token.

## Set up

See https://api.slack.com/bot-users for information on setting up and installing a Slack Bot.

## Inputs

- `message`: The Slack message to send

- `slack-token`: The Slack bot user access token

- `channel`: The Slack channel ID to send the message to

## Example Usage


```yaml
- name: Post message
uses: joshmgross/send-slack-message@main
with:
message: 'Hello world'
channel: ${{ secrets.SLACK_CHANNEL_ID }}
slack-token: ${{ secrets.SLACK_BOT_TOKEN }}
```
16 changes: 16 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: 'Send Slack Message'
description: 'Sends a slack message'
author: 'joshmgross'
inputs:
message:
required: true
description: 'The Slack message to send'
slack-token:
required: true
description: 'A bot user access token, see https://api.slack.com/bot-users'
channel:
required: true
description: 'The Slack channel ID'
runs:
using: 'node12'
main: 'dist/index.js'
196 changes: 196 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "send-slack-message",
"version": "1.0.0",
"description": "A GitHub action to send a Slack message",
"main": "dist/index.js",
"private": true,
"scripts": {
"build": "tsc",
"pack": "ncc build src/index.ts"
},
"repository": {
"type": "git",
"url": "git+https://github.com/joshmgross/send-slack-message.git"
},
"keywords": [
"Actions",
"node"
],
"author": "joshmgross",
"license": "MIT",
"bugs": {
"url": "https://github.com/joshmgross/send-slack-message.git"
},
"homepage": "https://github.com/joshmgross/send-slack-message.git",
"dependencies": {
"@actions/core": "^1.2.6",
"@slack/web-api": "^5.13.0"
},
"devDependencies": {
"@types/node": "^12.12.47",
"@zeit/ncc": "^0.22.3",
"typescript": "^3.9.5"
}
}
29 changes: 29 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { WebClient } from '@slack/web-api';
import * as core from "@actions/core";

async function run(): Promise<void> {
try {
// Inputs and validation
const slackToken = core.getInput("slack-token", { required: true });
const channel = core.getInput("channel", { required: true });
const message = core.getInput("message", { required: true });

// Send slack message
const slackWebClient = new WebClient(slackToken);
const result = await slackWebClient.chat.postMessage({
text: message,
channel: channel
});

if (result.ok) {
core.info('Slack message sent 🚀')
} else {
core.setFailed(`❌ Unable to send Slack message: ${result.error}`);
}

} catch (error) {
core.setFailed(`❌ Action failed with error: ${error}`)
}
}

run();
15 changes: 15 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
/* Basic Options */
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"outDir": "./lib", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */

/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
},
"exclude": ["node_modules"]
}

0 comments on commit a314c90

Please sign in to comment.