• Stars
    star
    2,736
  • Rank 16,637 (Top 0.4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A framework to build Slack apps using JavaScript

Bolt Bolt logo for JavaScript

codecov Node.js CI

A JavaScript framework to build Slack apps in a flash with the latest platform features. Read the getting started guide to set-up and run your first Bolt app.

Read the documentation to explore the basic and advanced concepts of Bolt for JavaScript.

Setup

npm install @slack/bolt

Initialization

Create an app by calling the constructor, which is a top-level export.

const { App } = require('@slack/bolt');

const app = new App({
  signingSecret: process.env.SLACK_SIGNING_SECRET,
  token: process.env.SLACK_BOT_TOKEN,
});

/* Add functionality here */

(async () => {
  // Start the app
  await app.start(process.env.PORT || 3000);

  console.log('โšก๏ธ Bolt app is running!');
})();

Listening for events

The Slack Request URL for a Bolt app must have the path set to /slack/events.
For example: https://my-slack-app.example.com/slack/events.
Otherwise, all incoming requests from Slack won't be handled.

Apps typically react to a collection of incoming events, which can correspond Events API events, actions, shortcuts, slash commands or options requests. For each type of request, there's a method to build a listener function.

// Listen for an event from the Events API
app.event(eventType, fn);

// Convenience method to listen to only `message` events using a string or RegExp
app.message([pattern ,] fn);

// Listen for an action from a Block Kit element (buttons, select menus, date pickers, etc)
app.action(actionId, fn);

// Listen for dialog submissions
app.action({ callback_id: callbackId }, fn);

// Listen for a global or message shortcuts
app.shortcut(callbackId, fn);

// Listen for slash commands
app.command(commandName, fn);

// Listen for view_submission modal events
app.view(callbackId, fn);

// Listen for options requests (from select menus with an external data source)
app.options(actionId, fn);

Making things happen

Most of the app's functionality will be inside listener functions (the fn parameters above). These functions are called with a set of arguments.

Argument Description
payload Contents of the incoming event. The payload structure depends on the listener. For example, for an Events API event, payload will be the event type structure. For a block action, it will be the action from within the actions array. The payload object is also accessible via the alias corresponding to the listener (message, event, action, shortcut, view, command, or options). For example, if you were building a message() listener, you could use the payload and message arguments interchangeably. An easy way to understand what's in a payload is to log it, or use TypeScript.
say Function to send a message to the channel associated with the incoming event. This argument is only available when the listener is triggered for events that contain a channel_id (the most common being message events). say accepts simple strings (for plain-text messages) and objects (for messages containing blocks). say returns a promise that will resolve with a chat.postMessage response.
ack Function that must be called to acknowledge that an incoming event was received by your app. ack exists for all actions, shortcuts, view, slash command and options requests. ack returns a promise that resolves when complete. Read more in Acknowledging events
client Web API client that uses the token associated with that event. For single-workspace installations, the token is provided to the constructor. For multi-workspace installations, the token is returned by the authorize function.
respond Function that responds to an incoming event if it contains a response_url (actions, shortcuts, view submissions, and slash commands). respond returns a promise that resolves with the results of responding using the response_url.
context Event context. This object contains data about the event and the app, such as the botId. Middleware can add additional context before the event is passed to listeners.
body Object that contains the entire body of the request (superset of payload). Some accessory data is only available outside of the payload (such as trigger_id and authorizations).

The arguments are grouped into properties of one object, so that it's easier to pick just the ones your listener needs (using object destructuring). Here is an example where the app sends a simple response, so there's no need for most of these arguments:

// Reverse all messages the app can hear
app.message(async ({ message, say }) => {
  // Filter out message events with subtypes (see https://api.slack.com/events/message)
  if (message.subtype === undefined || message.subtype === 'bot_message') {
    const reversedText = [...message.text].reverse().join("");
    await say(reversedText);
  }
});

Calling the Web API

In addition to the client property passed to listeners, each app has a top-level client that can be used to call methods. Unlike the client passed to listeners, the top-level client must be passed a token. Read the documentation for more details.

Acknowledging events

Some types of events need to be acknowledged in order to ensure a consistent user experience inside the Slack client (web, mobile, and desktop apps). This includes all action, shortcut, view, command, and options requests. Listeners for these events need to call the ack() function, which is passed in as an argument.

In general, the Slack platform expects an acknowledgement within 3 seconds, so listeners should call this function as soon as possible.

Depending on the type of incoming event a listener is meant for, ack() should be called with a parameter:

  • Block actions, global shortcuts, and message shortcuts: Call ack() with no parameters.

  • View submissions: Call ack() with no parameters or with a response action.

  • Options requests: Call ack() with an object containing the options for the user to see.

  • Legacy message button clicks, menu selections, and slash commands: Either call ack() with no parameters, a string to to update the message with a simple message, or an object to replace it with a complex message. Replacing the message to remove the interactive elements is a best practice for any action that should only be performed once.

  • Events API events do not need an ack() function since they are automatically acknowledged by your app.

Getting Help

The documentation has more information on basic and advanced concepts for Bolt for JavaScript.

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

  • Issue Tracker for questions, bug reports, feature requests, and general discussion related to Bolt for JavaScript. Try searching for an existing issue before creating a new one.
  • Email our developer support team: [email protected]

Contributing

We welcome contributions from everyone! Please check out our Contributor's Guide for how to contribute in a helpful and collaborative way.

More Repositories

1

python-slack-sdk

Slack Developer Kit for Python
Python
3,840
star
2

node-slack-sdk

Slack Developer Kit for Node.js
TypeScript
3,270
star
3

hubot-slack

Slack Developer Kit for Hubot
CoffeeScript
2,300
star
4

bolt-python

A framework to build Slack apps using Python
Python
1,053
star
5

slack-github-action

Send data into Slack using this GitHub Action!
JavaScript
953
star
6

python-rtmbot

A framework for receiving and interacting with events from Slack's RTM API
Python
680
star
7

java-slack-sdk

Slack Developer Kit (including Bolt for Java) for any JVM language
Java
573
star
8

python-slack-events-api

Slack Events API adapter for Python (Flask required)
Python
342
star
9

Slack-Python-Onboarding-Tutorial

a simple python onboarding bot and tutorial for Slack
Python
251
star
10

slack-api-specs

Open API specifications for platform products by Slack
220
star
11

steno

๐Ÿ“ผ Slack app testing companion - Record and Replay your HTTP requests, both incoming and outgoing
TypeScript
184
star
12

deno-slack-sdk

SDK for building Run on Slack apps using Deno
TypeScript
160
star
13

template-slash-command-and-dialogs

Sample Slack app that uses a Slash Command and interactive message to create helpdesk tickets
JavaScript
141
star
14

node-slack-interactive-messages

Slack Buttons, Menus, and Dialogs made simpler for Node
JavaScript
133
star
15

build-this-bot-workshop

Learn how to build a bot on Slack using Python
127
star
16

reacjilator

A translation bot that translates a message when a user reacted with an emoji ๐Ÿ‡จ๐Ÿ‡ณ ๐Ÿ‡ฎ๐Ÿ‡น ๐Ÿ‡น๐Ÿ‡ญ ๐Ÿ‡ซ๐Ÿ‡ท ๐Ÿ‡ฏ๐Ÿ‡ต ๐Ÿ‡ฎ๐Ÿ‡ณ ๐Ÿ‡บ๐Ÿ‡ธ ๐Ÿ‡ง๐Ÿ‡ฌ ๐Ÿ‡น๐Ÿ‡ผ ๐Ÿ‡ฆ๐Ÿ‡ช ๐Ÿ‡ฐ๐Ÿ‡ท
JavaScript
110
star
17

onboarding-example

A demonstration of how to build an onboarding app using Slack's Events API
JavaScript
99
star
18

node-tasks-app

Tasks App is a sample Task Management app built on the Slack Platform.
JavaScript
98
star
19

python-message-menu-example

A tutorial for adding Slack message menus to your Python app
Python
97
star
20

slack-platform-assets

Images, templates, and Sketch files to aid designing and presenting your Slack apps
94
star
21

node-slack-events-api

Slack Events API for Node
JavaScript
93
star
22

sample-message-menus-node

An example Slack app that demonstrates use of message menus
JavaScript
91
star
23

python-dialog-example

An example app to demonstrate Slack dialogs
Python
77
star
24

template-announcement-approvals

Sample Slack app that uses the Events API and interactive message to implement an approvals workflow
JavaScript
74
star
25

Slack-Ruby-Onboarding-Tutorial

An example Slack bot written in Ruby
Ruby
64
star
26

bolt-js-getting-started-app

Getting Started Slack app using โšก๏ธ Bolt for JavaScript
JavaScript
54
star
27

sample-app-unfurls

An example Slack app that demonstrates use of App Unfurls
JavaScript
45
star
28

app-interaction-patterns

A collection of common workflows and interaction patterns for Slack apps.
41
star
29

oauth-tutorial

Slack OAuth setup tutorial using a simple slash command bot
JavaScript
39
star
30

template-triage-bot

Triage Channel Stats w/ Bolt for JS & Shortcuts โšก๏ธ
JavaScript
39
star
31

template-actionable-notifications

Sample Slack app to illustrate how incoming webhooks and interactive messages can be used to build a helpdesk integration
JavaScript
35
star
32

deno-slack-api

Slack API Client for Deno Run on Slack projects
TypeScript
35
star
33

template-terms-of-service

Sample Slack app that uses the Events API and interactive messages to send new users a Terms of Service or welcome message
JavaScript
35
star
34

app-directory-assets

A collection of design assets to help build an app directory submission
34
star
35

template-incident-management

A sample of managing incidents via Slack
TypeScript
34
star
36

template-channel-webhooks

Sample Slack app that uses a Bot to create per-channel webhooks
JavaScript
31
star
37

TalkBot

Building a Twilio-powered Slack bot with Node.js
JavaScript
30
star
38

python-slack-discovery-sdk

This project aims to make using Slack's Discovery APIs easier.
Python
28
star
39

template-channel-naming

Sample Slack app that uses the Events API and interactive message to help enforce channel naming conventions
JavaScript
28
star
40

workflow-powerups

TypeScript
27
star
41

template-action-and-dialog

A sample Slack app "ClipIt", which allows user to clip a message using a message action
JavaScript
27
star
42

sample-message-menus-ruby

An example Slack app in Ruby that demonstrates use of message menus
Ruby
23
star
43

definition-app

A Slack app for storing and accessing company specific phrases
TypeScript
23
star
44

template-account-binding

A sample Slack app that shows you how to bind a Slack user to a user on another system
JavaScript
22
star
45

admin_app_management

Sample application to manage your applications within a Slack organization
TypeScript
20
star
46

pycon-2018

Sample app for Pycon 2018 Slack app workshop
Python
15
star
47

slack-reporting-tool

A Slack app to help administer workspaces by letting team members report offensive messages
TypeScript
15
star
48

deno-slack-runtime

Helper library for running a Run on Slack Deno function
TypeScript
13
star
49

pycon-2019

Pycon 2019 Workshop
Python
12
star
50

deno-slack-hooks

Helper library implementing the contract between the Slack CLI and Slack application SDKs
TypeScript
11
star
51

python-link-button-example

An example app using Slack link buttons and deep links
Python
10
star
52

deno-slack-hub

Connectors used to build coded workflows for Run on Slack apps using Deno
TypeScript
9
star
53

deno-slack-builder

Library for building a Run on Slack Deno project.
TypeScript
9
star
54

bolt-examples-aws-re-invent-2020

A collection of examples to get started with deploying modern โšก๏ธ Slack apps to AWS Lambda and Amazon Lightsail containers
Java
8
star
55

WeAreDevs

WeAreDevelopers Slack Workshop
Python
7
star
56

manifest-schema

Provide JSON schemas that define Slack's manifest.json file
Python
6
star
57

python-slack-hooks

Helper library implementing the contract between the Slack CLI and Bolt for Python
Python
5
star
58

template-message-linking

Sample Slack APP that uses the Events API to link to a conversation happening in one channel to another
JavaScript
5
star
59

bolt-python-getting-started-app

Getting Started Slack app using โšก๏ธ Bolt for Python
Python
4
star
60

easy-peasy-bot-custom-integration

DEPRECATED use https://github.com/slackapi/easy-peasy-bot instead
JavaScript
3
star
61

sample-incident-management

JavaScript
3
star
62

sample-code-index

An index of the most up-to-date sample code created by the Slack team
3
star
63

slack-health-score

A GitHub Action to report software project health score
JavaScript
3
star
64

deno-simple

TypeScript
2
star
65

deno-reverse-string

TypeScript
2
star
66

slack-app-time-off

Time-Off Request sample app for Slack's Next Generation Platform
TypeScript
1
star
67

deno-metadata-event

TypeScript
1
star
68

sunny-picnics

๐ŸŒค๐ŸŒณ๐ŸŒป๐Ÿงบ๐Ÿœ๐Ÿ‘’
1
star
69

deno-budget-calculator

TypeScript
1
star
70

deno-environment-variables

TypeScript
1
star
71

deno-testing-functions

TypeScript
1
star
72

template-ts-clip-message

TypeScript
1
star
73

slack-connect-sample

A sample app which shows off the functionality of the Slack Connect APIs.
JavaScript
1
star
74

deno-slack-protocols

Implements the rules for communication between Slack CLI and any Slack app development SDKs
TypeScript
1
star