Skip to content

Commit d435b84

Browse files
authored
API Docs: Custom steps documentation (#1457)
* added page for custom steps * alpha order bolt basics page * PR feedback
1 parent bd9c5e8 commit d435b84

File tree

3 files changed

+88
-9
lines changed

3 files changed

+88
-9
lines changed

docs/content/guides/bolt-basics.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,20 @@ Here is the list of the available methods to dispatch events.
3131

3232
|Method|Constraints (value: type)|Description|
3333
|-|-|-|
34-
|`app.event`|event type: `Class\<Event\>`|[Events API](/guides/events-api): Responds to any kinds of bot/user events you subscribe.|
35-
|`app.message`|keyword: `String` \| `Pattern`|[Events API](/guides/events-api): Responds to messages posted by a user only when the text in messages matches the given keyword or regular expressions.|
36-
|`app.command`|command name: `String` \| `Pattern`|[Slash Commands](/guides/slash-commands): Responds to slash command invocations in the workspace.|
34+
|`app.attachmentAction`|callback_id: `String` \| `Pattern`|Legacy Messaging: Responds to user actions in attachments. These events can be triggered in only messages.|
3735
|`app.blockAction`|action_id: `String` \| `Pattern`|[Interactive Components](/guides/interactive-components): Responds to user actions (e.g., click a button, choose an item from select menus, radio buttons, etc.) in `blocks`. These events can be triggered in all the surfaces (messages, modals, and Home tabs).|
3836
|`app.blockSuggestion`|action_id: `String` \| `Pattern`|[Interactive Components](/guides/interactive-components): Responds to user actions to input a keyword (the length needs to be the `min_query_length` or longer) in select menus (external data source).|
39-
|`app.viewSubmission`|callback_id: `String` \| `Pattern`|[Modals](/guides/modals): Responds to data submissions in modals.|
40-
|`app.viewClosed`|callback_id: `String` \| `Pattern`|[Modals](/guides/modals): Responds to the events where users close modals by clicking Cancel buttons. The `notify_on_close` has to be `true` when opening/pushing the modal.|
41-
|`app.globalShortcut`|callback_id: `String` \| `Pattern`|[Shortcuts](/guides/shortcuts): Responds to global shortcut invocations.|
42-
|`app.messageShortcut`|callback_id: `String` \| `Pattern`|[Shortcuts](/guides/shortcuts): Responds to shortcut invocations in message menus.|
37+
|`app.command`|command name: `String` \| `Pattern`|[Slash Commands](/guides/slash-commands): Responds to slash command invocations in the workspace.|
38+
|`app.dialogCancellation`|callback_id `String` \| `Pattern`|Dialogs: Responds to the events where users close dialogs by clicking Cancel buttons.|
4339
|`app.dialogSubmission`|callback_id: `String` \| `Pattern`|Dialogs: Responds to data submissions in dialogs.|
4440
|`app.dialogSuggestion`|callback_id: `String` \| `Pattern`|Dialogs: Responds to requests to load options for `"external"` typed select menus in dialogs.|
45-
|`app.dialogCancellation`|callback_id `String` \| `Pattern`|Dialogs: Responds to the events where users close dialogs by clicking Cancel buttons.|
46-
|`app.attachmentAction`|callback_id: `String` \| `Pattern`|Legacy Messaging: Responds to user actions in attachments. These events can be triggered in only messages.|
41+
|`app.event`|event type: `Class\<Event\>`|[Events API](/guides/events-api): Responds to any kinds of bot/user events you subscribe.|
42+
| `app.function` | callback_id: `String` \| `Pattern` | [Custom steps](/guides/custom-steps): Defines a function that can be used as a custom step in [Workflow Builder](https://slack.com/help/articles/360035692513-Guide-to-Slack-Workflow-Builder).
43+
|`app.globalShortcut`|callback_id: `String` \| `Pattern`|[Shortcuts](/guides/shortcuts): Responds to global shortcut invocations.|
44+
|`app.message`|keyword: `String` \| `Pattern`|[Events API](/guides/events-api): Responds to messages posted by a user only when the text in messages matches the given keyword or regular expressions.|
45+
|`app.messageShortcut`|callback_id: `String` \| `Pattern`|[Shortcuts](/guides/shortcuts): Responds to shortcut invocations in message menus.|
46+
|`app.viewClosed`|callback_id: `String` \| `Pattern`|[Modals](/guides/modals): Responds to the events where users close modals by clicking Cancel buttons. The `notify_on_close` has to be `true` when opening/pushing the modal.|
47+
|`app.viewSubmission`|callback_id: `String` \| `Pattern`|[Modals](/guides/modals): Responds to data submissions in modals.|
4748

4849
---
4950
## Development Guides by Feature

docs/content/guides/custom-steps.md

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
title: Custom Steps
3+
lang: en
4+
---
5+
6+
Your app can use the `function()` method to listen to incoming [custom step requests](https://docs.slack.dev/workflows/workflow-steps). Custom steps are used in Workflow Builder to build workflows. The method requires a step `callback_id` of type `string`. This `callback_id` must also be defined in your [Function](https://docs.slack.dev/reference/app-manifest#functions) definition. Custom steps must be finalized using the `complete()` or `fail()` listener arguments to notify Slack that your app has processed the request.
7+
8+
* `complete()` requires one argument: an `outputs` object. It ends your custom step successfully and provides an object containing the outputs of your custom step as per its definition.
9+
* `fail()` requires one argument: `error` of type `string`. It ends your custom step unsuccessfully and provides a message containing information regarding why your custom step failed.
10+
11+
You can reference your custom step's inputs using the `getInputs()` method shown below.
12+
13+
```java
14+
app.function("sample_function", (req, ctx) -> {
15+
app.executorService().submit(() -> {
16+
try {
17+
String userId = req.getEvent().getInputs().get("user_id").asString();
18+
ChatPostMessageResponse response = ctx.client().chatPostMessage(r -> r
19+
.channel(userId) // sending a DM
20+
.text("Hi! Thank you for submitting the request! We'll let you know once the processing completes.")
21+
);
22+
Map<String, Object> outputs = new HashMap<String, Object>();
23+
outputs.put("channel_id", response.getChannel());
24+
outputs.put("ts", response.getTs());
25+
ctx.complete(outputs);
26+
} catch (Exception e) {
27+
ctx.logger.error(e.getMessage(), e);
28+
try {
29+
ctx.fail("Failed to handle 'sample_function' custom step execution (error: " + e.getMessage() + ")");
30+
} catch (Exception ex) {
31+
ctx.logger.error(e.getMessage(), e);
32+
}
33+
}
34+
});
35+
return ctx.ack();
36+
});
37+
```
38+
39+
The corresponding function definition section of the app manifest for the preceding function might look like this:
40+
41+
```json
42+
...
43+
"functions": {
44+
"sample_function": {
45+
"title": "Send a request",
46+
"description": "Send some request to the backend",
47+
"input_parameters": {
48+
"user_id": {
49+
"type": "slack#/types/user_id",
50+
"title": "User",
51+
"description": "Who to send it",
52+
"is_required": true,
53+
"hint": "Select a user in the workspace",
54+
"name": "user_id"
55+
}
56+
},
57+
"output_parameters": {
58+
"channel_id": {
59+
"type": "slack#/types/channel_id",
60+
"title": "DM ID",
61+
"description": "The DM ID",
62+
"is_required": true,
63+
"name": "channel_id"
64+
},
65+
"ts": {
66+
"type": "string",
67+
"title": "Message timestamp",
68+
"description": "Sent message timestamp",
69+
"is_required": true,
70+
"name": "ts"
71+
}
72+
}
73+
}
74+
}
75+
```
76+
77+
Once your custom step is defined in your app's manifest and implemented in code, it is discoverable in Workflow Builder when you **Add Step** and search for the title of your step or name of your app.

docs/sidebars.js

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const sidebars = {
3636
items: ['guides/interactive-components', 'guides/modals', 'guides/app-home',],
3737
},
3838
'guides/ai-apps',
39+
'guides/custom-steps',
3940
'guides/shortcuts',
4041
'guides/slash-commands',
4142
{

0 commit comments

Comments
 (0)