Skip to content

gregjsong/go-ws-chatbot-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Chat Application

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.

Chat demo image

Table of Contents

Features

  • WebSocket Communication — Real-time messaging between clients
  • Chat Rooms with Commands — Use @chatCommand to 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

Getting Started

Requirements

  • Go 1.23+
  • SQLite3

Installation

  1. Clone the repository:

    git clone https://github.com/gregjsong/go-ws-chatbot-example.git
    cd go-ws-chatbot-example
  2. Run the server:

    go run cmd/server/main.go

Build

To build the project into a binary:

go build -o app ./cmd/server

Usage

Open your browser:

Chat System

Main 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.

Command-Based Messaging

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.

Bot System

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.

Project Structure

.
├── 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

Testing

Run the full test suite:

go test ./...

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published