You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add ai-enabled features text streaming, loading states, and feedback buttons (#23)
Co-authored-by: Maria Alejandra <104795114+srtaalej@users.noreply.github.com>
Co-authored-by: Eden Zimbelman <eden.zimbelman@salesforce.com>
Co-authored-by: Ale Mercado <maria.mercado@slack-corp.com>
Copy file name to clipboardExpand all lines: README.md
+30-13Lines changed: 30 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
-
# App Agent & Assistant Template (Bolt for Python)
1
+
# AI Agent App Template (Bolt for Python)
2
2
3
-
This Bolt for Python template demonstrates how to build [Agents & Assistants](https://api.slack.com/docs/apps/ai) in Slack.
3
+
This Bolt for Python template demonstrates how to build [AI Apps](https://docs.slack.dev/ai/) in Slack.
4
4
5
5
## Setup
6
6
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).
@@ -17,20 +17,25 @@ Join the [Slack Developer Program](https://api.slack.com/developer-program) for
17
17
4. Review the configuration and click *Create*
18
18
5. Click *Install to Workspace* and *Allow* on the screen that follows. You'll then be redirected to the App Configuration dashboard.
19
19
20
-
#### Environment Variables
20
+
### Environment Variables
21
+
21
22
Before you can run the app, you'll need to store some environment variables.
22
23
23
-
1. Open your app configuration page from this list, click **OAuth & Permissions** in the left hand menu, then copy the Bot User OAuth Token. You will store this in your environment as `SLACK_BOT_TOKEN`.
24
-
2. 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 this token. You will store this in your environment as `SLACK_APP_TOKEN`.
25
24
25
+
1. Rename `.env.sample` to `.env`.
26
+
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`.
27
+
```zsh
28
+
SLACK_BOT_TOKEN=YOUR_SLACK_BOT_TOKEN
29
+
```
30
+
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`.
26
31
```zsh
27
-
# Replace with your app token and bot token
28
-
# For Windows OS, env:SLACK_BOT_TOKEN = <your-bot-token> works
29
-
export SLACK_BOT_TOKEN=<your-bot-token>
30
-
export SLACK_APP_TOKEN=<your-app-token>
31
-
# This sample uses OpenAI's API by default, but you can switch to any other solution!
32
-
export OPENAI_API_KEY=<your-openai-api-key>
32
+
SLACK_APP_TOKEN=YOUR_SLACK_APP_TOKEN
33
33
```
34
+
4. Save your OpenAI key into `.env` under `OPENAI_API_KEY`.
35
+
```zsh
36
+
OPENAI_API_KEY=YOUR_OPEN_API_KEY
37
+
```
38
+
34
39
35
40
### Setup Your Local Project
36
41
```zsh
@@ -51,6 +56,8 @@ pip install -r requirements.txt
51
56
python3 app.py
52
57
```
53
58
59
+
Start talking to the bot! Start a new DM or thread and click the feedback button when it responds.
60
+
54
61
#### Linting
55
62
```zsh
56
63
# Run flake8 from root directory for linting
@@ -72,15 +79,25 @@ black .
72
79
73
80
### `/listeners`
74
81
75
-
Every incoming request is routed to a "listener". Inside this directory, we group each listener based on the Slack Platform feature used, so `/listeners/events` handles incoming events, `/listeners/shortcuts` would handle incoming [Shortcuts](https://api.slack.com/interactivity/shortcuts) requests, and so on.
82
+
Every incoming request is routed to a "listener". This directory groups each listener based on the Slack Platform feature used, so `/listeners/events` handles incoming events, `/listeners/shortcuts` would handle incoming [Shortcuts](https://docs.slack.dev/interactivity/implementing-shortcuts/) requests, and so on.
83
+
84
+
**`/listeners/assistant`**
85
+
86
+
Configures the new Slack Assistant features, providing a dedicated side panel UI for users to interact with the AI chatbot. This module includes:
87
+
88
+
`assistant.py`, which contains two listeners:
89
+
* The `@assistant.thread_started` listener receives an event when users start new app thread.
90
+
* The `@assistant.user_message` listener processes user messages in app threads or from the app **Chat** and **History** tab.
91
+
92
+
`ai/llm_caller.py`, which handles OpenAI API integration and message formatting. It includes the `call_llm()` function that sends conversation threads to OpenAI's models.
76
93
77
94
## App Distribution / OAuth
78
95
79
96
Only implement OAuth if you plan to distribute your application across multiple workspaces. A separate `app_oauth.py` file can be found with relevant OAuth settings.
80
97
81
98
When using OAuth, Slack requires a public URL where it can send requests. In this template app, we've used [`ngrok`](https://ngrok.com/download). Checkout [this guide](https://ngrok.com/docs#getting-started-expose) for setting it up.
82
99
83
-
Start `ngrok` to access the app on an external network and create a redirect URL for OAuth.
100
+
Start `ngrok` to access the app on an external network and create a redirect URL for OAuth.
0 commit comments