npm.io
0.1.2 • Published 4 years ago

slack-friends

Licence
MIT
Version
0.1.2
Deps
4
Size
16 kB
Vulns
22
Weekly
0
Stars
9

slack-friends

Make it easy to send to Slack from your application

Installation

💡 npm install slack-friends

How to get bot token

  1. https://api.slack.com/
  2. Your apps
  3. Create New App
  4. OAuth & Permissions - Bot User OAuth Token
Bot Token scopes 
  * channels:join
  * channels:read
  * chat:write

Usage

import { SlackFriends } from "slack-friends";

const slack = new SlackFriends({
  token: "Your Bot Token",
  channel: "Channel Name",
});
  • token : Please refer to 'How to get bot token' to issue the token
  • channel : write channel name eg) #channelName -> remove # and only use channelName
Common Message
slack.send("hello world");
Custom Message

Please refer to the detail to build Custom Message https://app.slack.com/block-kit-builder/

const customMessage = {
  "blocks": [
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "This is a section block with a button."
      },
      "accessory": {
        "type": "button",
        "text": {
          "type": "plain_text",
          "text": "Click Me",
          "emoji": true
        },
        "value": "click_me_123",
        "action_id": "button-action"
      }
    }
  ]
}

slack.send(customMessage);
Cron Message
slack.cron("* * * * *", "hello World");
 # ┌────────────── second (optional)
 # │ ┌──────────── minute
 # │ │ ┌────────── hour
 # │ │ │ ┌──────── day of month
 # │ │ │ │ ┌────── month
 # │ │ │ │ │ ┌──── day of week
 # │ │ │ │ │ │
 # │ │ │ │ │ │
 # * * * * * *

This is a quick reference to cron syntax and also shows the options supported by node-cron.

Schedule Message
slack.time(new Date("2022-06-18T05:17:00Z"), "hello World");
MIT

Keywords