1.2.0 • Published 4 years ago
@d0whc3r/moleculer-slack v1.2.0

moleculer-slack 
Send Messages to Slack API.
Install
$ npm install @d0whc3r/moleculer-slack --saveUsage
This addon reads the
SLACK_TOKENandSLACK_CHANNELenvironment variables, but all are optional
const { ServiceBroker } = require("moleculer");
const { SlackService } = require("@d0whc3r/moleculer-slack");
// Create broker
const broker = new ServiceBroker({ logger: console });
// Load my service
broker.createService({
    name: "slack",
    mixins: [SlackService]
});
// Start server
broker.start().then(() => {
  broker
    .call('slack.send', { message: 'testing!' })
    .then((response) => {
      console.log('Slack message response', response);
    })
    .catch(console.error);
});Settings
| Property | Type | Default | Description | 
|---|---|---|---|
slackToken | String | SLACK_TOKEN env variable | Slack API Token. Visit your Slack App dashboard's main page. Click "Create App, Generate Token", then copy and paste your "API TOKEN" here. | 
slackChannel | String | SLACK_CHANNEL env variable | Slack API Token. Visit your Slack App dashboard's main page. Add incoming webhook and create/select a channel, then copy and paste here. | 
Actions
send
Send a Slack Message
Parameters
| Property | Type | Default | Description | 
|---|---|---|---|
message | String | required | Message text | 
channel | String | null | (optional) Channel name, can be array or string, if it is a string it could be multiple channels separated by commas | 
token | String | null | (optional) Token to use | 
Results
Type: Promise<WebAPICallResult[]>
Methods
sendMessageToChannels
Send a slack message to one or more channels
Parameters
| Property | Type | Default | Description | 
|---|---|---|---|
message | String | - | Body of the message | 
channel | String or Array<String> | - | Channel or channels name/s | 
Results
Type: Promise<WebAPICallResult>[]
Test
$ npm testLicense
The project is available under the MIT license.