-
Notifications
You must be signed in to change notification settings - Fork 406
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
docs: replacement steps from apps with custom functions #2149
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4c6da27
docs: replacement steps from apps with custom functions
lukegalbraithrussell 81071fd
docs: keeping ye olde steps from app docs
lukegalbraithrussell aea4c85
docs: polishing custom functions
lukegalbraithrussell 00cbedb
docs: polished deprecation style
lukegalbraithrussell b3faab3
beta warnings
lukegalbraithrussell a9337ec
Update creating.md
lukegalbraithrussell 58b436f
Update listening.md
lukegalbraithrussell 8380f12
Update responding.md
lukegalbraithrussell c4a8688
Merge branch 'main' into docs-custom-functions
lukegalbraithrussell 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 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 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,20 @@ | ||
--- | ||
title: Creating custom functions | ||
lang: en | ||
slug: creating-custom-functions | ||
order: 1 | ||
--- | ||
|
||
<div class="section-content"> | ||
Custom functions allow your app to create and process workflow steps that users can add in [Workflow Builder](https://api.slack.com/workflows). | ||
|
||
We recommend using custom functions as a replacement for the [deprecated Workflow Steps from Apps](#steps). | ||
|
||
A custom function requires two components: | ||
|
||
* [A function definition in the app’s manifest](#defining-custom-functions) | ||
* [A listener to handle the function execution event](#listening-to-custom-functions) | ||
|
||
Read more about custom functions in the [Slack API documentation](https://api.slack.com/automation/functions/custom-bolt). | ||
|
||
</div> |
This file contains 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,44 @@ | ||
--- | ||
title: Defining custom functions | ||
lang: en | ||
slug: defining-custom-functions | ||
order: 2 | ||
--- | ||
|
||
<div class="section-content"> | ||
|
||
To make a custom function available for use in Workflow Builder, the app’s manifest must contain a function definition. | ||
|
||
A function’s definition contains information about the function, including its `callback_id`, `input_parameters`, `output_parameters`, as well as display information. | ||
|
||
To learn more about defining a function, see the [Slack API documentation](https://api.slack.com/automation/functions/custom-bolt#define-function). | ||
|
||
</div> | ||
|
||
```json | ||
"functions": { | ||
"sample_function": { | ||
"title": "Sample function", | ||
"description": "Runs sample function", | ||
"input_parameters": { | ||
"user_id": { | ||
"type": "slack#/types/user_id", | ||
"title": "User", | ||
"description": "Message recipient", | ||
"is_required": true, | ||
"hint": "Select a user in the workspace", | ||
"name": "user_id" | ||
} | ||
}, | ||
"output_parameters": { | ||
"user_id": { | ||
"type": "slack#/types/user_id", | ||
"title": "User", | ||
"description": "User that completed the function", | ||
"is_required": true, | ||
"name": "user_id" | ||
} | ||
} | ||
} | ||
} | ||
``` |
This file contains 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,32 @@ | ||
--- | ||
title: Listening to custom function executions | ||
lang: en | ||
slug: listening-to-custom-functions | ||
order: 3 | ||
--- | ||
|
||
<div class="section-content"> | ||
|
||
When your custom function is executed as a step in a workflow, your app will receive a [`function_executed`](https://api.slack.com/events/function_executed) event. The callback provided to the `function()` method will be run when this event is received. | ||
|
||
The callback is where you can access `inputs`, make third-party API calls, or set the output values that will be available to subsequent workflow steps by mapping values to the `outputs` object. | ||
|
||
Your app can call `complete()` to indicate that the function’s execution was successful, or `fail()` to signal that the function failed to complete. | ||
|
||
To learn more about listening to custom function executions, see the [Slack API documentation](https://api.slack.com/automation/functions/custom-bolt#listener). | ||
|
||
|
||
</div> | ||
|
||
```js | ||
app.function('sample_function', async ({ client, inputs, fail }) => { | ||
try { | ||
const { user_id } = inputs; | ||
await complete({ outputs: { user_id } }); | ||
} catch (error) { | ||
console.error(error); | ||
fail({ error: `Failed to handle a function request: ${error}` }); | ||
} | ||
}); | ||
``` | ||
|
This file contains 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,24 @@ | ||
--- | ||
title: Responding to interactivity | ||
lang: en | ||
slug: responding-to-interactivity | ||
order: 4 | ||
--- | ||
|
||
<div class="section-content"> | ||
|
||
Interactive elements provided to the user, via message or modal, from within the `function()` method’s callback are associated with that unique `function_executed` event. This association allows for the completion of functions at a later time, like once the user has clicked a button. | ||
|
||
Incoming actions that are associated with a function have the same `inputs`, `complete`, and `fail` utilities as offered by the `function()` method. | ||
|
||
To learn more about responding to interactivity, see the [Slack API documentation](https://api.slack.com/automation/functions/custom-bolt#interactivity). | ||
|
||
</div> | ||
|
||
```js | ||
// If associated with a function, function-specific utilities are made available | ||
app.action('approve_button', async ({ complete, fail }) => { | ||
// Signal the function has completed once the button is clicked | ||
await complete({ outputs: { message: 'Request approved 👍' } }); | ||
}); | ||
``` |
This file contains 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 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 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 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.
these weren't tutorials so weren't showing up here.