Skip to content
Open
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
55 changes: 46 additions & 9 deletions docs/content/tutorial/ai-chatbot.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,66 @@ If you'd rather skip the tutorial and just head straight to the code, you can us
2. Select the workspace you want to install the application in.
3. Copy the contents of the [`manifest.json`](https://github.com/slack-samples/bolt-python-ai-chatbot/blob/main/manifest.json) file 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. You're now in your app configuration's **Basic Information** page. Navigate to the **Install App** link in the left nav and click **Install to Workspace*, then **Allow** on the screen that follows.
5. You're now in your app configuration's **Basic Information** page. Navigate to the **Install App** link in the left nav and click **Install to Workspace**, then **Allow** on the screen that follows.

### Obtaining and storing your environment variables {#environment-variables}

Before you'll be able to successfully run the app, you'll need to first obtain and set some environment variables.

#### Slack tokens {#slack-tokens}

From your app's page on [app settings](https://api.slack.com/apps) collect an app and bot token:

1. On the **Install App** page, copy your **Bot User OAuth Token**. You will store this in your environment as `SLACK_BOT_TOKEN` (we'll get to that next).
2. Navigate to **Basic Information** and in the **App-Level Tokens** section , click **Generate Token and Scopes**. Add the [`connections:write`](https://docs.slack.dev/reference/scopes/connections.write) scope, name the token, and click **Generate**. (For more details, refer to [understanding OAuth scopes for bots](https://docs.slack.dev/authentication/tokens#bot)). Copy this token. You will store this in your environment as `SLACK_APP_TOKEN`.

To store your tokens and environment variables, run the following commands in the terminal. Replace the placeholder values with your bot and app tokens collected above, as well as the key or keys for the AI provider or providers you want to use:
To store your tokens and environment variables, run the following commands in the terminal. Replace the placeholder values with your bot and app tokens collected above:

**For macOS**

```bash
export SLACK_BOT_TOKEN=<your-bot-token>
export SLACK_APP_TOKEN=<your-app-token>
export OPENAI_API_KEY=<your-api-key>
export ANTHROPIC_API_KEY=<your-api-key>
```

**For Windows**

```bash
set SLACK_BOT_TOKEN=<your-bot-token>
set SLACK_APP_TOKEN=<your-app-token>
set OPENAI_API_KEY=<your-api-key>
set ANTHROPIC_API_KEY=<your-api-key>
```

#### Provider tokens {#provider-tokens}

Models from different AI providers are available if the corresponding environment variable is added as shown in the sections below.

##### Anthropic {#anthropic}

To interact with Anthropic models, navigate to your Anthropic account dashboard to [create an API key](https://console.anthropic.com/settings/keys), then export the key as follows:

```zsh
export ANTHROPIC_API_KEY=<your-api-key>
```

##### Google Cloud Vertex AI {#google-cloud-vertex-ai}

To use Google Cloud Vertex AI, [follow this quick start](https://cloud.google.com/vertex-ai/generative-ai/docs/start/quickstarts/quickstart-multimodal#expandable-1) to create a project for sending requests to the Gemini API, then gather [Application Default Credentials](https://cloud.google.com/docs/authentication/provide-credentials-adc) with the strategy to match your development environment.

Once your project and credentials are configured, export environment variables to select from Gemini models:

```zsh
export VERTEX_AI_PROJECT_ID=<your-project-id>
export VERTEX_AI_LOCATION=<location-to-deploy-model>
```

The project location can be located under the **Region** on the [Vertex AI](https://console.cloud.google.com/vertex-ai) dashboard, as well as more details about available Gemini models.

##### OpenAI {#openai}

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

```zsh
export OPENAI_API_KEY=<your-api-key>
```

## Setting up and running your local project {#configure-project}
Expand All @@ -69,12 +104,14 @@ cd bolt-python-ai-chatbot
Start your Python virtual environment:

**For macOS**

```bash
python3 -m venv .venv
source .venv/bin/activate
```

**For Windows**

```bash
py -m venv .venv
.venv\Scripts\activate
Expand Down Expand Up @@ -123,7 +160,7 @@ Under **Then, do these things**, click **Add steps** and complete the following:

![Send a message](/img/tutorials/ai-chatbot/3.png)

We'll add two more steps under the **Then, do these things** section.
We'll add two more steps under the **Then, do these things** section.

First, scroll to the bottom of the list of steps and choose **Custom**, then choose **Bolty** and **Bolty Custom Function**. In the **Channel** drop-down menu, select **Channel that the user joined**. Click **Save**.

Expand All @@ -142,7 +179,7 @@ When finished, click **Finish Up**, then click **Publish** to make the workflow

### Summarizing recent conversations {#summarize}

In order for Bolty to provide summaries of recent conversation in a channel, Bolty _must_ be a member of that channel.
In order for Bolty to provide summaries of recent conversation in a channel, Bolty _must_ be a member of that channel.

1. Invite Bolty to a channel that you are able to leave and rejoin (for example, not the **#general** channel or a private channel someone else created) by mentioning the app in the channel — i.e., tagging **@Bolty** in the channel and sending your message.
2. Slackbot will prompt you to either invite Bolty to the channel, or do nothing. Click **Invite Them**. Now when new users join the channel, the workflow you just created will be kicked off.
Expand Down Expand Up @@ -189,7 +226,7 @@ def handle_summary_function_callback(

To ask Bolty a question, you can chat with Bolty in any channel the app is in. Use the `\ask-bolty` slash command to provide a prompt for Bolty to answer. Note that Bolty is currently not supported in threads.

You can also navigate to **Bolty** in your **Apps** list and select the **Messages** tab to chat with Bolty directly.
You can also navigate to **Bolty** in your **Apps** list and select the **Messages** tab to chat with Bolty directly.

![Ask Bolty](/img/tutorials/ai-chatbot/8.png)

Expand Down
Loading