This repository contains a Slack bot that generates and displays images based on prompts using OpenAI's API. The bot listens for commands in Slack channels and responds with images generated by OpenAI.
To run this Slack bot, you need to have the following prerequisites:
- Python (version 3.7 or higher)
- Slack workspace with the ability to add a new app
- OpenAI org and API keys
- Slack app token and bot token
-
Clone this repository to your local machine:
git clone https://github.com/JamesBLewis/slack-to-image.git
-
Change to the cloned repository's directory:
cd slack-to-image/app
-
Install the required Python dependencies:
pip install -r requirements.txt
All you need from here is an ORG_KEY and API key.
- Fetch your org key (OPENAI_ORG) from the account settings page.
- Create a new API key (OPENAI_KEY) on the API key Page.
To set up the Slack app and slash command, follow these steps:
- Go to the Slack API website and sign in to your workspace.
- Create a new Slack app by clicking on "Create an App" and provide a name and select the workspace where you want to install the app.
- Enable Socket Mode by navigating to the "Socket Mode" section in your app's settings and turning it on.
- In the "Slash Commands" section, click on "Create New Command". Set the command as
/imagine
. - Generate an app-level token by navigating to the "Basic Information" page of your app. Under "App-Level Tokens", click on "Generate Token and Scopes". Make sure to include the scope "connections:write".
- Copy the "App Level Tokens" (SLACK_XAPP) from the above step and the "Bot User OAuth Tokens" (SLACK_XOXB) from the "OAuth & Permissions" page.
Before running the bot, you need to configure the necessary environment variables. Open the .env
file in the repository directory and update the values accordingly:
SLACK_XAPP=<slack-app-token>
SLACK_XOXB=<slack-bot-token>
OPENAI_ORG=<openai-organization>
OPENAI_KEY=<openai-api-key>
Replace <slack-app-token>
, <slack-bot-token>
, <openai-organization>
, and <openai-api-key>
with your actual tokens and keys.
To start the Slack bot, run the following command:
python ./app/main.py
The bot will establish a connection to your Slack workspace and start listening for commands.
To generate and display images, use the /imagine
command in a Slack channel where the bot is installed. The command accepts a prompt as an argument.
/imagine <prompt>
Replace <prompt>
with the text that describes the desired image. The bot will generate images based on the provided prompt and display them in the channel. Optionally you may prefix your can prefix your prompt with x4 (where 4 is some int between 1 and 10). This will result in the desired number of images being generated.
If you want to contribute to this project, you can fork the repository, make changes, and submit a pull request. Please ensure that your code follows the existing style and includes appropriate documentation and tests.
This project is licensed under the MIT License.
Very heavily inspired by slack-diffusion by Dylan Butler.