@microfox/slack
Version:
This package provides a lightweight, proxy interface to the official Slack Web API, offering a curated set of the most commonly used functions for building Slack integrations. It is designed to be simple, efficient, and easy to integrate into your project
50 lines (35 loc) • 1.25 kB
Markdown
The `WebClient` is the main entry point for interacting with the Slack Web API. You need to instantiate it before you can call any of the API methods.
To create a new `WebClient` instance, you need to provide a Slack API token.
```typescript
import { WebClient } from '@microfox/slack';
// You can get this token from your Slack app settings
const token = process.env.SLACK_BOT_TOKEN;
const web = new WebClient(token);
```
You can also provide a `WebClientOptions` object to configure the client with more advanced settings, such as custom retry logic, TLS configuration, or logging.
```typescript
import { WebClient, LogLevel } from '@microfox/slack';
const token = process.env.SLACK_BOT_TOKEN;
const web = new WebClient(token, {
logLevel: LogLevel.DEBUG
});
```
Once you have a `WebClient` instance, you can use it to call any of the available API methods.
```typescript
(async () => {
try {
// Call the chat.postMessage method
const result = await web.chat.postMessage({
channel: '#general',
text: 'Hello, world!'
});
console.log(`Successfully sent message ${result.ts}`);
} catch (error) {
console.error(error);
}
})();
```