@bondsports/slack
v1.0.2
Published
The Slack package provides functionality for sending messages to Slack channels using the Slack API
Downloads
1,627
Maintainers
Keywords
Readme
Slack
The Slack package provides functionality for sending messages to Slack channels using the Slack API.
Installation
To install the Slack package, you can use npm or yarn:
npm install @bondsports/slack
or
yarn add @bondsports/slack
Usage
You can use the Slack Client by importing it into your TypeScript code:
import { SlackClient } from '@bondsports/slack';
// Initialize SlackClient with your Slack API token, environment, and default channel
const slackClient = new SlackClient('your-api-token', 'production', '#general');
// Send a message to Slack
slackClient.sendMessage('Hello, Slack!').then((success) => {
if (success) {
console.log('Message sent successfully');
} else {
console.error('Failed to send message');
}
});
Constructor
The SlackClient
constructor takes three parameters:
token
: A string representing your Slack API token.environment
: A string representing the environment in which the client operates.defaultChannel
: A string representing the default channel to which messages will be sent.
Example:
const slackClient = new SlackClient('your-api-token', 'production', '#general');
Methods
sendMessage
The sendMessage
method sends a message to a Slack channel.
async sendMessage(message: string, options?: ISendMessageOptions): Promise<boolean>
message
: The message to send to the Slack channel.options
: Optional parameters for sending the message.
Example:
slackClient.sendMessage('Hello, Slack!').then((success) => {
if (success) {
console.log('Message sent successfully');
} else {
console.error('Failed to send message');
}
});