Simple slack bot to connect to GPT Chat.
This project uses:
- slack-bolt for Python
This project is supported by Bitovi, a DevOps consultancy. You can get help or ask questions on our:
Or, you can hire us for training, consulting, or development. Set up a free consultation.
The inspiration for this project is here: https://medium.com/@alexandre.tkint/integrate-openais-chatgpt-within-slack-a-step-by-step-approach-bea43400d311
- Fork this repo
- Register an app with Slack and obtain tokens
- Obtain AWS credentials
- Obtain the OpenAI API key
- Install necessary dependencies
- Run the application
- Test out
The first step in integrating ChatGPT with Slack is to register an app with Slack and obtain the Slack Bot Token and Slack App Token. To do this, follow these steps:
- Log in to your Slack workspace
- Go to the Slack API website
- Click on “Create an app” and select “From scratch”
- Give your app a name, select your Slack workspace
- In Basic information > Add features and functionality. Click on “Permissions” and in Scopes add in Bot Token Scopes: app_mentions:read ; channels:history ; channels:read ; chat:write
- In settings, click on “Socket Mode”, enable it and give the token a name. Copy the Slack Bot App Token (starts with xapp)
- In Basic information > Add features and functionality. Click on “Event Subscriptions” and enable it. Furthermore in “Subscribe to bot events” select “app_mention”. Save changes.
- Go to the “OAuth & Permissions” section and install your app to your workspace
- Copy the Slack Bot Token (starts with
xoxb
), you'll add it to a GitHub repo secret calledDOT_ENV
.
Sign up for an AWS account.
You'll need
- An access key id
- A secret access key
- (optionally) A session token
To obtain these values for an AWS IAM User, see Getting AWS credentials for an AWS IAM user
Then add GitHub Secrets accordingly for:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
The next step is to obtain the OpenAI API key. Why? Will need to connect to OpenAI’s API in order to use their GPT-3 API. If you are new to this, no problem, you’ll get 18$ for free without having to provide a credit card. To generate an API key, follow these steps:
- Go to the OpenAI API website
- Log in or sign up for an OpenAI account
- Go to the API Key section and create a new API key
- Copy the API key
Create a new secret in deployment repository's GitHub Secrets called DOT_ENV
with the following contents:
OPENAI_API_KEY="sk-......."
SLACK_BOT_APP_TOKEN="xapp-......."
SLACK_API_KEY="xoxb-......."
You can add the following variables too, if you feel the need to adjust them:
OPENAI_ENGINE="gpt-3.5-turbo"
OPENAI_MAX_TOKENS="1024"
OPENAI_ACK_MSG="Hello from your bot! :robot_face: \nThanks for your request, I'm on it!"
OPENAI_REPLY_MSG="Here you go: \n"
See OpenAI engine models here
.github/workflows/deploy.yaml
name: Deploy
on:
push:
branches: [ main ]
permissions:
contents: read
jobs:
EC2-Deploy:
runs-on: ubuntu-latest
environment:
name: ${{ github.ref_name }}
url: ${{ steps.deploy.outputs.vm_url }}
steps:
- id: deploy
name: Deploy
uses: bitovi/[email protected]
with:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID}}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
aws_default_region: us-east-1
# Provide a secret called `DOT_ENV` to append environment variables to the .env file
dot_env: ${{ secrets.DOT_ENV }}