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