This repository contains a SlackBot built on Cloudflare Workers that leverages OpenAI to answer questions when mentioned.
- Serverless: Powered by Cloudflare Workers, ensuring high availability and scalability with minimal infrastructure management.
- AI-Powered Responses: Uses OpenAI to generate intelligent, context-aware responses to your questions.
- Slack Integration: Responds to mentions in Slack channels, making it easy to interact with the bot in your workspace.
- Mention the Bot: Simply mention the bot in any Slack channel with your question.
- OpenAI Integration: The bot processes your message and sends it to OpenAI’s API for a response.
- Reply: The bot returns the generated response directly in the Slack channel.
• A Cloudflare Workers account. • A Slack workspace with API credentials. • An OpenAI API key.
-
Clone the Repository:
-
Install Dependencies:
bun i
- Set Up Environment Variables:
-
Create a .dev.vars file in the root directory with the following keys:
-
local
cp .dev.vars.example .dev.vars
vim .dev.vars
- Cloudflare Workers
OPENAI_API_KEY: sk-proj-X_XXXXXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
OPENAI_MODEL: gpt-4o-mini
OPENAI_PROMPT: あなたは優秀なSlackBotです。
OPENAI_MAX_REFER_MESSAGES: 8
SLACK_TOKEN: xoxb-XXXXXXXXXXXXX-XXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXX
SLACK_SIGNING_SECRET: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
SLACK_APP_TOKEN: xapp-X-XXXXXXXXXXX-XXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
SLACK_BOT_ID: XXXXXXXXXXX
SLACK_TEMP_MESSAGE: ...
SLACK_BOT_ERROR_MESSAGE: エラーが発生しました。
- Development
ngrok http http://localhost:8080
- Deploy to Cloudflare Workers:
bun run deploy
After deployment, invite the bot to a Slack channel. You can mention the bot using @YourBotName followed by your question, and the bot will respond with an answer generated by OpenAI.
@YourBotName What is the capital of France?
Response:
The capital of France is Paris! It's known for its beautiful architecture, rich history, and delicious food. Have you ever been there or is it on your travel list?
Contributions are welcome! Feel free to submit a pull request or open an issue if you have any suggestions or improvements.
This project is licensed under the MIT License. See the LICENSE file for details.
This template provides a comprehensive overview of your SlackBot project, making it easy for others to understand and contribute.