Messaging API client for Slack
npm i --save messaging-api-slack
or
yarn add messaging-api-slack
Get your webhook url by adding a Incoming Webhooks integreation to your team or setup Incoming Webhooks function to your app.
import { SlackClient } from 'messaging-api-slack';
// get webhook URL by adding a Incoming Webhook integration to your team.
// https://my.slack.com/services/new/incoming-webhook/
const client = SlackClient.connect('https://hooks.slack.com/services/XXXXXXXX/YYYYYYYY/zzzzzZZZZZ');
All methods return a Promise.
client.sendRawBody({ text: 'Hello!' });
client.sendText('Hello!');
client.sendAttachments([
{
fallback: 'some text',
pretext: 'some pretext',
color: 'good',
fields: [
{
title: 'aaa',
value: 'bbb',
short: false,
},
],
},
{
fallback: 'some other text',
pretext: 'some pther pretext',
color: '#FF0000',
fields: [
{
title: 'ccc',
value: 'ddd',
short: false,
},
],
}
]);
client.sendAttachment({
fallback: 'some text',
pretext: 'some pretext',
color: 'good',
fields: [
{
title: 'aaa',
value: 'bbb',
short: false,
},
],
});