Skip to content
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: document custom step usage #2198

Merged
merged 34 commits into from
Aug 14, 2024
Merged

docs: document custom step usage #2198

merged 34 commits into from
Aug 14, 2024

Conversation

WilliamBergamin
Copy link
Contributor

@WilliamBergamin WilliamBergamin commented Aug 13, 2024

This PR aims to provide documentation for custom step usage in the bolt framework

Testing

  1. Pull this branch
  2. cd ./docs
  3. npm install
  4. npm start
  5. http://localhost:3000/bolt-js/concepts/custom-steps

Requirements (place an x in each [ ])

@WilliamBergamin WilliamBergamin added the docs M-T: Documentation work only label Aug 13, 2024
@WilliamBergamin WilliamBergamin self-assigned this Aug 13, 2024
@@ -0,0 +1,101 @@
---
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need help with the translation 🙏

Copy link

codecov bot commented Aug 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.59%. Comparing base (91b3519) to head (6779dbb).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2198   +/-   ##
=======================================
  Coverage   81.59%   81.59%           
=======================================
  Files          19       19           
  Lines        1646     1646           
  Branches      464      464           
=======================================
  Hits         1343     1343           
  Misses        194      194           
  Partials      109      109           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@srajiang srajiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

English bits look good to me, left one small comment. I've not tested with these instructs though, so I'll let someone else approve.

README.md Outdated Show resolved Hide resolved
@WilliamBergamin
Copy link
Contributor Author

Removed the existing docs/content/custom-functions documentation

Reason for this is that it included information that was not bolt specific and duplicated in api.slack.com. It also seems like overkill to have a dedicated sidebar section for custom steps

@WilliamBergamin WilliamBergamin changed the base branch from main to feat-functions August 13, 2024 19:46
Copy link
Contributor

@filmaj filmaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job! Left some suggestions.

docs/content/basic/custom-steps.md Outdated Show resolved Hide resolved
docs/content/basic/custom-steps.md Show resolved Hide resolved
<summary>
Listening to custom step actions
</summary>
Your app can listen to user actions, like button clicks, created from `custom steps` using the `action` method.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested tweak to the introduction here:

Suggested change
Your app can listen to user actions, like button clicks, created from `custom steps` using the `action` method.
Your app's custom steps may create interactivity points for users, for example:
- Post a message with a button
- [Open a modal view](creating-modals)
If such interaction points originate from a custom step execution, the events sent to your app representing the end-user interaction with these points are considered to be _function-scoped interactivity events_. These interactivity events can be handled by your app using the same concepts we covered earlier, such as [Listening to actions](action-listening) or [Listening to views](view-submissions).
The one addition that function-scoped interactivity events have is they will contain data related to the `function_executed` event they were spawned from, such as custom step input data and access to `complete()` and `fail()` handlers to manage step control flow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good 🙇 provides more information without duplicating documentation from api.slack.com

I had to adapt this slightly to because open modal views are not yet supported, but hopefully soon

docs/content/basic/custom-steps.md Outdated Show resolved Hide resolved
docs/content/basic/custom-steps.md Outdated Show resolved Hide resolved
docs/content/basic/custom-steps.md Outdated Show resolved Hide resolved
Copy link
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super solid! 🏆 🚀 I left a few comments on wording and a suggestion on introducing this ✨ as a concept ✨ but don't think those are blocking.

Removing ack from the function listener might be though! 😳 I'm finding this won't transpile when collected from the listener arguments...

I also agree with a lot of the suggestions from @filmaj and think this'll be good to merge once you think so!

Comment on lines 16 to 18
app.function('sample_custom_step', async ({ ack, inputs, complete, fail, logger }) => {
try {
await ack();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
app.function('sample_custom_step', async ({ ack, inputs, complete, fail, logger }) => {
try {
await ack();
app.function('sample_custom_step', async ({ inputs, complete, fail, logger }) => {
try {

Removing the ack here since this isn't provided for function executions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to keep it in the docs, there are a number of issues opened related to calling ack before executing custom logic

Keeping this in hopes that it will help developers avoid a bug 🙏

We can remove it in a follow up PR as well 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the function_executed events are actually different from other events and can't use ack at all!

Within JavaScript code this is undefined within the listener so this call will error 😬 It's not so clear from this picture but the hover hint is hinting at this in a TypeScript project:

undefined

Comment on lines 47 to 49
app.function('sample_function', async ({ ack, client, inputs, fail, logger }) => {
try {
await ack();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
app.function('sample_function', async ({ ack, client, inputs, fail, logger }) => {
try {
await ack();
app.function('sample_function', async ({ client, inputs, fail, logger }) => {
try {

slug: /concepts/custom-steps
---

Your app can use the `function()` method to listen to incoming [custom step requests](https://api.slack.com/automation/functions/custom-bolt). 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://api.slack.com/concepts/manifests#functions) definition. Custom steps must be finalized using the `complete()` or `fail()` listener arguments to notify Slack that your app has processed the request.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Your app can use the `function()` method to listen to incoming [custom step requests](https://api.slack.com/automation/functions/custom-bolt). 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://api.slack.com/concepts/manifests#functions) definition. Custom steps must be finalized using the `complete()` or `fail()` listener arguments to notify Slack that your app has processed the request.
Your app can use the `function()` listener to listen to incoming [custom step requests](https://api.slack.com/automation/functions/custom-bolt). Custom steps are used in Workflow Builder to build workflows.
Adding a custom step starts with a definition in [the app manifest](https://api.slack.com/concepts/manifests#functions) and a `function()` listener listening for the `callback_id` of that function. Upon function execution the listener is called and can run whatever code, but must finish with either the `complete()` or `fail()` listener argument to end the step:

Hoping to set a bit more context for custom steps in just the first paragraph! Also wanting to frame the following one as more instruction instead of reference, but feel free to change it or ignore 🙏

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also not certain about the "method" vs "listener" naming!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of the documentation uses the method terminology instead of the listener

I think its better to be consistent and stick to method

We can send a follow up PR to update all the terms 👍

docs/content/basic/custom-steps.md Outdated Show resolved Hide resolved
Comment on lines -13 to -39
```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"
}
}
}
}
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it'd be nice to include this as <details> in the docs so the inputs and complete.outputs in the examples have context, but not necessary 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then I'm not sure if that'd also mean referencing function_runtime settings and the function_executed event 😓

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea 💯 done ✅

Base automatically changed from feat-functions to main August 14, 2024 18:22
@WilliamBergamin WilliamBergamin requested a review from zimeg August 14, 2024 19:26
Copy link
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome saucesome! 😋 Thanks for addressing the feedback! 🚀

@WilliamBergamin WilliamBergamin merged commit 9839f0c into main Aug 14, 2024
17 checks passed
@WilliamBergamin WilliamBergamin deleted the document-custom-steps branch August 14, 2024 19:36
@zimeg zimeg added this to the 3.21.1 milestone Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs M-T: Documentation work only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants