///
import http, { RequestListener, Agent } from 'http';
import { RequestHandler } from 'express';
/**
* An adapter for Slack's interactive message components such as buttons, menus, and dialogs.
*/
export declare class SlackMessageAdapter {
/**
* Slack app signing secret used to authenticate request
*/
signingSecret: string;
/**
* The number of milliseconds to wait before flushing a synchronous response to an incoming request and falling back
* to an asynchronous response.
*/
syncResponseTimeout: number;
/**
* 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.
*/
lateResponseFallbackEnabled: boolean;
private callbacks;
private axios;
private server?;
/**
* Create a message adapter.
*
* @param signingSecret - Slack app signing secret used to authenticate request
* @param options.syncResponseTimeout - number of milliseconds to wait before flushing a synchronous response to an
* incoming request and falling back to an asynchronous response.
* @param options.lateResponseFallbackEnabled - 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.
*/
constructor(signingSecret: string, { syncResponseTimeout, lateResponseFallbackEnabled, agent, }?: MessageAdapterOptions);
/**
* 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 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
*/
createServer(): Promise;
/**
* Start a built-in server that dispatches Slack's interactive message actions and menu requests to this message
* adapter interface.
*
* @returns A promise that resolves once the server is ready
*/
start(port: number): Promise;
/**
* Stop the previously started built-in server.
*
* @returns A promise that resolves once the server is cleaned up.
*/
stop(): Promise;
/**
* 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 A middleware function (see http://expressjs.com/en/guide/using-middleware.html)
*/
expressMiddleware(): RequestHandler;
/**
* Create a request listener function that handles HTTP requests, verifies requests and dispatches responses
*/
requestListener(): RequestListener;
/**
* 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`**|**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`.
*
* @param matchingConstraints - the callback ID (as a string or RegExp) or an object describing the constraints to
* match actions for the handler.
* @param callback - the function to run when an action is matched
* @returns this instance (for chaining)
*/
action(matchingConstraints: string | RegExp | ActionConstraints, callback: ActionHandler): this;
shortcut(matchingConstraints: string | RegExp | ShortcutConstraints, callback: ShortcutHandler): this;
/**
* 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`**|**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`.
*
* @param matchingConstraints - the callback ID (as a string or RegExp) or an object describing the constraints to
* select options requests for the handler.
* @param callback - the function to run when an options request is matched
* @returns this instance (for chaining)
*/
options(matchingConstraints: string | RegExp | OptionsConstraints, callback: OptionsHandler): 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.
*
* @param matchingConstraints - the callback ID (as a string or RegExp) or an object describing the constraints to
* match view submissions for the handler.
* @param callback - the function to run when an view submission is matched
* @returns this instance (for chaining)
*/
viewSubmission(matchingConstraints: string | RegExp | ViewConstraints, callback: ViewSubmissionHandler): this;
/**
* Add a handler for view closed interaction. The handler should not return a value.
*
* @param matchingConstraints - the callback ID (as a string or RegExp) or an object describing the constraints to
* match view closed interactions for the handler.
* @param callback - the function to run when an view closed interaction is matched
* @returns this instance (for chaining)
*/
viewClosed(matchingConstraints: string | RegExp | ViewConstraints, callback: ViewClosedHandler): this;
/**
* Dispatches the contents of an HTTP request to the registered handlers.
*
* @remarks
* This is an internal API not meant to be used by code depending on this package.
*
* @internal
* @returns 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.
*/
dispatch(payload: any): Promise | undefined;
private registerCallback;
private matchCallback;
}
export default SlackMessageAdapter;
/** Some HTTP response statuses. */
export declare enum ResponseStatus {
Ok = 200,
Failure = 500
}
/**
* The result of a call to {@link SlackMessageAdapter#dispatch}.
*/
export interface DispatchResult {
status: ResponseStatus;
content?: any;
}
/**
* Options for constructing {@link SlackMessageAdapter}.
*/
export interface MessageAdapterOptions {
syncResponseTimeout?: number;
lateResponseFallbackEnabled?: boolean;
agent?: Agent;
}
/**
* Constraints on when to call an action handler.
*/
export interface ActionConstraints {
/**
* A string or RegExp to match against the `callback_id`
*/
callbackId?: string | RegExp;
/**
* A string or RegExp to match against the `block_id`
*/
blockId?: string | RegExp;
/**
* A string or RegExp to match against the `action_id`
*/
actionId?: string | RegExp;
/**
* Valid types include all
* [actions block elements](https://api.slack.com/reference/messaging/interactive-components),
* `select` only for menu selections, or `dialog_submission` only for dialog submissions
*/
type?: string;
/**
* When `true` only match actions from an unfurl
*/
unfurl?: boolean;
}
/**
* Constraints on when to call an shortcut handler.
*/
export interface ShortcutConstraints {
/**
* A string or RegExp to match against the `callback_id`
*/
callbackId?: string | RegExp;
/**
* Valid type includes shortcut
*/
type?: 'shortcut';
}
/**
* Constraints on when to call an options handler.
*/
export interface OptionsConstraints {
/**
* A string or RegExp to match against the `callback_id`
*/
callbackId?: string | RegExp;
/**
* A string or RegExp to match against the `block_id`
*/
blockId?: string | RegExp;
/**
* A string or RegExp to match against the `action_id`
*/
actionId?: string | RegExp;
/**
* The source of options request.
*/
within: 'block_actions' | 'interactive_message' | 'dialog';
}
/**
* Constraints on when to call a view submission or view closed handler.
*/
export interface ViewConstraints {
/**
* A string or RegExp to match against the `callback_id`
*/
callbackId?: string | RegExp;
/**
* A string to match against the `external_id`
*/
externalId?: string | RegExp;
/**
* A string to match against the `view_id`
*/
viewId?: string;
}
export declare type AnyConstraints = ActionConstraints | OptionsConstraints | ViewConstraints | ShortcutConstraints;
/**
* The type of stored constraints.
*/
declare const enum StoredConstraintsType {
Action = "action",
Shortcut = "shortcut",
Options = "options",
ViewSubmission = "view_submission",
ViewClosed = "view_closed"
}
/**
* Internal storage type that describes the constraints of an ActionHandler or OptionsHandler.
*/
export declare type StoredConstraints = ({
handlerType: StoredConstraintsType.Action;
} & ActionConstraints) | ({
handlerType: StoredConstraintsType.Shortcut;
} & ShortcutConstraints) | ({
handlerType: StoredConstraintsType.Options;
} & OptionsConstraints) | ({
handlerType: StoredConstraintsType.ViewSubmission;
} & ViewConstraints) | ({
handlerType: StoredConstraintsType.ViewClosed;
} & ViewConstraints);
/**
* A function used to send message updates after an action is handled. This function can be used
* up to 5 times in 30 minutes.
*
* @param message - a [message](https://api.slack.com/docs/interactive-message-field-guide#top-level_message_fields).
* Dialog submissions do not allow `replace_original: false` on this message.
* @returns there's no contract or interface for the resolution value, but this Promise will resolve when the HTTP
* response from the `response_url` request is complete and reject when there is an error.
*/
export declare type Respond = (message: any) => Promise;
/**
* A handler function for action requests (block actions, button presses, menu selections,
* and dialog submissions).
*
* @param payload - an object describing the
* [block actions](https://api.slack.com/messaging/interactivity/enabling#understanding-payloads)
* [button press](https://api.slack.com/docs/message-buttons#responding_to_message_actions),
* [menu selection](https://api.slack.com/docs/message-menus#request_url_response), or
* [dialog submission](https://api.slack.com/dialogs#evaluating_submission_responses).
* @param respond - When the action is a button press or menu selection, this function is used to update the message
* where the action occurred or create new messages in the same conversation. When the action is a dialog submission,
* this function is used to create new messages in the conversation where the dialog was triggered.
* @returns When the action is a button press or a menu selection, this object is a replacement
* [message](https://api.slack.com/docs/interactive-message-field-guide#top-level_message_fields) for the message in
* which the action occurred. It may also be a Promise for a message, and if so and the Promise takes longer than the
* `syncResponseTimeout` to complete, the message is sent over the `response_url`. The message may also be a new
* message in the same conversation by setting `replace_original: false`. When the action is a dialog submission,
* this object is a list of [validation errors](https://api.slack.com/dialogs#input_validation). It may also be a
* Promise for a list of validation errors, and if so and the Promise takes longer than the `syncResponseTimeout` to
* complete, Slack will display an error to the user. If there is no return value, then button presses and menu
* selections do not update the message and dialog submissions will validate and dismiss.
*/
export declare type ActionHandler = (payload: any, respond: Respond) => any | Promise | undefined;
/**
* A handler function for global shortcuts.
*
* TODO: describe the payload and return values more specifically?
*/
export declare type ShortcutHandler = (payload: any) => any | Promise | undefined;
/**
* A handler function for menu options requests.
*
* @param payload - an object describing
* [the state of the menu](https://api.slack.com/docs/message-menus#options_load_url)
* @returns an [options list](https://api.slack.com/docs/interactive-message-field-guide#option_fields) or
* [option groups list](https://api.slack.com/docs/interactive-message-field-guide#option_groups). When the menu is
* within an interactive message, (`within: 'interactive_message'`) the option keys are `text` and `value`. When the
* menu is within a dialog (`within: 'dialog'`) the option keys are `label` and `value`. When the menu is within a
* dialog (`within: 'block_actions'`) the option keys are a text block and `value`. This function may also return a
* Promise either of these values. If a Promise is returned and it does not complete within 3 seconds, Slack will
* display an error to the user. If there is no return value, then the user is shown an empty list of options.
*/
export declare type OptionsHandler = (payload: any) => any | Promise | undefined;
/**
* A handler function for view submission requests.
*
* TODO: describe the payload and return values more specifically?
*/
export declare type ViewSubmissionHandler = (payload: any) => any | Promise | undefined;
/**
* A handler function for view closed requests.
*
* TODO: describe the payload and return values more specifically?
*/
export declare type ViewClosedHandler = (payload: any) => void;
//# sourceMappingURL=adapter.d.ts.map