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:
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
# 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:
docker build -t matrix-gpt-bot:latest .
Run the container:
docker run -d --name matrix-gpt-bot matrix-gpt-bot:latest
Kubernetes (K3s)
- Create a namespace and pull-secret for private registries if needed.
- 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
Description
Languages
Go
88.6%
Dockerfile
11.4%