Skip to main content

Overview

The Conversations API allows you to list all Telegram conversations initiated with the bot and retrieve messages from specific conversations.
All conversation endpoints require authentication. Include a valid JWT token in the Authorization header.

List All Conversations

curl -X GET http://localhost:8080/api/conversations \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
Retrieves a summary list of all Telegram conversations initiated with the bot.

Endpoint

GET /api/conversations

Headers

Authorization
string
required
Bearer token for authentication
Authorization: Bearer <your-jwt-token>

Response

Returns an array of conversation summary objects.
conversations
array

Success Response (200 OK)

[
  {
    "id": "123456789",
    "participantName": "JohnDoe",
    "lastMessageAt": "2024-03-15T10:30:45"
  },
  {
    "id": "987654321",
    "participantName": "Jane Smith",
    "lastMessageAt": "2024-03-14T15:22:10"
  }
]

Error Responses

{
  "message": "Authentication Failed",
  "details": "JWT token is missing or invalid"
}

Get Conversation Messages

curl -X GET http://localhost:8080/api/conversations/123456789/messages \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
Retrieves the complete list of messages for a specific conversation, ordered by date.

Endpoint

GET /api/conversations/{id}/messages

Path Parameters

id
string
required
The conversation ID (Telegram chat ID)Example: 123456789

Headers

Authorization
string
required
Bearer token for authentication
Authorization: Bearer <your-jwt-token>

Response

Returns an array of message objects ordered chronologically.
messages
array

Success Response (200 OK)

[
  {
    "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "content": "Hello! How can I help you?",
    "direction": "INCOMING",
    "sentAt": "2024-03-15T10:28:30"
  },
  {
    "id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
    "content": "This is a response from the AI bot",
    "direction": "OUTGOING",
    "sentAt": "2024-03-15T10:28:35"
  },
  {
    "id": "c3d4e5f6-a7b8-9012-cdef-123456789012",
    "content": "Thanks! That was helpful.",
    "direction": "INCOMING",
    "sentAt": "2024-03-15T10:30:45"
  }
]

Error Responses

{
  "message": "Authentication Failed",
  "details": "JWT token is missing or invalid"
}
{
  "message": "Resource Not Found",
  "details": "Conversation with ID '123456789' could not be found."
}

Message Direction Flow

Understanding message directions:
1

INCOMING Messages

Messages sent by Telegram users to the bot. These trigger the AI response system.
2

OUTGOING Messages

Messages sent from the bot to Telegram users. Can be:
  • AI-generated responses (automatic)
  • Admin-initiated messages (via API)

Pagination

The current API version does not implement pagination. All messages for a conversation are returned in a single response. This may be added in future versions for conversations with large message histories.

Source Code References

  • Controller: ConversationController.java:44 (list conversations), ConversationController.java:58 (get messages)
  • DTOs:
    • ConversationSummaryDto.java:5 - Conversation summary structure
    • MessageDto.java:6 - Message structure
  • Domain Model: Message.java:48 - MessageDirection enum

Next Steps

Send Messages

Learn how to send messages to conversations

Authentication

Review authentication requirements

Build docs developers (and LLMs) love