百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

slack-bot-api

> 编程语言
开源

:rocket: 简单的方法来控制您的 Slack 机器人

1.3K stars0 点赞1 次浏览
访问官网GitHub

工具介绍

:rocket: 简单的方法来控制您的 Slack 机器人

SlackBots.js

This is Node.js library for easy operation with Slack API.

It also exposes all opportunities of Slack's Real Time Messaging API.

Installation

bash
npm install slackbots

Params

  • token (string) the slack token
  • name (string) the name of the bot
  • disconnect (boolean, defaults: false) whether to open websocket connection to listen to incoming messages, set to true for one time use

Events

  • start - event fired, when Real Time Messaging API is started (via websocket),
  • message - event fired, when something happens in Slack. Description of all events here,
  • open - websocket connection is open and ready to communicate,
  • close - websocket connection is closed.
  • error - an error occurred while connecting to Slack

Methods

  • getChannels() (return: promise) - returns a list of all channels in the team,
  • getGroups() (return: promise) - returns a list of all groups in the team,
  • getUsers() (return: promise) - returns a list of all users in the team,
  • getImChannels() (return: promise) - returns a list of bots direct message channels in the team,
  • getChannel(name) (return: promise) - gets channel by name,
  • getGroup(name) (return: promise) - gets group by name,
  • getUser(name) (return: promise) - gets user by name,
  • getUserByEmail(name) (return: promise) - gets user by name,
  • getChannelId(name) (return: promise) - gets channel ID by name,
  • getGroupId(name) (return: promise) - gets group ID by name,
  • getUserId(name) (return: promise) - gets user ID by name,
  • getChatId(name) (return: promise) - it returns or opens and returns a direct message channel ID,
  • postEphemeral(id, user, text, params) (return: promise) - posts an ephemeral message to channel and user by ID,
  • postMessage(id, text, params) (return: promise) - posts a message to channel | group | user by ID,
  • updateMessage(channelId, timestamp, text, params) (return: promise) - updates a message in a channel,
  • postTo(name, message [, params, callback]) (return: promise) - posts a message to channel | group | user by name,
  • postMessageToUser(name, message [, params, callback]) (return: promise) - posts a direct message by user name,
  • postMessageToGroup(name, message [, params, callback]) (return: promise) - posts a message to private group by name,
  • postMessageToChannel(name, message [, params, callback]) (return: promise) - posts a message to channel by name.
  • openIm(userId) (return: promise) - opens a direct message channel with another member in the team

Usage

…

PROFIT!

javascript
/**
 * @param {object} data
 */
bot.on('message', function(data) {
    // all ingoing events https://api.slack.com/rtm
    console.log(data);
});

Response Handler

The simplest way for handling response is callback function, which is specified as a last argument:

javascript
bot.postMessageToUser('user1', 'hi', function(data) {/* ... */});
bot.postMessageToUser('user1', 'hi', params, function(data) {/* ... */});

But also you can use promises.

Error:

javascript
bot.postMessageToUser('user1', 'hi').fail(function(data) {
    //data = { ok: false, error: 'user_not_found' }
})

Success:

javascript
bot.postMessageToUser('user', 'hi').then(function(data) {
    // ...
})

Error and Success:

javascript
bot.postMessageToUser('user', 'hi').always(function(data) {
    // ...
})

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言