-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #597 from misscoded/feat-workflow-steps
Add support for Workflow Steps from Apps
- Loading branch information
Showing
15 changed files
with
849 additions
and
141 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
title: Adding or editing workflow steps | ||
lang: en | ||
slug: adding-editing-steps | ||
order: 3 | ||
beta: true | ||
--- | ||
|
||
<div class='section-content'> | ||
|
||
When a builder adds (or later edits) your step in their workflow, your app will receive a `workflow_step_edit` action. The callback assigned to the `edit` property of the `WorkflowStep` configuration object passed in during instantiation will run when this action occurs. | ||
|
||
Whether a builder is adding or editing a step, you need to provide them with a special `workflow_step` modal — a workflow step configuration modal — where step-specific settings are chosen. Since the purpose of this modal is tied to a workflow step's configuration, it has more restrictions than typical modals—most notably, you cannot include `title`, `submit`, or `close` properties in the payload. By default, the `callback_id` used for this modal will be the same as that of the workflow step. | ||
|
||
Within the `edit` callback, the `configure()` utility can be used to easily open your step's configuration modal by passing in an object with your view's `blocks`. To disable configuration save before certain conditions are met, pass in `submit_disabled` with a value of `true`. | ||
|
||
To learn more about workflow step configuration modals, [read the documentation](https://api.slack.com/reference/workflows/configuration-view). | ||
|
||
</div> | ||
|
||
```javascript | ||
const ws = new WorkflowStep('add_task', { | ||
edit: async ({ ack, step, configure }) => { | ||
await ack(); | ||
|
||
const blocks = [ | ||
{ | ||
'type': 'input', | ||
'block_id': 'task_name_input', | ||
'element': { | ||
'type': 'plain_text_input', | ||
'action_id': 'name', | ||
'placeholder': { | ||
'type': 'plain_text', | ||
'text': 'Add a task name' | ||
} | ||
}, | ||
'label': { | ||
'type': 'plain_text', | ||
'text': 'Task name' | ||
} | ||
}, | ||
{ | ||
'type': 'input', | ||
'block_id': 'task_description_input', | ||
'element': { | ||
'type': 'plain_text_input', | ||
'action_id': 'description', | ||
'placeholder': { | ||
'type': 'plain_text', | ||
'text': 'Add a task description' | ||
} | ||
}, | ||
'label': { | ||
'type': 'plain_text', | ||
'text': 'Task description' | ||
} | ||
}, | ||
]; | ||
|
||
await configure({ blocks }); | ||
}, | ||
save: async ({ ack, step, update }) => {}, | ||
execute: async ({ step, complete, fail }) => {}, | ||
}); | ||
``` |
This file was deleted.
Oops, something went wrong.
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,31 @@ | ||
--- | ||
title: Creating a workflow step | ||
lang: en | ||
slug: creating-steps | ||
order: 2 | ||
beta: true | ||
--- | ||
|
||
<div class='section-content'> | ||
|
||
To create a new workflow step, Bolt provides the `WorkflowStep` class. | ||
|
||
When instantiating a new `WorkflowStep`, pass in the step's `callback_id`, which is defined in your app configuration, and a step configuration object. | ||
|
||
The configuration object for a `WorkflowStep` contains three properties: `edit`, `save`, and `execute`. Each of these properties must either hold a value of a single callback or an array of callbacks. All callbacks have access to a `step` object that contains information about the workflow step event, as well as one or more utility functions. | ||
|
||
After instantiating your workflow step, pass it the instance into `app.step()`. Behind the scenes, your app will listen and respond to the workflow step’s events using the callbacks provided in the configuration object. | ||
|
||
</div> | ||
|
||
```javascript | ||
const { WorkflowStep } = require('@slack/bolt'); | ||
|
||
const ws = new WorkflowStep('add_task', { | ||
edit: async ({ ack, step, configure }) => {}, | ||
save: async ({ ack, step, update }) => {}, | ||
execute: async ({ step, complete, fail }) => {}, | ||
}); | ||
|
||
app.step(ws); | ||
``` |
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,59 @@ | ||
--- | ||
title: Saving the step configuration | ||
lang: en | ||
slug: saving-steps | ||
order: 4 | ||
beta: true | ||
--- | ||
|
||
<div class='section-content'> | ||
|
||
When the workflow step's configuration has been saved (using the step configuration modal from the `edit` callback), your app will listen for the `view_submission` event. The method assigned to the `save` property of the `WorkflowStep` configuration object passed in during instantiation will run when this event occurs. | ||
|
||
Once the configuration for the workflow step has been determined, builders often use that configuration to craft the custom outputs and behavior that occurs when the end user executes the step. | ||
|
||
Within the `save` callback, the `update()` method can be used to save the builder's step configuration by passing in the following arguments: `inputs`, `outputs`, `step_name` and `step_image_url`. | ||
|
||
`inputs` is an object representing the data your app expects to receive from the user upon workflow step execution. To use variables that were collected earlier in the workflow, you can include handlebar-style syntax (`{{ variable }}`). During the workflow step's execution, those variables will be replaced with their actual runtime value. | ||
|
||
`outputs` is an array of objects containing data that your app will provide upon the workflow step's completion. Outputs can then be used in subsequent steps of the workflow. | ||
|
||
`step_name` and `step_image_url` are available for a more customized look and feel of your workflow step. | ||
|
||
To learn more about how to structure these parameters, [read the documentation](https://api.slack.com/reference/workflows/workflow_step). | ||
|
||
</div> | ||
|
||
```javascript | ||
const ws = new WorkflowStep('add_task', { | ||
edit: async ({ ack, step, configure }) => {}, | ||
save: async ({ ack, step, update }) => { | ||
await ack(); | ||
|
||
const { values } = view.state; | ||
const taskName = values.task_name_input.name; | ||
const taskDescription = values.task_description_input.description; | ||
|
||
const inputs = { | ||
taskName: { value: taskName }, | ||
taskDescription: { value: taskDescription } | ||
}; | ||
|
||
const outputs = [ | ||
{ | ||
type: 'text', | ||
name: 'taskName', | ||
label: 'Task name', | ||
}, | ||
{ | ||
type: 'text', | ||
name: 'taskDescription', | ||
label: 'Task description', | ||
} | ||
]; | ||
|
||
await update({ inputs, outputs }); | ||
}, | ||
execute: async ({ step, complete, fail }) => {}, | ||
}); | ||
``` |
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
Oops, something went wrong.