matrix-gpt-bot/README.md
2025-05-09 04:43:15 +00:00

84 lines
2.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Matrix GPT Bot
A Matrix chat bot written in Go that leverages OpenAI to provide GPT-powered conversational responses. The bot listens for messages prefixed with `gpt:` or mentions (`@gpt:<domain>`) and maintains per-user conversation history.
## Features
- **GPT Conversations**: Respond to `gpt: <your message>` commands.
- **Matrix Mentions**: Also triggers on full Matrix mention (`@gpt:domain`).
- **Contextual History**: Keeps a conversation history per user.
- **HTML Formatting**: Sends replies as plain text (no additional markup).
- **Docker Support**: Easily containerize for deployment.
## Prerequisites
- Go 1.20+ installed
- Access to a Matrix homeserver (e.g., Synapse)
- A bot user created on your Matrix server
- An OpenAI API key
## Configuration
Edit `config/config.go` to set your credentials:
```go
func Load() *Config {
return &Config{
Homeserver: "https://matrix.your-server.net",
BotUserID: "@gpt:your-server.net", // Your bot's user ID
AccessToken: "YOUR_MATRIX_ACCESS_TOKEN", // Your Matrix access token
OpenAIKey: "YOUR_OPENAI_API_KEY", // Your OpenAI API key
}
}
```
## Local Development
```bash
# Clone the repository
git clone https://git.ewnix.net/phlux/matrix-gpt-bot.git
cd matrix-gpt-bot
# Initialize modules and download dependencies
go mod init matrix-gpt-bot
go mod tidy
# Run the bot
go run .
```
Invite your bot into a Matrix room and test:
```
gpt: Hello, bot!
```
## Docker Deployment
To build a Docker image:
```bash
docker build -t matrix-gpt-bot:latest .
```
Run the container:
```bash
docker run -d --name matrix-gpt-bot matrix-gpt-bot:latest
```
## Kubernetes (K3s)
1. Create a namespace and pull-secret for private registries if needed.
2. Deploy with a standard Deployment manifest, mounting environment variables for credentials.
## Command Reference
- `gpt: <message>` Sends `<message>` to OpenAI and returns the response.
- `@gpt:domain <message>` Alternate trigger via mention.
## License
MIT © Your Name