Node Slack SDK

适用于 Node.js 的 Slack 开发人员工具包。「Slack Developer Kit for Node.js」

Github星跟踪图

Node Slack SDK

build-ci


Getting Started

Visit the documentation site for all the lovely details.

This SDK is a collection of single-purpose packages. The packages are aimed at making building Slack apps
easy, performant, secure, and scalable. They can help with just about anything in the Slack platform, from dropping
notifications in channels to fully interactive bots.

The Slack platform offers several APIs to build apps. Each Slack API delivers part of the capabilities from the
platform, so that you can pick just those that fit for your needs. This SDK offers a corresponding package for each of
Slack's APIs. They are small and powerful when used independently, and work seamlessly when used together, too.

Just starting out? The Getting Started tutorial will
walk you through building your first Slack app using Node.js.

Slack API What its for NPM Package
Web API Send data to or query data from Slack using any of over 220 methods. @slack/web-api
OAuth Setup the authentication flow using V2 OAuth for Slack apps as well as V1 OAuth for classic Slack apps. @slack/oauth
Incoming Webhooks Send notifications to a single channel which the user picks on installation. @slack/webhook
Socket Mode Listen for incoming messages and a limited set of events happening in Slack, using WebSocket. @slack/socket-mode

Not sure about which APIs are right for your app? Read our blog
post
that explains the options.
If you're still not sure, reach out for help and our community can guide you.

Deprecation Notice

@slack/events-api and @slack/interactive-messages officially reached EOL on May 31st, 2021. Development has fully stopped for these packages and all remaining open issues and pull requests have been closed.

At this time, we recommend migrating to Bolt for JavaScript, a framework that offers all of the functionality available in those packages (and more). To help with that process, we've provided some migration samples for those looking to convert their existing apps.

Installation

Use your favorite package manager to install any of the packages and save to your package.json:

$ npm install @slack/web-api @slack/socket-mode

# Or, if you prefer yarn
$ yarn add @slack/web-api @slack/socket-mode

Usage

The following examples summarize the most common ways to use this package. There's also a Getting Started
tutorial
that's perfect for just starting out, and each
package's documentation, linked in the table above.

Posting a message with Web API

Your app will interact with the Web API through the WebClient object, which is an export from @slack/web-api. You
typically instantiate a client with a token you received from Slack. The example below shows how to post a message into
a channel, DM, MPDM, or group. The WebClient object makes it simple to call any of the over 130 Web API
methods
.

const { WebClient } = require('@slack/web-api');

// An access token (from your Slack app or custom integration - xoxp, xoxb)
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';

(async () => {
  // See: https://api.slack.com/methods/chat.postMessage
  const res = await web.chat.postMessage({ channel: conversationId, text: 'Hello there' });

  // `res` contains information about the posted message
  console.log('Message sent: ', res.ts);
})();

Note: To use the example above, the token is required to have either the bot, chat:user:write, or
chat:bot:write scopes.

Tip: Use the Block Kit Builder for a playground
where you can prototype your message's look and feel.

Listening for an event with the Events API

Refer to Bolt for JavaScript document pages.

Responding to interactive messages

Refer to Bolt for JavaScript document pages.

Using Socket Mode

Refer to the module document page and Bolt for JavaScript document page.

Requirements

This package supports Node v14 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.

Getting Help

If you get stuck, we're here to help. The following are the best ways to get assistance working through your issue:

  • Issue Tracker for questions, feature requests, bug reports and
    general discussion related to these packages. Try searching before you create a new issue.
  • Email us in Slack developer support: developers@slack.com

主要指标

概览
名称与所有者slackapi/node-slack-sdk
主编程语言TypeScript
编程语言JavaScript (语言数: 4)
平台
许可证MIT License
所有者活动
创建于2014-03-25 21:56:50
推送于2025-04-17 18:55:50
最后一次提交
发布数351
最新版本名称@slack/web-api@7.10.1-featWorkObjectsBeta.1 (发布于 )
第一版名称1.0.1 (发布于 2014-05-13 13:41:24)
用户参与
星数3.3k
关注者数121
派生数674
提交数2.6k
已启用问题?
问题数938
打开的问题数32
拉请求数1083
打开的拉请求数10
关闭的拉请求数197
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?