feat: implement terminal messenger with conversation management
feat: implement terminal messenger with conversation management - Add terminal-based messenger client connecting to Verint API endpoint - Implement colorized output (blue for user input, green for assistant responses) - Add readline integration for arrow key navigation through input history - Implement conversation persistence with unique history files per conversation ID - Add conversation resume feature listing 5 most recent conversations - Store and auto-load model names per conversation - Display last 10 message exchanges when resuming conversations - Log full conversation history (user + assistant messages) with timestamps - Simplify codebase by consolidating file operations into reusable functions - Fix Sscanf error handling for conversation selection Features: - Request/response handling with conversation context via previous_response_id - Three file types per conversation: .tmp (readline history), _log.txt (full conversation), _meta.txt (model name) - Automatic conversation ID assignment after first message - Clean exit handling and proper resource cleanup
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
# Terminal Messenger
|
||||
|
||||
A simple, colorful terminal-based messenger application written in Go that connects to a remote messaging endpoint.
|
||||
A simple, colorful terminal-based messenger application written in Go that connects to a remote messaging endpoint with conversation persistence and history management.
|
||||
|
||||
## 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
|
||||
- 💾 **Conversation persistence** - Resume previous conversations seamlessly
|
||||
- 📝 **Full conversation logs** - Both user and assistant messages saved with timestamps
|
||||
- 🔄 **Auto-resume** - Lists your 5 most recent conversations on startup
|
||||
- 🏷️ **Model tracking** - Automatically saves and loads the model used per conversation
|
||||
- 🚀 **Simple and fast** - Minimal setup, quick startup
|
||||
- 📝 **Line editing** - Full cursor movement and text editing support
|
||||
|
||||
## Prerequisites
|
||||
|
||||
@@ -19,26 +21,20 @@ A simple, colorful terminal-based messenger application written in Go that conne
|
||||
|
||||
1. **Clone or download the project**
|
||||
|
||||
2. **Initialize Go module**
|
||||
|
||||
```bash
|
||||
go mod init messenger
|
||||
```
|
||||
|
||||
3. **Install dependencies**
|
||||
2. **Install dependencies**
|
||||
|
||||
```bash
|
||||
go get github.com/chzyer/readline
|
||||
```
|
||||
|
||||
4. **Build the application (optional)**
|
||||
3. **Build the application (optional)**
|
||||
```bash
|
||||
go build -o messenger main.go
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Running the application
|
||||
### Starting the application
|
||||
|
||||
**Using go run:**
|
||||
|
||||
@@ -52,13 +48,29 @@ go run main.go
|
||||
./messenger
|
||||
```
|
||||
|
||||
### Getting started
|
||||
### First time usage
|
||||
|
||||
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
|
||||
1. Press 'n' or Enter when asked about continuing a conversation
|
||||
2. Enter a model name (or press Enter for "default")
|
||||
3. Start chatting with the assistant
|
||||
4. Type `quit` or `exit` to end the session
|
||||
|
||||
### Resuming a conversation
|
||||
|
||||
1. When prompted, you'll see your recent conversations:
|
||||
|
||||
```
|
||||
Recent conversations:
|
||||
1. resp_d2925cd3-d99c-46f6-a70a-05b1453b8d4f (model: gpt-4)
|
||||
2. resp_a1234567-89ab-cdef-0123-456789abcdef (model: default)
|
||||
|
||||
Continue? (enter number or 'n' for new):
|
||||
```
|
||||
|
||||
2. Enter the number (1-5) to resume that conversation
|
||||
3. The last 10 message exchanges will be displayed
|
||||
4. The model name is automatically loaded
|
||||
5. Continue chatting from where you left off
|
||||
|
||||
### Keyboard shortcuts
|
||||
|
||||
@@ -67,9 +79,26 @@ go run main.go
|
||||
- **←/→ (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
|
||||
- **Ctrl+C** or type `quit`/`exit` - Exit application
|
||||
|
||||
## Configuration
|
||||
## How It Works
|
||||
|
||||
### Conversation Files
|
||||
|
||||
For each conversation, three files are created in `/tmp/`:
|
||||
|
||||
1. **`messenger_{ID}.tmp`** - Readline history for arrow key navigation (user inputs only)
|
||||
2. **`messenger_{ID}_log.txt`** - Full conversation log with timestamps (both user and assistant)
|
||||
3. **`messenger_{ID}_meta.txt`** - Stores the model name for the conversation
|
||||
|
||||
### Conversation Continuity
|
||||
|
||||
- Each response from the API includes a unique `id`
|
||||
- This ID is sent as `previous_response_id` in subsequent requests
|
||||
- This maintains conversation context across the entire session
|
||||
- When resuming, the conversation ID is loaded and context is preserved
|
||||
|
||||
## API Configuration
|
||||
|
||||
The application connects to:
|
||||
|
||||
@@ -81,8 +110,6 @@ To change the endpoint, modify the `apiURL` constant in `main.go`.
|
||||
|
||||
### Request format
|
||||
|
||||
The application sends POST requests with the following JSON structure:
|
||||
|
||||
```json
|
||||
{
|
||||
"input": "your message here",
|
||||
@@ -96,8 +123,6 @@ The application sends POST requests with the following JSON structure:
|
||||
|
||||
### Response format
|
||||
|
||||
Expected response structure:
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "response-id",
|
||||
@@ -126,7 +151,7 @@ Expected response structure:
|
||||
|
||||
```
|
||||
.
|
||||
├── main.go # Main application file
|
||||
├── main.go # Main application file (~160 lines)
|
||||
├── go.mod # Go module file
|
||||
└── README.md # This file
|
||||
```
|
||||
@@ -151,7 +176,11 @@ 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/`.
|
||||
The app creates files in `/tmp/`. If you encounter permission errors, ensure you have write access to `/tmp/`.
|
||||
|
||||
### Cannot find previous conversations
|
||||
|
||||
Conversations are stored in `/tmp/` which may be cleared on system restart. For permanent storage, modify the file paths in `main.go` to use a different directory like `~/.messenger/`.
|
||||
|
||||
## Dependencies
|
||||
|
||||
|
||||
Reference in New Issue
Block a user