0.1.2 ā¢ Published 2 years ago
slack-friends v0.1.2
slack-friends
Make it easy to send to Slack from your application
Installation
š” npm install slack-friends
How to get bot token
- https://api.slack.com/
- Your apps
- Create New App
- 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 tokenchannel
: write channel name eg) #channelName -> remove#
and only usechannelName
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");