All Projects → slackapi → Bolt Js

slackapi / Bolt Js

Licence: mit
A framework to build Slack apps using JavaScript

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Bolt Js

Node Slack Sdk
Slack Developer Kit for Node.js
Stars: ✭ 2,988 (+51.6%)
Mutual labels:  slack, websocket, websockets, websocket-client, socket-mode
Python Slack Sdk
Slack Developer Kit for Python
Stars: ✭ 3,307 (+67.78%)
Mutual labels:  slack, websocket, websockets, websocket-client, socket-mode
Bolt Python
A framework to build Slack apps using Python
Stars: ✭ 190 (-90.36%)
Mutual labels:  slack, websocket, websockets, websocket-client
Java Slack Sdk
Slack Developer Kit (including Bolt for Java) for any JVM language
Stars: ✭ 393 (-80.06%)
Mutual labels:  slack, websocket, websockets, websocket-client
Arduinowebsockets
arduinoWebSockets
Stars: ✭ 1,265 (-35.82%)
Mutual labels:  websocket, websockets, websocket-client
Websocket Client
WebSocket client for Python
Stars: ✭ 2,810 (+42.57%)
Mutual labels:  websocket, websockets, websocket-client
Claws
Awesome WebSocket CLient - an interactive command line client for testing websocket servers
Stars: ✭ 187 (-90.51%)
Mutual labels:  websocket, websockets, websocket-client
Beast
HTTP and WebSocket built on Boost.Asio in C++11
Stars: ✭ 3,241 (+64.43%)
Mutual labels:  websocket, websockets, websocket-client
Websocket Client
🔧 .NET/C# websocket client library
Stars: ✭ 297 (-84.93%)
Mutual labels:  websocket, websockets, websocket-client
Websockets
Library for building WebSocket servers and clients in Python
Stars: ✭ 3,724 (+88.94%)
Mutual labels:  websocket, websockets, websocket-client
Php Wss
Web-socket server/client with multi-process and parse templates support on server and send/receive options on client
Stars: ✭ 117 (-94.06%)
Mutual labels:  websocket, websockets, websocket-client
Starscream
Websockets in swift for iOS and OSX
Stars: ✭ 7,105 (+260.48%)
Mutual labels:  websocket, websockets, websocket-client
Gun
HTTP/1.1, HTTP/2 and Websocket client for Erlang/OTP.
Stars: ✭ 710 (-63.98%)
Mutual labels:  websocket, websockets, websocket-client
Awesome Websockets
A curated list of Websocket libraries and resources.
Stars: ✭ 850 (-56.87%)
Mutual labels:  websocket, websockets, websocket-client
Sketchpad
Sketchpad is fully customisable collaborative whiteboard plugin written in pure JavaScript.
Stars: ✭ 85 (-95.69%)
Mutual labels:  websocket, websocket-client
Uvicorn Gunicorn Starlette Docker
Docker image with Uvicorn managed by Gunicorn for high-performance Starlette web applications in Python 3.7 and 3.6 with performance auto-tuning. Optionally with Alpine Linux.
Stars: ✭ 92 (-95.33%)
Mutual labels:  framework, websockets
Nodefony Starter
Nodefony Starter Node.js Framework
Stars: ✭ 95 (-95.18%)
Mutual labels:  framework, websocket
Localslackirc
IRC gateway for slack, running on localhost for one user
Stars: ✭ 84 (-95.74%)
Mutual labels:  slack, websockets
T Io
解决其它网络框架没有解决的用户痛点,让天下没有难开发的网络程序
Stars: ✭ 1,331 (-32.47%)
Mutual labels:  websocket, websocket-client
Fs2 Http
Http Server and client using fs2
Stars: ✭ 132 (-93.3%)
Mutual labels:  websockets, websocket-client

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 interchangably. 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 (shortcuts, actions, 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 }) => {
  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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].