-
Notifications
You must be signed in to change notification settings - Fork 228
API Docs: Custom steps documentation #1457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,77 @@ | ||||||
| --- | ||||||
| title: Custom Steps | ||||||
| lang: en | ||||||
| --- | ||||||
|
|
||||||
| 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. | ||||||
|
|
||||||
| * `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. | ||||||
| * `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. | ||||||
|
|
||||||
| You can reference your custom step's inputs using the `getInputs()` method shown below. | ||||||
|
|
||||||
| ```java | ||||||
| app.function("sample_function", (req, ctx) -> { | ||||||
| app.executorService().submit(() -> { | ||||||
| try { | ||||||
| var userId = req.getEvent().getInputs().get("user_id").asString(); | ||||||
| var response = ctx.client().chatPostMessage(r -> r | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| .channel(userId) // sending a DM | ||||||
| .text("Hi! Thank you for submitting the request! We'll let you know once the processing completes.") | ||||||
| ); | ||||||
| var outputs = new HashMap<String, Object>(); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| outputs.put("channel_id", response.getChannel()); | ||||||
| outputs.put("ts", response.getTs()); | ||||||
| ctx.complete(outputs); | ||||||
| } catch (Exception e) { | ||||||
| ctx.logger.error(e.getMessage(), e); | ||||||
| try { | ||||||
| ctx.fail("Failed to handle 'sample_function' custom step execution (error: " + e.getMessage() + ")"); | ||||||
| } catch (Exception ex) { | ||||||
| ctx.logger.error(e.getMessage(), e); | ||||||
| } | ||||||
| } | ||||||
| }); | ||||||
| return ctx.ack(); | ||||||
| }); | ||||||
| ``` | ||||||
|
|
||||||
| The corresponding function definition section of the app manifest for the preceding function might look like this: | ||||||
|
|
||||||
| ```json | ||||||
| ... | ||||||
| "functions": { | ||||||
| "sample_function": { | ||||||
| "title": "Send a request", | ||||||
| "description": "Send some request to the backend", | ||||||
| "input_parameters": { | ||||||
| "user_id": { | ||||||
| "type": "slack#/types/user_id", | ||||||
| "title": "User", | ||||||
| "description": "Who to send it", | ||||||
| "is_required": true, | ||||||
| "hint": "Select a user in the workspace", | ||||||
| "name": "user_id" | ||||||
| } | ||||||
| }, | ||||||
| "output_parameters": { | ||||||
| "channel_id": { | ||||||
| "type": "slack#/types/channel_id", | ||||||
| "title": "DM ID", | ||||||
| "description": "The DM ID", | ||||||
| "is_required": true, | ||||||
| "name": "channel_id" | ||||||
| }, | ||||||
| "ts": { | ||||||
| "type": "string", | ||||||
| "title": "Message timestamp", | ||||||
| "description": "Sent message timestamp", | ||||||
| "is_required": true, | ||||||
| "name": "ts" | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| 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. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every other code snippet in these docs use the proper type rather then
var