Class: SlackMessageAdapter
Defined in: adapter.ts:120
An adapter for Slack's interactive message components such as buttons, menus, and dialogs.
Constructors
new SlackMessageAdapter()
new SlackMessageAdapter(signingSecret, __namedParameters): SlackMessageAdapter
Defined in: adapter.ts:154
Create a message adapter.
Parameters
signingSecret
string
Slack app signing secret used to authenticate request
__namedParameters
Returns
Properties
lateResponseFallbackEnabled
lateResponseFallbackEnabled: boolean;
Defined in: adapter.ts:136
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
signingSecret: string;
Defined in: adapter.ts:124
Slack app signing secret used to authenticate request
syncResponseTimeout
syncResponseTimeout: number;
Defined in: adapter.ts:130
The number of milliseconds to wait before flushing a synchronous response to an incoming request and falling back to an asynchronous response.
Methods
action()
action(matchingConstraints, callback): this
Defined in: adapter.ts:284
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 responseWhen 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 responseWhen 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 responseWhen 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
matchingConstraints
the callback ID (as a string or RegExp) or an object describing the constraints to match actions for the handler.
string
| RegExp
| ActionConstraints
callback
the function to run when an action is matched
Returns
this
this instance (for chaining)
createServer()
createServer(): Promise<Server>
Defined in: adapter.ts:197
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
<Server
>
A promise that resolves to an instance of http.Server and will dispatch interactive message actions and options requests to this message adapter instance. See https://nodejs.org/dist/latest/docs/api/http.html#http_class_http_server
dispatch()
dispatch(payload):
| undefined
| Promise<DispatchResult>
Defined in: adapter.ts:424
Internal
Dispatches the contents of an HTTP request to the registered handlers.
Parameters
payload
any
Returns
| undefined
| Promise
<DispatchResult
>
A promise of the response information (an object with status and content that is a JSON serializable object or a string or undefined) for the request. An undefined return value indicates that the request was not matched.
Remarks
This is an internal API not meant to be used by code depending on this package.
expressMiddleware()
expressMiddleware(): RequestHandler
Defined in: adapter.ts:248
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
A middleware function (see http://expressjs.com/en/guide/using-middleware.html)
options()
options(matchingConstraints, callback): this
Defined in: adapter.ts:342
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
matchingConstraints
the callback ID (as a string or RegExp) or an object describing the constraints to select options requests for the handler.
string
| RegExp
| OptionsConstraints
callback
the function to run when an options request is matched
Returns
this
this instance (for chaining)
requestListener()
requestListener(): RequestListener
Defined in: adapter.ts:258
Create a request listener function that handles HTTP requests, verifies requests and dispatches responses
Returns
RequestListener
shortcut()
shortcut(matchingConstraints, callback): this
Defined in: adapter.ts:308
Parameters
matchingConstraints
string
| RegExp
| ShortcutConstraints
callback
Returns
this
start()
start(port): Promise<Server>
Defined in: adapter.ts:208
Start a built-in server that dispatches Slack's interactive message actions and menu requests to this message adapter interface.
Parameters
port
number
Returns
Promise
<Server
>
A promise that resolves once the server is ready
stop()
stop(): Promise<void>
Defined in: adapter.ts:223
Stop the previously started built-in server.
Returns
Promise
<void
>
A promise that resolves once the server is cleaned up.
viewClosed()
viewClosed(matchingConstraints, callback): this
Defined in: adapter.ts:397
Add a handler for view closed interaction. The handler should not return a value.
Parameters
matchingConstraints
the callback ID (as a string or RegExp) or an object describing the constraints to match view closed interactions for the handler.
string
| RegExp
| ViewConstraints
callback
the function to run when an view closed interaction is matched
Returns
this
this instance (for chaining)
viewSubmission()
viewSubmission(matchingConstraints, callback): this
Defined in: adapter.ts:375
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
matchingConstraints
the callback ID (as a string or RegExp) or an object describing the constraints to match view submissions for the handler.
string
| RegExp
| ViewConstraints
callback
the function to run when an view submission is matched
Returns
this
this instance (for chaining)