@ingestkorea/client-slack
v0.8.1
Published
INGESTKOREA SDK Slack Client for Node.js.
Downloads
182
Maintainers
Readme
@ingestkorea/client-slack
Description
INGESTKOREA SDK Slack Client for Node.js.
Installing
npm install @ingestkorea/client-slack
Getting Started
Pre-requisites
- Use TypeScript v5.x
- Includes the TypeScript definitions for node.
npm install -D @types/node # save dev mode
Support Methods
- SendMessage
Import
import { SlackClient, SendMessageCommand, SendMessageCommandInput } from "@ingestkorea/client-slack";
Usage
To send a request, you:
- Initiate client with configuration.
- Initiate command with input parameters.
- Call
send
operation on client with command object as input.
// a client can be shared by different commands.
const client = new SlackClient({
credentials: {
token: "YOUR_TOKEN", // required // xoxb-xxxxxxxx
channel: "YOUR_CHANNEL_ID", // required
},
});
SendMessageCommand (Simple)
const params: SendMessageCommandInput = {
text: "Hello client-slack : " + new Date().toISOString(), // required
channel: "YOUR_CHANNEL_ID", // optional // this channelId override SlackClient config
};
const command = new SendMessageCommand(params);
SendMessageCommand (with Blocks)
Support Blocks:
- HeaderBlock
- DividerBlock
- SectionBlock
const params: SendMessageCommandInput = {
text: "hello client-slack : " + new Date().toISOString(),
blocks: [
{ type: "header", text: { type: "plain_text", text: "This is HeaderBlock" } },
{ type: "divider" },
{
type: "section",
text: { type: "mrkdwn", text: "*This is SectionBlock_01*" },
},
{
type: "section",
fields: [
{ type: "mrkdwn", text: "_This is SectionBlock_02-1_" },
{ type: "plain_text", emoji: true, text: "This is SectionBlock_02-2" },
],
},
{
type: "section",
text: { type: "plain_text", text: "This is SectionBlock_03" },
fields: [
{ type: "mrkdwn", text: "_This is SectionBlock_03-1_" },
{ type: "plain_text", emoji: true, text: "This is SectionBlock_03-2" },
],
},
],
};
const command = new SendMessageCommand(params);
Async/await
(async () => {
try {
const data = await client.send(command);
console.dir(data, { depth: 4 });
} catch (err) {
console.log(err);
}
})();
Promises
client
.send(command)
.then((data) => console.dir(data, { depth: 4 }))
.catch((err) => console.log(err));
License
This SDK is distributed under the MIT License, see LICENSE for more information.