![]() |
|
![]() |
![]() |
Please see: https://vrpconsulting.com/wp-content/uploads/2023/04/GPT-Slack-Bot-Architecture.pdf
This app is designed to be hosted on a FREE Python Anywhere account
Please sign up for your own Python Anywhere account here: www.pythonanywhere.com
Once you've created your account, go to the "Files" section and create a new folder (e.g. "slack") and upload these files there.
Then, create a new Web App by navigating to the "Web" section and following the on-screen instructions. You will need to specify the "Routing.py" file as the main app file for your Flask web app. To do this, go back to the "Web" section and scroll to "WSGI configuration file" and edit the file. Make sure it looks like this:
import sys # add your project directory to the sys.path project_home = '/home/vrpinc/slack' if project_home not in sys.path: sys.path = [project_home] + sys.path # import flask app but need to call it "application" for WSGI to work from Routing import app as application
From your Python Anywhere console, you will need to install a new MySQL instance. Keep the database name as default.
Once you've supplied a username and password, you will need to add them to the config.py file.
You will also need to create a "jobs" table in your database.
Open a new MySQL console for your database and enter the following commands:
CREATE TABLE jobs ( id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, slug VARCHAR(64) NOT NULL, state VARCHAR(10) NOT NULL DEFAULT 'queued', result INT(11) DEFAULT 0, webhook_url VARCHAR(500), message TEXT, user_id VARCHAR(20), response TEXT, channel_id VARCHAR(20) );
For these Python files to run correctly, you will need to install the "openai" module.
To do so, open a bash prompt and type "pip install openai"
The flask, sql_alchemy and other modules should already be installed.
Main flask routing definitions for the Slack App endpoints
You will need to configure your Slack app settings as follows:
Interactivity URL: https://your_account.pythonanywhere.com/slack/interactivity
Events URL: https://your_account.pythonanywhere.com/slack/events
Slash Command: https://your_account.pythonanywhere.com/slack/slash_command
Picks items off the queue from the MySQL "jobs" table and processes them
The inspiration for this design pattern came from https://blog.pythonanywhere.com/198
Contains all the Slack Markdown for modals, App home page and other UI/UX elements
Contains credentials for Slack, MySQL and OpenAI (consider moving to environment variables for production environment)
If you would like to implement the same App using Node.js and Firebase (instead of Python, Flask and MySQL) checkout: https://github.com/magician11/openai-slack