Peter.Morton c198babc75 simplified code
Reductions:

~170 lines → ~110 lines (35% fewer lines)
Removed unnecessary functions and constructors
Combined structs and simplified JSON parsing
Streamlined error handling
Merged sendRequest and SendMessage into single Send method

Key simplifications:

Used inline struct definitions for Response parsing
Replaced Metadata struct with simple map[string]string
Removed NewMessenger constructor - use struct literal directly
Inlined the header printing
Simplified constant names (colorBlue → blue)
Reduced verbose error messages

The app works exactly the same but with much cleaner, more maintainable
code! All features are preserved:

 Colorized input/output
 Arrow key history navigation
â Conversation context tracking
 Same API communication
2025-11-01 22:56:53 -05:00
..
2025-11-01 22:46:34 -05:00
2025-11-01 22:46:34 -05:00
2025-11-01 22:56:53 -05:00
2025-11-01 22:46:34 -05:00

Terminal Messenger

A simple, colorful terminal-based messenger application written in Go that connects to a remote messaging endpoint.

Features

  • 🎨 Colorized output - Blue for your input, green for assistant responses
  • ⌨️ Input history - Navigate previous messages with arrow keys
  • 💬 Conversation context - Maintains conversation continuity across messages
  • 🚀 Simple and fast - Minimal setup, quick startup
  • 📝 Line editing - Full cursor movement and text editing support

Prerequisites

  • Go 1.16 or higher
  • Internet connection

Installation

  1. Clone or download the project

  2. Initialize Go module

    go mod init messenger
    
  3. Install dependencies

    go get github.com/chzyer/readline
    
  4. Build the application (optional)

    go build -o messenger main.go
    

Usage

Running the application

Using go run:

go run main.go

Or if you built the binary:

./messenger

Getting started

  1. When prompted, enter a model name (or press Enter for "default")
  2. Start typing your messages
  3. The assistant will respond to each message
  4. Use arrow keys to navigate through your input history
  5. Type quit or exit to end the session

Keyboard shortcuts

  • ↑ (Up arrow) - Navigate to previous input
  • ↓ (Down arrow) - Navigate to next input
  • ←/→ (Left/Right arrows) - Move cursor within current input
  • Ctrl+A - Jump to beginning of line
  • Ctrl+E - Jump to end of line
  • Ctrl+C - Interrupt/exit application

Configuration

The application connects to:

https://router.ivastudio.verint.live/ProxyScript/run/67bca862210071627d32ef12/current/basic_messenger

To change the endpoint, modify the apiURL constant in main.go.

Request format

The application sends POST requests with the following JSON structure:

{
  "input": "your message here",
  "model": "model name",
  "previous_response_id": "previous response ID for context",
  "metadata": {
    "channel": "text"
  }
}

Response format

Expected response structure:

{
  "id": "response-id",
  "object": "response",
  "created_at": 1234567890,
  "status": "completed",
  "model": "Model Name",
  "output": [
    {
      "type": "message",
      "id": "message-id",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "Assistant response here",
          "annotations": []
        }
      ]
    }
  ]
}

Project Structure

.
├── main.go              # Main application file
├── go.mod               # Go module file
└── README.md            # This file

Troubleshooting

Connection errors

If you encounter connection errors, check:

  • Your internet connection
  • The endpoint URL is accessible
  • Firewall settings aren't blocking the connection

Module errors

If you get "module not found" errors:

go mod tidy

History file permissions

The app creates a history file at /tmp/messenger_history.tmp. If you encounter permission errors, ensure you have write access to /tmp/.

Dependencies

License

This project is provided as-is for educational and development purposes.

Contributing

Feel free to submit issues, fork the repository, and create pull requests for any improvements.