A real-time chat application written in Go, featuring WebSocket communication and bot integration. This project serves as an example for building scalable WebSocket-based systems with support for automated bot interactions.
- WebSocket Communication — Real-time messaging between clients
- Chat Rooms with Commands — Use
@chatCommandto target specific rooms - Bots — Assign custom bots to chats for automated replies
- Main Chat View — View all messages from all chats in one place
- Web Interface for Management — Create/manage chats and bots via UI
- Go 1.23+
- SQLite3
-
Clone the repository:
git clone https://github.com/gregjsong/go-ws-chatbot-example.git cd go-ws-chatbot-example -
Run the server:
go run cmd/server/main.go
To build the project into a binary:
go build -o app ./cmd/serverOpen your browser:
- Chat client: http://localhost:8090
- Create/manage bots: http://localhost:8090/manage
- Create/manage chats: http://localhost:8090/manage/chat
The main chat shows all messages from all chat rooms.
It acts as a global feed and allows posting to specific chats using commands.
From any chat (including the main chat), you can send a message to a specific room by prefixing it with the room’s command:
@dev Hello developers!
@support Need help with the login issue.
Each chat is associated with a unique @command. Messages starting with this command will be routed to that chat room, even if you're typing from a different room.
Bots can be created and assigned to any chat. When a message is received in that chat, all assigned bots are notified and may respond.
.
├── cmd/
│ └── server/ # Entry point (main.go)
├── config/ # Configuration files
├── db/
│ └── init.sql # Initial database schema
├── internal/
│ ├── bot/ # Bot logic
│ ├── chat/ # WebSocket chat hub, client handling, chat/bot integration
│ ├── db/ # Database related logic
│ ├── ui/ # UI related logic for templates/static
│ └── utils/ # Utility functions
├── logs/ # Log output directory (runtime)
├── templates/ # HTML templates for UI rendering
├── web/ # Static assets (JS, HTML)
├── go.mod
└── README.md
Run the full test suite:
go test ./...