Adding interactivity to your app adds a dynamic experience that makes it more substantive than just a bot sending messages. There are a few different ways to achieve interactivity in a workflow app.
All options share some basic elements in common.
In order to prevent inundating users with pop-ups they didn't ask for, all app interactivity requires an interactivity parameter. This is the user's consent to interact with the app; only a user's interaction can open a form or modal.
Whether the user is opening a form, modal, or sending an interactive message, this looks the same—including an input_parameter
of the type interactivity
.
Not supported in Workflow Builder
Custom functions that require interactivity inputs are not currently supported in Workflow Builder.
Both modals and interactive messages allow for interactive blocks, a flexible and dynamic way to create visually appealing app interaction. Check out an example in step 2 of Creating an interactive message, explore the Block Kit reference for a menu of interactive options, then try them out in Block Kit Builder.
An interactive form is a static mechanism that merely gathers information from the user, but modals and messages allow for more of a back-and-forth interaction. This means being able to respond to your user's actions and inputs dynamically. This is achieved by utilizing interactivity handlers.
Handler name | Description | Where it can be used |
---|---|---|
BlockActionsHandler |
Used to respond to interactivity that happens within an interactive block. | Modals |
BlockSuggestionHandler |
Used alongside a select menu of external data source element. | Modals |
ViewSubmissionHandler |
Used to update a modal view after it has been submitted. | Modals |
ViewClosedHandler |
Used to update an app after a view has been closed. | Modals |
UnhandledEventHandler |
Used as a catch-all for unhandled events. | Modals |
It's best practice to properly handle a function's success or error when a modal is submitted or closed. Refer to creating an interactive modal for more details.
View sample payloads for these handlers in the Interaction payloads documentation.
Each handler contains two arguments, a constraint
and a handler
, such that its invocation will look like this:
addBlockActionsHandler(constraint, handler)
addBlockSuggestionHandler(constraint, handler)
addViewSubmissionHandler(constraint, handler)
addViewClosedHandler(constraint, handler)
addUnhandledEventHandler(constraint, handler)
If any incoming event matches the constraint
, the specified handler will be invoked with the event payload. The handler
arugment is the handler function that you define—what you want to happen in this event. Every type of handler function has the same context properties available to it, which are the same as the context properties available to custom functions. This allows for authoring focused, single-purpose handlers and provides a concise, yet flexible API for registering handlers to specific interactions.
What the constraint
field allows depends on the type of handler.
For the BlockActionsHandler
and the BlockSuggestionHandler
, the constraint
can be either a BlockActionConstraintField
or a BlockActionConstraintObject
.
BlockActionConstraintField
can be one of three options.
type BlockActionConstraintField = string | string[] | RegExp;
string
, it must match the field exactly.string
, it must match one of the array values exactly.RegExp
, the regular expression must match.The BlockActionConstraintObject
contains two properties.
type BlockActionConstraintObject = {
block_id?: BlockActionConstraintField;
action_id?: BlockActionConstraintField;
};
When the constraint
is provided as an object in the form of a BlockActionConstraintObject
, it can contain either or both a block_id
and an action_id
.
BlockActionConstraintField
(see above).action_id
and block_id
properties exist on the constraint, then both action_id
and block_id
properties must match any incoming action.See an example of the BlockActionsHandler
and the BlockSuggestionHandler
in action in the Creating an interactive message guide.
The constraint
field for the view handlers is a bit different than in the BlockActionsHandler
and BlockSuggestionHandler
.
SlackFunction({ ... }).addViewSubmissionHandler("my_view_callback_id", async (ctx) => { ... });
For view handlers, the consraint
argument can be either a string
, string[]
, or a RegExp
.
string
constraint must match a view's callback_id
exactly.string []
constraint must match a view's callback_id
to any of the strings in the array.callback_id
.The UnhandledEventHandler
handles everything unaccounted for. It then makes sense that this handler does not accept a constraint
argument. It does, however, accept the same handler
argument as the other handlers, which is the handler function you define. Remember, all custom function context properties are availalbe for use here.
.addUnhandledEventHandler(({ body: _body }) => {
console.log("unhandled event happened");
//add some other actions
})
Ready to get started?
✨ Get started with collecting user input by creating a form.
✨ Dazzle your users by sending them an interactive message.
✨ Create some back-and-forth banter with interactive modals.