From 4623120f3d6469dc8f340ddc981b482c64f4753c Mon Sep 17 00:00:00 2001 From: Alissa Renz Date: Thu, 11 Jan 2024 14:52:39 -0800 Subject: [PATCH] Incorporate PR suggestions --- .env.sample | 5 ----- README.md | 24 +++++++++++++++++++----- app.js | 12 ++++++------ manifest.json | 43 ++++++++++++++++++++----------------------- 4 files changed, 45 insertions(+), 39 deletions(-) delete mode 100644 .env.sample diff --git a/.env.sample b/.env.sample deleted file mode 100644 index b5618fa..0000000 --- a/.env.sample +++ /dev/null @@ -1,5 +0,0 @@ -SLACK_CLIENT_ID=YOUR_SLACK_CLIENT_ID -SLACK_CLIENT_SECRET=YOUR_SLACK_CLIENT_SECRET -SLACK_SIGNING_SECRET=YOUR_SLACK_SIGNING_SECRET -SLACK_APP_TOKEN=YOUR_SLACK_APP_TOKEN -SLACK_BOT_TOKEN=YOUR_SLACK_BOT_TOKEN \ No newline at end of file diff --git a/README.md b/README.md index 7314a26..e023276 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Bolt for JavaScript Automation Template App +# Bolt for JavaScript Custom Function Template -This is a generic Bolt for JavaScript template app intended to be used as a foundation upon which to build custom functions for use in Workflow Builder. +This is a Bolt for JavaScript template app used to build custom functions in [Workflow Builder](https://api.slack.com/start#workflow-builder). ## Setup @@ -37,7 +37,7 @@ name has the string `(local)` appended. # Run app locally $ slack run -Connected, awaiting events +⚡️ Bolt app is running! ⚡️ ``` To stop running locally, press ` + C` to end the process. @@ -49,12 +49,26 @@ Run ESLint for code formatting and linting: $ npm run lint ``` +## Using Functions in Workflow Builder +With your server running, your function is now ready for use in [Workflow Builder](https://api.slack.com/start#workflow-builder)! Add it as a custom step in a new or existing workflow, then run the workflow while your app is running. + +For more information on creating workflows and adding custom steps, read more [here](https://slack.com/help/articles/17542172840595-Create-a-new-workflow-in-Slack). + ## Project Structure +### `.slack/` + +Contains `apps.dev.json` and `config.json`, which include installation details for your project. + +### `app.js` + +`app.js` is the entry point for the application and is the file you'll run to start the server. This project aims to keep this file as thin as possible, primarily using it as a way to route inbound requests. + ### `manifest.json` `manifest.json` is a configuration for Slack apps. With a manifest, you can create an app with a pre-defined configuration, or adjust the configuration of an existing app. -### `app.js` +### `slack.json` -`app.js` is the entry point for the application and is the file you'll run to start the server. This project aims to keep this file as thin as possible, primarily using it as a way to route inbound requests. \ No newline at end of file +Used by the Slack CLI to interact with the project's SDK dependencies. It contains +script hooks that are executed by the CLI and implemented by `@slack/cli-hooks`. \ No newline at end of file diff --git a/app.js b/app.js index 2f89688..edf8859 100644 --- a/app.js +++ b/app.js @@ -9,9 +9,6 @@ const app = new App({ socketMode: true, appToken: process.env.SLACK_APP_TOKEN, logLevel: LogLevel.DEBUG, - // To opt-out of using the JIT token to make `client` calls in - // function-related callbacks, set attachFunctionToken to false. - // attachFunctionToken: false, }); /** Sample Function Listener */ @@ -41,7 +38,7 @@ app.function('sample_function', async ({ client, inputs, fail }) => { }); } catch (error) { console.error(error); - fail({ error: `Failed to handle a function request (error: ${error}` }); + fail({ error: `Failed to handle a function request: ${error}` }); } }); @@ -50,16 +47,19 @@ app.action('sample_button', async ({ body, client, complete, fail }) => { const { channel, message, interactivity: { interactor } } = body; try { + // Functions should be marked as successfully completed using `complete` or + // as having failed using `fail`, else they'll remain in an 'In progress' state. + // Learn more at https://api.slack.com/automation/interactive-messages await complete({ outputs: { user_id: interactor.id } }); - client.chat.update({ + await client.chat.update({ channel: channel.id, ts: message.ts, text: 'Function completed successfully!', }); } catch (error) { console.error(error); - fail({ error: `Failed to handle a function request (error: ${error}` }); + fail({ error: `Failed to handle a function request: ${error}` }); } }); diff --git a/manifest.json b/manifest.json index 7580625..9d41a45 100644 --- a/manifest.json +++ b/manifest.json @@ -21,9 +21,6 @@ } }, "settings": { - "event_subscriptions": { - "bot_events": [] - }, "interactivity": { "is_enabled": true }, @@ -33,27 +30,27 @@ }, "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" + "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 to used the function", + "is_required": true, + "name": "user_id" + } } - } } } } \ No newline at end of file