Skip to content

Commit dfb2ec8

Browse files
committed
chore: merge w ai-apps
2 parents 9fb532b + 20419a8 commit dfb2ec8

8 files changed

Lines changed: 28 additions & 15 deletions

File tree

.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

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ env*/
1616
venv/
1717
.venv*
1818
.env*
19+
!.env.sample
1920

2021
# codecov / coverage
2122
.coverage

README.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,25 @@ Join the [Slack Developer Program](https://api.slack.com/developer-program) for
1717
4. Review the configuration and click *Create*
1818
5. Click *Install to Workspace* and *Allow* on the screen that follows. You'll then be redirected to the App Configuration dashboard.
1919

20-
#### Environment Variables
20+
### Environment Variables
21+
2122
Before you can run the app, you'll need to store some environment variables.
2223

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

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`.
2631
```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
3333
```
34+
4. Save your OpenAI key into `.env` under `OPENAI_API_KEY`.
35+
```zsh
36+
OPENAI_API_KEY=YOUR_OPEN_API_KEY
37+
```
38+
3439

3540
### Setup Your Local Project
3641
```zsh
@@ -84,7 +89,7 @@ Configures the new Slack Assistant features, providing a dedicated side panel UI
8489
* The `@assistant.thread_started` listener receives an event when users start new app thread.
8590
* The `@assistant.user_message` listener processes user messages in app threads or from the app **Chat** and **History** tab.
8691

87-
`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.
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.
8893

8994
## App Distribution / OAuth
9095

app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99

1010
from listeners import register_listeners
1111

12-
1312
# Load environment variables
14-
load_dotenv()
13+
load_dotenv(dotenv_path=".env", override=False)
1514

1615
# Initialization
1716
logging.basicConfig(level=logging.DEBUG)

listeners/assistant/assistant.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
from ..llm_caller import call_llm
1010
from ..views.feedback_block import create_feedback_block
11+
from ai.llm_caller import call_llm
12+
1113

1214
# Refer to https://tools.slack.dev/bolt-python/concepts/assistant/ for more details
1315
assistant = Assistant()
@@ -86,9 +88,9 @@ def respond_in_assistant_thread(
8688
"""
8789
try:
8890
channel_id = payload["channel"]
89-
team_id = payload["team"]
91+
team_id = context.team_id
9092
thread_ts = payload["thread_ts"]
91-
user_id = payload["user"]
93+
user_id = context.user_id
9294
user_message = payload["text"]
9395

9496
set_status(

listeners/events/app_mentioned.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from slack_bolt import Say
44
from slack_sdk import WebClient
55

6-
from ..llm_caller import call_llm
6+
from ai.llm_caller import call_llm
77
from ..views.feedback_block import create_feedback_block
88

99

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ openai
77
pytest
88
flake8
99
black
10+
python-dotenv==1.1.1

0 commit comments

Comments
 (0)