Skip to main content

Complete message

Creates a message and gets a response from a chat.

Endpoint

POST https://api.cogfy.com/collections/:collectionId/chats/:chatId/messages

Path parameters

  • collectionId: The ID of the collection that contains the chat.
  • chatId: The ID of the chat where the message will be sent.

Request body

  • content: The content of the message.
  • contentType: The type of content. Can be "text" or "audio".
  • file: Contains file information if a file is included in the message.
    • name: The name of the file.
    • size: The file size in bytes.
    • mimeType: The MIME type of the file.
    • base64: The base64-encoded file content.

Example JSON request

{
"content": "Hello!",
"contentType": "text",
"file": {
"name": "example.pdf",
"size": 234131,
"mimeType": "application/pdf",
"base64": "JVBERi0xLjQKJ..."
}
}

Response body

  • id: The unique identifier of the created message.
  • content: The content of the message.
  • files: A list of files attached to the message, each containing:
    • name: The name of the file.
    • size: The file size in bytes.
    • mimeType: The MIME type of the file.
    • base64: The base64-encoded file content.
  • data: Additional metadata about the message. The structure varies based on message type:
    • Assistant messages (type: "assistant"): Contains completion data, WhatsApp integration info, scheduled message details, or history merge settings.
      • completion: Information about the completion process.
        • sources: Array of retrieval sources used (consensus, embedding, record, or typesense).
      • whatsapp: WhatsApp integration metadata.
        • connectionId: The connection identifier.
        • from.phoneNumberId: The sender's phone number ID.
        • to.waId: The recipient's WhatsApp ID.
        • to.phoneNumber: The recipient's phone number.
        • context.messageId: The context message ID for replies.
      • scheduleMessage: Scheduled message information.
        • middleware.id: The middleware identifier.
      • history: Message history configuration.
        • mergeType: How to handle history ("merge", "append", or "prepend").
    • Tool messages (type: "tool"): Contains information about tool usage.
      • tool: Tool execution details.
        • name: The name of the tool used.
        • args: Arguments passed to the tool.
        • sources: Array of retrieval sources used.
    • User messages (type: "user"): Contains retrieval data and WhatsApp context.
      • retrieval: Retrieval information.
        • sources: Array of retrieval sources used.
      • whatsapp: WhatsApp message context.
        • from.waId: The sender's WhatsApp ID.
        • to.phoneNumberId: The recipient's phone number ID.
        • context.forwarded: Whether the message was forwarded.
        • context.frequentlyForwarded: Whether the message was frequently forwarded.
        • context.from: The original sender if forwarded.
        • context.id: The original message ID.

Retrieval sources

Retrieval sources can be one of four types:

  • Consensus (type: "consensus"): Contains consensus-based information.
    • title: The title of the consensus source.
    • quote: A relevant quote from the source.
    • bottomLine: Summary or conclusion.
    • url: Source URL.
    • hashTags: Related hashtags.
  • Embedding (type: "embedding"): Contains vector embedding match information.
    • id: The embedding identifier.
    • collectionId: The collection containing the embedding.
    • recordId: The record identifier.
    • similarity: Similarity score.
    • content: The matched content.
    • fileId: Associated file ID (if applicable).
    • fileName: Associated file name (if applicable).
    • pageNumber: Page number in the file (if applicable).
  • Record (type: "record"): Contains direct record match information.
    • id: The record identifier.
    • collectionId: The collection containing the record.
    • content: The record content.
    • title: The record title.
    • similarity: Similarity score (if applicable).
  • Typesense (type: "typesense"): Contains search index match information.
    • id: The search result identifier.
    • content: The matched content.
    • collection: The search collection name.

Example JSON response

{
"id": "<UUID>",
"content": "Hello, how can I help you?",
"files": [
{
"name": "audio.mp3",
"size": 343721,
"mimeType": "audio/mp3",
"base64": "WVREFiLG0aADKGK..."
}
],
"data": {
"type": "assistant",
"completion": {
"sources": [
{
"type": "embedding",
"embedding": {
"id": "<UUID>",
"collectionId": "<UUID>",
"recordId": "<UUID>",
"similarity": 0.95,
"content": "Relevant context from knowledge base...",
"fileName": "documentation.pdf",
"pageNumber": 5
}
}
]
}
}
}