Skip to content

Commit d4ae3aa

Browse files
authored
Initial commit
0 parents  commit d4ae3aa

23 files changed

+2603
-0
lines changed

.env.sample

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SLACK_APP_TOKEN=YOUR_SLACK_APP_TOKEN
2+
SLACK_BOT_TOKEN=YOUR_SLACK_BOT_TOKEN
3+
# SLACK_API_URL=YOUR_SLACK_API_URL
4+
# This template uses OpenAI, but you can use any other provider!
5+
OPENAI_API_KEY=YOUR_OPENAI_API_KEY

.github/CODEOWNERS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Code owners are the default owners for everything in
2+
# this repository. The owners listed below will be requested for
3+
# review when a pull request is opened.
4+
# To add code owner(s), uncomment the line below and
5+
# replace the @global-owner users with their GitHub username(s).
6+
# * @global-owner1 @global-owner2

.github/dependabot.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "npm"
4+
directory: "/"
5+
schedule:
6+
interval: "monthly"
7+
labels:
8+
- "npm"
9+
- "dependencies"
10+
- package-ecosystem: "github-actions"
11+
directory: "/"
12+
schedule:
13+
interval: "monthly"

.github/workflows/lint.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 5
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
node-version:
17+
- 18.x
18+
- 20.x
19+
- 22.x
20+
steps:
21+
- uses: actions/checkout@v5
22+
- name: Use Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v5
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
- name: Install packages
27+
run: npm install
28+
- name: Run the lint
29+
run: npm run lint
30+
- name: Run the typechecker
31+
run: npm run check

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/node_modules
2+
.DS_Store
3+
.env*
4+
!.env.sample

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Slack Technologies, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# AI Agent App Template (Bolt for JavaScript)
2+
3+
This Bolt for JavaScript template demonstrates how to build [AI Apps](https://docs.slack.dev/ai/) in Slack.
4+
5+
Models from [OpenAI](https://openai.com) are used and can be customized for prompts of all kinds.
6+
7+
## Setup
8+
9+
Before getting started, make sure you have a development workspace where you have permissions to install apps. If you don’t have one setup, go ahead and [create one](https://slack.com/create).
10+
11+
### Developer Program
12+
13+
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 you build and grow.
14+
15+
## Installation
16+
17+
### Create a Slack App
18+
19+
1. Open [https://api.slack.com/apps/new](https://api.slack.com/apps/new) and
20+
choose "From an app manifest"
21+
2. Choose the workspace you want to install the application to
22+
3. Copy the contents of [manifest.json](./manifest.json) into the text box that
23+
says `*Paste your manifest code here*` (within the JSON tab) and click _Next_
24+
4. Review the configuration and click _Create_
25+
5. You'll then be redirected to App Settings. Visit the **Install App** page and install your app.
26+
27+
### Environment Variables
28+
29+
Before you can run the app, you'll need to store some environment variables.
30+
31+
32+
1. Rename `.env.sample` to `.env`.
33+
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`.
34+
```zsh
35+
SLACK_BOT_TOKEN=YOUR_SLACK_BOT_TOKEN
36+
```
37+
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`.
38+
```zsh
39+
SLACK_APP_TOKEN=YOUR_SLACK_APP_TOKEN
40+
```
41+
4. Save your OpenAI key into `.env` under `OPENAI_API_KEY`.
42+
```zsh
43+
OPENAI_API_KEY=YOUR_OPEN_API_KEY
44+
```
45+
46+
47+
### Local Project
48+
49+
```zsh
50+
# Clone this project onto your machine
51+
git clone https://github.com/slack-samples/bolt-js-assistant-template.git
52+
53+
# Change into this project directory
54+
cd bolt-js-assistant-template
55+
56+
# Install dependencies
57+
npm install
58+
59+
# Run Bolt server
60+
npm start
61+
```
62+
63+
### Linting
64+
65+
```zsh
66+
# Run lint for code formatting and linting
67+
npm run lint
68+
```
69+
70+
## Project Structure
71+
72+
### `manifest.json`
73+
74+
`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.
75+
76+
### `app.js`
77+
78+
`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.

ai/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { OpenAI } from 'openai';
2+
3+
// LLM system prompt
4+
export const DEFAULT_SYSTEM_CONTENT = `You're an assistant in a Slack workspace.
5+
Users in the workspace will ask you to help them write something or to think better about a specific topic.
6+
You'll respond to those questions in a professional way.
7+
When you include markdown text, convert them to Slack compatible ones.
8+
When a prompt has Slack's special syntax like <@USER_ID> or <#CHANNEL_ID>, you must keep them as-is in your response.`;
9+
10+
// OpenAI LLM client
11+
export const openai = new OpenAI({
12+
apiKey: process.env.OPENAI_API_KEY,
13+
});

app.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import 'dotenv/config';
2+
import { App, LogLevel } from '@slack/bolt';
3+
import { registerListeners } from './listeners/index.js';
4+
5+
// Initialize the Bolt app
6+
const app = new App({
7+
token: process.env.SLACK_BOT_TOKEN,
8+
appToken: process.env.SLACK_APP_TOKEN,
9+
socketMode: true,
10+
logLevel: LogLevel.DEBUG,
11+
clientOptions: {
12+
slackApiUrl: process.env.SLACK_API_URL || 'https://slack.com/api',
13+
},
14+
});
15+
16+
// Register the action and event listeners
17+
registerListeners(app);
18+
19+
// Start the Bolt app
20+
(async () => {
21+
try {
22+
await app.start();
23+
app.logger.info('⚡️ Bolt app is running!');
24+
} catch (error) {
25+
app.logger.error('Failed to start the app', error);
26+
}
27+
})();

biome.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
3+
"formatter": {
4+
"enabled": true,
5+
"formatWithErrors": false,
6+
"includes": ["**"],
7+
"attributePosition": "auto",
8+
"indentStyle": "space",
9+
"indentWidth": 2,
10+
"lineWidth": 120,
11+
"lineEnding": "lf"
12+
},
13+
"javascript": {
14+
"formatter": {
15+
"quoteStyle": "single"
16+
}
17+
},
18+
"linter": {
19+
"enabled": true,
20+
"rules": {
21+
"recommended": true
22+
}
23+
},
24+
"assist": {
25+
"actions": {
26+
"source": {
27+
"organizeImports": "on"
28+
}
29+
}
30+
},
31+
"vcs": {
32+
"enabled": true,
33+
"clientKind": "git",
34+
"useIgnoreFile": true
35+
}
36+
}

0 commit comments

Comments
 (0)