
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@slack/client
Advanced tools
Slack Developer Kit - official clients for the Web API, RTM API, and Incoming Webhooks
Visit the full documentation for all the lovely details.
So you want to build a Slack app with Node.js? We've got you covered. This package is aimed at making building Slack apps ridiculously easy. It helps you build on all aspects of the Slack platform, from dropping notifications in channels to fully interactive bots.
Upgrading from version 3? The migration guide has all the information you need to bring your app up to speed.
This package supports Node v6 and higher. It's highly recommended to use the latest LTS version of node, and the documentation is written using syntax and features from that version.
Use npm to install the package and save it to your package.json
:
$ npm install @slack/client
The Slack platform offers several APIs to build apps. Each API delivers part of the capabilities from the platform, with a range of complexity and functionality, so that you can pick the one that fits for your app.
Slack API | Outgoing | Incoming | NPM Package | Documentation |
---|---|---|---|---|
Web API | ⬆️ | ⬜️ | @slack/client | Guide |
RTM API | ⬆️ | ⬇️ | @slack/client | Guide |
Incoming Webhooks | ⬆️ | ⬜️ | @slack/client | Guide |
Events API | ⬜️ | ⬇️ | @slack/events-api | README |
Interactive Messages | ⬜️ | ⬇️ | @slack/interactive-messages | README |
Just starting out? We suggest starting at the Getting Started guide which will walk you through building your first Slack app using Node.js.
Not sure about which APIs are right for your app? Read our helpful blog post that explains and compares the options. If you're still not sure, reach out for help and our community can guide you.
Your app will interact with the Web API through the WebClient
object, which a top level export
from this package. At a minimum, you need to instantiate it with a token. The example below shows
how to post a message into a channel, DM, MPDM, or group. This will require either the
chat:user:write
or chat:bot:write
scopes.
const { WebClient } = require('@slack/client');
// An access token (from your Slack app or custom integration - xoxp, xoxb, or xoxa)
const token = process.env.SLACK_TOKEN;
const web = new WebClient(token);
// This argument can be a channel ID, a DM ID, a MPDM ID, or a group ID
const conversationId = 'C1232456';
// See: https://api.slack.com/methods/chat.postMessage
web.chat.postMessage({ channel: conversationId, text: 'Hello there' })
.then((res) => {
// `res` contains information about the posted message
console.log('Message sent: ', res.ts);
})
.catch(console.error);
The WebClient
object makes it simple to call any of the
over 130 Web API methods. See the
guide for details.
Your app will interact with the RTM API through the RTMClient
object, which is a top level
export from this package. At a minimum, you need to instantiate it with a token, usually a
bot token.
const { RTMClient } = require('@slack/client');
// An access token (from your Slack app or custom integration - usually xoxb)
const token = process.env.SLACK_TOKEN;
// The client is initialized and then started to get an active connection to the platform
const rtm = new RTMClient(token);
rtm.start();
// This argument can be a channel ID, a DM ID, a MPDM ID, or a group ID
const conversationId = 'C1232456';
// The RTM client can send simple string messages
rtm.sendMessage('Hello there', conversationId)
.then((res) => {
// `res` contains information about the posted message
console.log('Message sent: ', res.ts);
})
.catch(console.error);
The RTMClient
object makes it simple to listen for events from a workspace
and send simple messages to a workspace. See the
guide for details.
Incoming webhooks are an easy way to send notifications
to a Slack channel with a minimum of setup. You'll need a webhook URL from a Slack app or a custom
integration to use the IncomingWebhook
class.
const { IncomingWebhook } = require('@slack/client');
const url = process.env.SLACK_WEBHOOK_URL;
const webhook = new IncomingWebhook(url);
// Send simple text to the webhook channel
webhook.send('Hello there', function(err, res) {
if (err) {
console.log('Error:', err);
} else {
console.log('Message sent: ', res);
}
});
If you get stuck, we're here to help. The following are the best ways to get assistance working through your issue:
developers@slack.com
FAQs
Legacy wrapper for official Slack Platform's Web API, RTM API, and Incoming Webhook libraries. Use @slack/web-api, @slack/rtm-api, or @slack/webhook instead.
We found that @slack/client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.