0.3.0 • Published 6 years ago

slack-report v0.3.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Slack Report

XO code style license

Why Slack Report?

Slack is the most popular collaboration tool. However, when it comes to message formatting, Slack provides very limited features. This makes it difficult to share monitored metrics or analyzed statistics in a structured format.

Slack Report gives you a better way to do this by making use of message attachments. Especially, the API based on Builder Pattern allows you to write clean and easy-to-read code.

Installation

You can install Slack Report through npm:

npm install slack-report --save

Usage Example

Builder

You can set up the report by using method chain. You should call title and metric methods at least once. Other fields are optional. Don't forget to call the build method at the end of the chain. You can find an example here.

const ReportBuilder = require('slack-report');

const report = new ReportBuilder()
  .title('Daily User Report')
  .titleLink('https://fabric.io')
  .description('This is a sample report made by Slack Report.')
  .metric(dau, {
    title: 'DAU',
    description: 'This is a sample table.',
    timestamp: Date.now(),
    author: 'Delightroom'
  })
  .build();

Preview

Before publishing it to Slack, you can preview the message . The preview method prints out an url. Just copy and paste the link to your browser.

report.preview();

Publish

In order to publish the report, you need to call the publish method with slack webhook url, which starts with https://hooks.slack.com/services. The method returns axios object so I would recommend use await operator. For the detailed info about slack webhook, please refer to this document.

const slackWebhookUrl = 'https://api.slack.com/incoming-webhooks/...';
await report.publish(slackWehookUrl);

License

This project is licensed under the MIT License - see the LICENSE file for details

0.3.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago