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

chore: update project for app settings configuration first #39

Merged
merged 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SLACK_APP_TOKEN=YOUR_SLACK_APP_TOKEN
SLACK_BOT_TOKEN=YOUR_SLACK_BOT_TOKEN
8 changes: 7 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ updates:
interval: "monthly"
labels:
- "npm"
- "dependencies"
- "dependencies"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
labels:
- "dependencies"
92 changes: 55 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Bolt for JavaScript Custom Function Template

This is a Bolt for JavaScript template app used to build custom functions in [Workflow Builder](https://api.slack.com/start#workflow-builder).
This is a Bolt for JavaScript template app used to build custom functions for
use in [Workflow Builder](https://api.slack.com/start#workflow-builder).

## Setup

Expand All @@ -9,66 +10,83 @@ you have permission to install apps. **Please note that the features in this
project require that the workspace be part of
[a Slack paid plan](https://slack.com/pricing).**

### Install the Slack CLI
### Developer Program

To use this template, you need to install and configure the Slack CLI.
Step-by-step instructions can be found in our
[Quickstart Guide](https://api.slack.com/automation/quickstart).
Join the [Slack Developer Program](https://api.slack.com/developer-program) for
exclusive access to sandbox environments for building and testing your apps,
tooling, and resources created to help developers build and grow.

### Clone the Template
## Installation

Start by cloning this repository:
### Create a Slack App

```zsh
# Clone this project onto your machine
$ slack create my-app -t slack-samples/bolt-js-custom-function-template
1. Open [https://api.slack.com/apps/new](https://api.slack.com/apps/new) and
choose "From an app manifest"
2. Choose the workspace you want to install the application to
3. Copy the contents of [manifest.json](./manifest.json) into the text box that
says `*Paste your manifest code here*` (within the JSON tab) and click _Next_
4. Review the configuration and click _Create_
5. Click _Install_ button and _Allow_ on the screen that follows. You'll then be
redirected to the App Settings dashboard.

# Change into the project directory
$ cd my-app
```
### Environment Variables

Before you can run the app, you'll need to store some environment variables.

## Running Your Project Locally
1. Rename `.env.sample` to `.env`
2. Open your apps setting page from
[this list](https://api.slack.com/apps), click _OAuth & Permissions_ in the
left hand menu, then copy the _Bot User OAuth Token_ into your `.env` file
under `SLACK_BOT_TOKEN`
3. Click _Basic Information_ from the left hand menu and follow the steps in the
_App-Level Tokens_ section to create an app-level token with the
`connections:write` scope. Copy that token into your `.env` as
`SLACK_APP_TOKEN`.

While building your app, you can see your changes appear in your workspace in
real-time with `slack run`. You'll know an app is the development version if the
name has the string `(local)` appended.
### Local Project

```zsh
# Run app locally
$ slack run
# Clone this project onto your machine
git clone https://github.com/slack-samples/bolt-js-custom-function-template.git

⚡️ Bolt app is running! ⚡️
```
# Change into this project directory
cd bolt-js-custom-function-template

# Install dependencies
npm install

To stop running locally, press `<CTRL> + C` to end the process.
# Run Bolt server
npm start
```

### Linting

Run ESLint for code formatting and linting:

```zsh
$ npm run lint
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.
## Using Steps in Workflow Builder

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
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.

### `.slack/`
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).

Contains `apps.dev.json` and `config.json`, which include installation details for your project.
## Project Structure

### `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.
`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.

### `slack.json`

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`.
`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.
3 changes: 3 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const { App, LogLevel } = require('@slack/bolt');
const { config } = require('dotenv');

config();

/** Initialization */
const app = new App({
Expand Down Expand Up @@ -35,7 +38,7 @@
],
});
} catch (error) {
console.error(error);

Check warning on line 41 in app.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement

Check warning on line 41 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}` });
}
});
Expand All @@ -56,7 +59,7 @@
text: 'Function completed successfully!',
});
} catch (error) {
console.error(error);

Check warning on line 62 in app.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement

Check warning on line 62 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}` });
}
});
Expand All @@ -65,8 +68,8 @@
(async () => {
try {
await app.start();
console.log('⚡️ Bolt app is running!');

Check warning on line 71 in app.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement

Check warning on line 71 in app.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected console statement
} catch (error) {
console.error('Failed to start the app', error);

Check warning on line 73 in app.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement

Check warning on line 73 in app.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected console statement
}
})();
115 changes: 44 additions & 71 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"url": "https://github.com/slack-samples/bolt-js-custom-function-template/issues"
},
"dependencies": {
"@slack/bolt": "3.17.1-customFunctionBeta.0"
"@slack/bolt": "3.17.1-customFunctionBeta.0",
"dotenv": "~16.4.5"
},
"devDependencies": {
"@slack/cli-hooks": "^1.1.1",
"eslint": "~8.57.0",
"eslint-config-airbnb-base": "~15.0.0",
"eslint-plugin-import": "~2.29.1"
Expand Down
Loading
Loading