diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..ce5d7e4 --- /dev/null +++ b/.env.sample @@ -0,0 +1,5 @@ +SLACK_APP_TOKEN=YOUR_SLACK_APP_TOKEN +SLACK_BOT_TOKEN=YOUR_SLACK_BOT_TOKEN +# SLACK_API_URL=YOUR_SLACK_API_URL +# This template uses OpenAI, but you can use any other provider! +OPENAI_API_KEY=YOUR_OPENAI_API_KEY diff --git a/.gitignore b/.gitignore index abc3d97..a99f209 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ env*/ venv/ .venv* .env* +!.env.sample # codecov / coverage .coverage diff --git a/README.md b/README.md index c28f64f..88beaad 100644 --- a/README.md +++ b/README.md @@ -17,20 +17,25 @@ Join the [Slack Developer Program](https://api.slack.com/developer-program) for 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. 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`. -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`. +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 +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 -# Replace with your app token and bot token -# For Windows OS, env:SLACK_BOT_TOKEN = works -export SLACK_BOT_TOKEN= -export SLACK_APP_TOKEN= -# This sample uses OpenAI's API by default, but you can switch to any other solution! -export OPENAI_API_KEY= +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 +``` + ### Setup Your Local Project ```zsh diff --git a/app.py b/app.py index fb7bccf..0c3f1e2 100644 --- a/app.py +++ b/app.py @@ -1,12 +1,17 @@ import os import logging +from dotenv import load_dotenv + from slack_bolt import App from slack_bolt.adapter.socket_mode import SocketModeHandler from slack_sdk import WebClient from listeners import register_listeners +# Load environment variables +load_dotenv(dotenv_path=".env", override=False) + # Initialization logging.basicConfig(level=logging.DEBUG) diff --git a/requirements.txt b/requirements.txt index 5cd8a51..76b1703 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ openai pytest flake8 black +python-dotenv==1.1.1