An adapter for Slack’s interactive message components such as buttons, menus, and dialogs.
Create a message adapter.
Parameters:
Name | Type | Required | Description |
---|---|---|---|
signingSecret | string |
✓ | Slack app signing secret used to authenticate request |
opts | MessageAdapterOptions |
✗ | See options. |
Options:
Name | Type | |
---|---|---|
agent | Agent |
|
lateResponseFallbackEnabled | boolean |
|
syncResponseTimeout | number |
Name | Type | Description |
---|---|---|
lateResponseFallbackEnabled | boolean |
Whether or not promises that resolve after the syncResponseTimeout can fallback to a request for the response_url. This only works in cases where the semantic meaning of the response and the response_url are the same. |
signingSecret | string |
Slack app signing secret used to authenticate request |
syncResponseTimeout | number |
The number of milliseconds to wait before flushing a synchronous response to an incoming request and falling back to an asynchronous response. |
Add a handler for an interactive message action.
Usually there’s no need to be concerned with how a message is sent to Slack, but the following table describes it fully.
Action|Return object
|Return Promise<object>
|Return undefined
|Call respond(message)
|Notes :—–:|:—–:|:—–:|:—–:|:—–:|:—–: Button Press| Message in response | When resolved before syncResponseTimeout
or lateResponseFallbackEnabled: false
, message in response
When resolved after syncResponseTimeout
and lateResponseFallbackEnabled: true
, message in request to response_url
| Empty response | Message in request to response_url
| Create a new message instead of replacing using replace_original: false
Menu Selection| Message in response | When resolved before syncResponseTimeout
or lateResponseFallbackEnabled: false
, message in response
When resolved after syncResponseTimeout
and lateResponseFallbackEnabled: true
, message in request to response_url
| Empty response | Message in request to response_url
| Create a new message instead of replacing using replace_original: false
Message Action | Message in response | When resolved before syncResponseTimeout
or lateResponseFallbackEnabled: false
, message in response
When resolved after syncResponseTimeout
and lateResponseFallbackEnabled: true
, message in request to response_url
| Empty response | Message in request to response_url
| Dialog Submission| Error list in response | Error list in response | Empty response | Message in request to response_url
| Returning a Promise that takes longer than 3 seconds to resolve can result in the user seeing an error. Warning logged if a promise isn’t completed before syncResponseTimeout
.
Parameters:
Name | Type | Required | Description |
---|---|---|---|
matchingConstraints | string | RegExp | ActionConstraints |
✓ | the callback ID (as a string or RegExp) or an object describing the constraints to match actions for the handler. |
callback | ActionHandler |
✓ | the function to run when an action is matched |
Returns this
Create a server that dispatches Slack’s interactive message actions and menu requests to this message adapter instance. Use this method if your application will handle starting the server.
Returns Promise<http.Server>
Create a middleware function that can be used to integrate with the express
web framework in order for incoming requests to be dispatched to this message adapter instance.
Returns RequestHandler
Add a handler for an options request
Usually there’s no need to be concerned with how a message is sent to Slack, but the following table describes it fully
|Return options
|Return Promise<options>
|Return undefined
|Notes :—–:|:—–:|:—–:|:—–:|:—–: Options Request| Options in response | Options in response | Empty response | Returning a Promise that takes longer than 3 seconds to resolve can result in the user seeing an error. If the request is from within a dialog, the text
field is called label
.
Parameters:
Name | Type | Required | Description |
---|---|---|---|
matchingConstraints | string | RegExp | OptionsConstraints |
✓ | the callback ID (as a string or RegExp) or an object describing the constraints to select options requests for the handler. |
callback | OptionsHandler |
✓ | the function to run when an options request is matched |
Returns this
Create a request listener function that handles HTTP requests, verifies requests and dispatches responses
Returns RequestListener
Parameters:
Name | Type | Required | |
---|---|---|---|
matchingConstraints | string | RegExp | ShortcutConstraints |
✓ | |
callback | ShortcutHandler |
✓ |
Returns this
Start a built-in server that dispatches Slack’s interactive message actions and menu requests to this message adapter interface.
Parameters:
Name | Type | Required | |
---|---|---|---|
port | number |
✓ |
Returns Promise<http.Server>
Stop the previously started built-in server.
Returns Promise<void>
Add a handler for view closed interaction. The handler should not return a value.
Parameters:
Name | Type | Required | Description |
---|---|---|---|
matchingConstraints | string | RegExp | ViewConstraints |
✓ | the callback ID (as a string or RegExp) or an object describing the constraints to match view closed interactions for the handler. |
callback | ViewClosedHandler |
✓ | the function to run when an view closed interaction is matched |
Returns this
Add a handler for view submission.
The value returned from the callback
determines the response sent back to Slack. The handler can return a plain object with a response_action
property to dismiss the modal, push a view into the modal, display validation errors, or update the view. Alternatively, the handler can return a Promise for this kind of object, which resolves before syncResponseTimeout
or lateResponseFallbackEnabled: false
, to perform the same response actions. If the Promise resolves afterwards or lateResponseFallbackEnabled: true
then the modal will be dismissed. If the handler returns undefined
the modal will be dismissed.
Parameters:
Name | Type | Required | Description |
---|---|---|---|
matchingConstraints | string | RegExp | ViewConstraints |
✓ | the callback ID (as a string or RegExp) or an object describing the constraints to match view submissions for the handler. |
callback | ViewSubmissionHandler |
✓ | the function to run when an view submission is matched |
Returns this
Factory method to create an instance of SlackMessageAdapter
Parameters:
Name | Type | Required | |
---|---|---|---|
signingSecret | string |
✓ | |
options | MessageAdapterOptions |
✗ |
Returns SlackMessageAdapter
A dictionary of codes for errors produced by this package.
Some HTTP response statuses.
Constraints on when to call an action handler.
Name | Type | Description |
---|---|---|
actionId | string | RegExp |
A string or RegExp to match against the |
blockId | string | RegExp |
A string or RegExp to match against the |
callbackId | string | RegExp |
A string or RegExp to match against the |
type | string |
Valid types include all [actions block elements](https://api.slack.com/reference/messaging/interactive-components), |
unfurl | boolean |
When |
The result of a call to dispatch
.
Name | Type | |
---|---|---|
content | any |
|
status | ResponseStatus |
Options for constructing SlackMessageAdapter
.
Name | Type | |
---|---|---|
agent | Agent |
|
lateResponseFallbackEnabled | boolean |
|
syncResponseTimeout | number |
Constraints on when to call an options handler.
Name | Type | Description |
---|---|---|
actionId | string | RegExp |
A string or RegExp to match against the |
blockId | string | RegExp |
A string or RegExp to match against the |
callbackId | string | RegExp |
A string or RegExp to match against the |
within | 'block_actions' | 'interactive_message' | 'dialog' |
The source of options request. |
Constraints on when to call an shortcut handler.
Name | Type | Description |
---|---|---|
callbackId | string | RegExp |
A string or RegExp to match against the |
type | 'shortcut' |
Valid type includes shortcut |
Constraints on when to call a view submission or view closed handler.
Name | Type | Description |
---|---|---|
callbackId | string | RegExp |
A string or RegExp to match against the |
externalId | string | RegExp |
A string to match against the |
viewId | string |
A string to match against the |
A handler function for action requests (block actions, button presses, menu selections, and dialog submissions).
) => any | Promise<any> | undefined
A handler function for menu options requests.
<any> | undefined
A function used to send message updates after an action is handled. This function can be used up to 5 times in 30 minutes.
<unknown>
A handler function for global shortcuts.
TODO: describe the payload and return values more specifically?
<any> | undefined
A handler function for view closed requests.
TODO: describe the payload and return values more specifically?
One of:
A handler function for view submission requests.
TODO: describe the payload and return values more specifically?
<any> | undefined