Skip to content

Commit 2f514e1

Browse files
committed
added page for custom steps
1 parent bd9c5e8 commit 2f514e1

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

docs/content/guides/custom-steps

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
var userId = req.getEvent().getInputs().get("user_id").asString();
18+
var 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+
var 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 app manifest function definition for the preceding function might look like this:
40+
41+
```json
42+
"functions": {
43+
"sample_function": {
44+
"title": "Send a request",
45+
"description": "Send some request to the backend",
46+
"input_parameters": {
47+
"user_id": {
48+
"type": "slack#/types/user_id",
49+
"title": "User",
50+
"description": "Who to send it",
51+
"is_required": true,
52+
"hint": "Select a user in the workspace",
53+
"name": "user_id"
54+
}
55+
},
56+
"output_parameters": {
57+
"channel_id": {
58+
"type": "slack#/types/channel_id",
59+
"title": "DM ID",
60+
"description": "The DM ID",
61+
"is_required": true,
62+
"name": "channel_id"
63+
},
64+
"ts": {
65+
"type": "string",
66+
"title": "Message timestamp",
67+
"description": "Sent message timestamp",
68+
"is_required": true,
69+
"name": "ts"
70+
}
71+
}
72+
}
73+
}
74+
```
75+
76+
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 name of your app.

docs/sidebars.js

Lines changed: 1 addition & 0 deletions
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)