Chat History
Retrieve conversation history for a chat session. Messages include text content and audio URLs for voice messages stored in MinIO.
Info
Voice messages are automatically stored in MinIO and the audio URLs are included in the history response.
Get Conversation History
Retrieve paginated chat messages for a session. Messages are returned in reverse chronological order (newest first).
history.ts
typescript
import { AICommerce } from '@yassirbenmoussa/aicommerce-sdk';
const client = new AICommerce({
apiKey: 'YOUR_API_KEY',
});
// Get conversation history
const history = await client.getHistory({
sessionToken: 'your-session-token',
page: 1,
limit: 20
});
console.log(history.messages); // Array of messages
console.log(history.pagination); // Pagination infoQuery Parameters
| Field | Type | Required | Description |
|---|---|---|---|
| sessionToken | string | Yes | The session token from a previous chat interaction |
| sort | string | No | docs.sections.chatHistory.queryParams.sortDesc |
| page | number | No | Page number for pagination (default: 1) |
| limit | number | No | Messages per page, 1-100 (default: 20) |
Response Format
response.json
json
{
"messages": [
{
"id": "uuid",
"role": "user",
"content": "Show me laptops under $500",
"audioUrl": "https://minio.../chat-audio/...", // null if text message
"productIds": [],
"createdAt": "2024-01-14T12:00:00Z"
},
{
"id": "uuid",
"role": "assistant",
"content": "Here are some laptops...",
"audioUrl": null,
"productIds": ["prod-1", "prod-2"],
"createdAt": "2024-01-14T12:00:01Z"
}
],
"pagination": {
"page": 1,
"limit": 20,
"total": 42,
"totalPages": 3,
"hasMore": true
}
}Message Fields
| Field | Type | Description |
|---|---|---|
| id | string | Unique message identifier |
| role | string | Message role: 'user' or 'assistant' |
| content | string | Text content of the message |
| audioUrl | string | null | MinIO URL for voice messages (null for text messages) |
| productIds | string[] | Array of recommended product IDs (for assistant messages) |
| createdAt | string | ISO 8601 timestamp when message was created |
Tip
Audio URLs point to files stored in MinIO. You can use these URLs directly in audio players to replay voice messages.