You can register handlers to respond to specific view interactions by chaining methods onto your SlackFunction definition. These handlers use a constraint to match the view's callback_id.
Supported Handlers
addViewSubmissionHandler(constraint, handler): Invoked when a user submits a view.addViewClosedHandler(constraint, handler): Invoked when a user closes a view. Requirement: The view must have notify_on_close: true set.
Constraint Types
The constraint argument can be:
- A
string: Must match the callback_id exactly. - An
array of strings: Matches if the callback_id is in the array. - A
RegExp: Matches if the callback_id satisfies the regular expression.
Response Actions
Inside a view handler, you can respond to interactions in two ways:
- Using the Client API: Call
await client.views.push(...) or await client.views.update(...). - Using
response_action: Return a specially crafted object from the handler function.
Comparison of methods:
// Method 1: Using the API
}).addViewSubmissionHandler(/view/, async ({ client, body }) => {
await client.views.push({
trigger_id: body.trigger_id,
view: { /* ... */ },
});
})
// Method 2: Using response_action
}).addSubmissionHandler(/view/, async () => {
return {
response_action: "push",
view: { /* ... */ },
};
});
export default SlackFunction(DiaryFunction, async ({ inputs, client }) => {
// ... logic ...
}).addViewSubmissionHandler(
/view/,
async ({ view, body, token }) => {
console.log("Incoming view submission handler invocation", body);
},
)
.addViewClosedHandler(
/view/,
async ({ view, body, token }) => {
console.log("Incoming view closed handler invocation", body);
},
);