examples/

directory
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2025 License: MIT

README ΒΆ

Hi Examples

This directory contains examples demonstrating how to use and extend the Hi chat client.

πŸ“‚ Examples

1. Headless Mode (headless/)

Run the chat client without TUI, using simple stdin/stdout.

cd examples/headless
go run main.go --name mybot --room lobby

Use case: Building chat bots, automation, or integrating with other systems.

2. Keyword Replacement (with_keyword_replace/)

Filter and replace keywords in messages (both incoming and outgoing).

cd examples/with_keyword_replace
go run main.go --name alice --room lobby

Try typing messages with words like "bad", "ugly", or "stupid" - they will be replaced with ***.

Use case: Content moderation, profanity filters, word replacement.

3. Plugins (plugins/)

Reusable middleware plugins that implement MessageMiddleware interface.

Available plugins:

  • keyword_replace.go - Replace keywords in messages

πŸ”Œ Creating Your Own Middleware

Implement the MessageMiddleware interface:

type MessageMiddleware interface {
    ProcessIncoming(sender, content string) (string, bool)
    ProcessOutgoing(content string) (string, bool)
}

Example:

package myplugin

type MyMiddleware struct {
    // your fields
}

func (m *MyMiddleware) ProcessIncoming(sender, content string) (string, bool) {
    // Process received message
    // Return modified content and true to continue, or "", false to filter out
    return content, true
}

func (m *MyMiddleware) ProcessOutgoing(content string) (string, bool) {
    // Process message before sending
    // Return modified content and true to send, or "", false to cancel
    return content, true
}

πŸš€ Running Examples

Each example can be run independently:

# Headless mode
cd examples/headless && go run main.go

# With keyword replacement
cd examples/with_keyword_replace && go run main.go

# Build and install as binaries
go build -o headless-chat ./examples/headless
go build -o filtered-chat ./examples/with_keyword_replace

πŸ’‘ Ideas for More Plugins

  • Encryption/Decryption - Secure messages with AES/RSA
  • Message Logger - Save chat history to file/database
  • Rate Limiter - Prevent message spam
  • Translation - Auto-translate messages to different languages
  • Emoji Converter - Convert text to emojis
  • Command Handler - Handle / commands like /help, /stats
  • AI Bot - Integrate with LLMs for automated responses

Directories ΒΆ

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL