messaging-api-slack
Messaging API client for Slack
Table of Contents
Installation
npm i --save messaging-api-slack
or
yarn add messaging-api-slack
Usage
Initialize
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';
const client = SlackClient.connect('https://hooks.slack.com/services/XXXXXXXX/YYYYYYYY/zzzzzZZZZZ');
API Reference
All methods return a Promise.
Send API
Official docs
sendRawBody(body)
client.sendRawBody({ text: 'Hello!' });
sendText(text)
client.sendText('Hello!');
sendAttachments(attachments)
Official docs
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,
},
],
}
]);
sendAttachment(attachment)
Official docs
client.sendAttachment({
fallback: 'some text',
pretext: 'some pretext',
color: 'good',
fields: [
{
title: 'aaa',
value: 'bbb',
short: false,
},
],
});