Skip to content
Merged
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
111 changes: 87 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,126 @@

This Bolt for Python template demonstrates how to build [AI Apps](https://docs.slack.dev/ai/) in Slack.

Models from [OpenAI](https://openai.com) are used and can be customized for prompts of all kinds.

## Setup

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

### Developer Program

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.

## Installation

#### Create a Slack App
Add this app to your workspace using either the Slack CLI or other development tooling, then read ahead to configuring LLM responses in the **[Providers](#providers)** section.

### Using Slack CLI

Install the latest version of the Slack CLI for your operating system:

- [Slack CLI for macOS & Linux](https://docs.slack.dev/tools/slack-cli/guides/installing-the-slack-cli-for-mac-and-linux/)
- [Slack CLI for Windows](https://docs.slack.dev/tools/slack-cli/guides/installing-the-slack-cli-for-windows/)

You'll also need to log in if this is your first time using the Slack CLI.

```sh
slack login
```

#### Initializing the project

```sh
slack create my-bolt-python-assistant --template slack-samples/bolt-python-assistant-template
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🐍 note: Additional steps are output related to setting up a virtual environment with the current version of this command. I think it's alright to not include these steps here with plans of enhancement upstream!

cd my-bolt-python-assistant
```

#### Creating the Slack app

Use the following command to add your new Slack app to your development workspace. Choose a "local" app environment for upcoming development:

```sh
slack install
```

After the Slack app has been created you're all set to configure the LLM provider!

### Using Terminal

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 to Workspace* and *Allow* on the screen that follows. You'll then be redirected to the App Configuration dashboard.
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 to Workspace_ and _Allow_ on the screen that follows. You'll then be redirected to the App Configuration dashboard.

### Environment Variables
#### Environment Variables

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


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

```sh
SLACK_BOT_TOKEN=YOUR_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`.
```zsh

```sh
SLACK_APP_TOKEN=YOUR_SLACK_APP_TOKEN
```
4. Save your OpenAI key into `.env` under `OPENAI_API_KEY`.
```zsh
OPENAI_API_KEY=YOUR_OPEN_API_KEY
```

#### Initializing the project

### Setup Your Local Project
```zsh
# Clone this project onto your machine
git clone https://github.com/slack-samples/bolt-python-assistant-template.git
```sh
git clone https://github.com/slack-samples/bolt-python-assistant-template.git my-bolt-python-assistant
cd my-bolt-python-assistant
```

# Change into this project directory
cd bolt-python-assistant-template
#### Setup your python virtual environment

# Setup your python virtual environment
```sh
python3 -m venv .venv
source .venv/bin/activate # for Windows OS, .\.venv\Scripts\Activate instead should work
```

# Install the dependencies
#### Install dependencies

```sh
pip install -r requirements.txt
```

## Providers

### OpenAI Setup

Unlock the OpenAI models from your OpenAI account dashboard by clicking [create a new secret key](https://platform.openai.com/api-keys), then save your OpenAI key into the `.env` file as `OPENAI_API_KEY` like so:

```zsh
OPENAI_API_KEY=YOUR_OPEN_API_KEY
```

## Development

### Starting the app

#### Slack CLI

# Start your local server
```sh
slack run
```

#### Terminal

```sh
python3 app.py
```

Start talking to the bot! Start a new DM or thread and click the feedback button when it responds.

#### Linting
```zsh
### Linting

```sh
# Run ruff check from root directory for linting
ruff check

Expand Down Expand Up @@ -88,7 +150,8 @@ Configures the new Slack Assistant features, providing a dedicated side panel UI
- The `assistant_thread_started.py` file, which responds to new app threads with a list of suggested prompts.
- The `message.py` file, which responds to user messages sent to app threads or from the **Chat** and **History** tab with an LLM generated response.

### `ai/`
### `/ai`

The `llm_caller.py` file, which handles OpenAI API integration and message formatting. It includes the `call_llm()` function that sends conversation threads to OpenAI's models.

## App Distribution / OAuth
Expand Down