Skip to content

Commit

Permalink
Incorporate PR suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
misscoded committed Jan 11, 2024
1 parent 4404efa commit 4623120
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 39 deletions.
5 changes: 0 additions & 5 deletions .env.sample

This file was deleted.

24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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 `<CTRL> + C` to end the process.
Expand All @@ -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.
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`.
12 changes: 6 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -41,7 +38,7 @@ app.function('sample_function', async ({ client, inputs, fail }) => {
});
} catch (error) {
console.error(error);

Check warning on line 40 in app.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement

Check warning on line 40 in app.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected console statement
fail({ error: `Failed to handle a function request (error: ${error}` });
fail({ error: `Failed to handle a function request: ${error}` });
}
});

Expand All @@ -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);

Check warning on line 61 in app.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement

Check warning on line 61 in app.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected console statement
fail({ error: `Failed to handle a function request (error: ${error}` });
fail({ error: `Failed to handle a function request: ${error}` });
}
});

Expand Down
43 changes: 20 additions & 23 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
}
},
"settings": {
"event_subscriptions": {
"bot_events": []
},
"interactivity": {
"is_enabled": true
},
Expand All @@ -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"
}
}
}
}
}
}

0 comments on commit 4623120

Please sign in to comment.