The Slack package provides functionality for sending messages to Slack channels using the Slack API
npm install @bondsports/slackThe Slack package provides functionality for sending messages to Slack channels using the Slack API.
To install the Slack package, you can use npm or yarn:
``bash`
npm install @bondsports/slack
or
`bash`
yarn add @bondsports/slack
You can use the Slack Client by importing it into your TypeScript code:
`typescript
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');
}
});
`
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:
`typescript`
const slackClient = new SlackClient('your-api-token', 'production', '#general');
The sendMessage method sends a message to a Slack channel.
`typescript`
async sendMessage(message: string, options?: ISendMessageOptions): Promise
- message: The message to send to the Slack channel.options
- : Optional parameters for sending the message.
Example:
`typescript``
slackClient.sendMessage('Hello, Slack!').then((success) => {
if (success) {
console.log('Message sent successfully');
} else {
console.error('Failed to send message');
}
});