> For the complete documentation index, see [llms.txt](https://40factory.gitbook.io/wilson/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://40factory.gitbook.io/wilson/3.12/rest-api/chat/send-chat-message.md).

# Send chat message

This endpoint allows the user to send a message, get the generated response, and save it in a specific chat identified by the \<chat\_id>.

## Request <a href="#request" id="request"></a>

### Url

```
POST 
https://wilson.40mat.com/apif/v2/chat/<chat_id>/messages
```

### Headers

<pre><code><strong>AUTH
</strong>Bearer "eyJ0eXAiOiJKV1QiLCJub25jZSI6IndUZXphSTNjdTNVYj..."
</code></pre>

### Parameters

```
No parameters are required for this endpoint.
```

### Body

```json
{
    "message": "Hello, how you can help me?",
    "auto_document_selector": true,
    "filters": {
        "paths": ["679221c553fb..."],
        "tags": ["679221c345gb..."]
    },
    "document_ids": ["679221c689fb..."]
}
```

The request body is in JSON format contain following properties:

* `message` (string, required): Request message content.
* `auto_document_selector` (boolean): If True, force the auto docuemnt selection of documents.
* `filters` (object):
  * `paths` (string array): List of id of documents of knowledge base to use.
  * `tags` (string array): List of id of tags to use.
* `document_ids` (string array): List of documents to inject into the chat.

***

## Response&#x20;

```json
{
    "chat_id": "682f53929b5...",
    "actor": "wilson",
    "timestamp": "2025-05-26T15:23:45.006404Z",
    "text": "I can provide service on industrial machines in a variety of ways, including:\n1. **Maintenance**: Maintenance and replacement operations should be performed by experienced maintainers in compliance with applicable workplace safety laws and environmental issues of the specific installation. It is recommended to have extraordinary maintenance work carried out by the Manufacturer or a specialized and authorized center. Before carrying out any work, the personnel in charge must switch off the power supply to the machine and lock the isolating switches in the isolated circuit position.\n2. **Safety**: Before carrying out any maintenance work, it is necessary to activate all planned safety devices and to consider whether it is necessary to properly inform the operating personnel and those in the vicinity. It is important to properly mark nearby areas and prevent access to all devices that could, if activated, cause unexpected hazardous conditions causing harm to people's safety and health.\4. **Spares**: It is essential to replace excessively worn parts using only original spare parts. No liability is accepted for damage to persons or parts resulting from the use of non-original spare parts and extraordinary interventions that may alter safety requirements, without the Manufacturer's authorization.\n\n5. **Disposal**: Do not dispose of polluting liquids, worn parts and maintenance residues into the environment. Dispose of them in accordance with the relevant laws.\n If you have specific questions or need detailed instructions on a particular aspect of machine maintenance or use, I can provide you with the necessary information based on available documentation.",
    "question": "Hello, how you can help me?",
    "rephrasing": "How can you provide support on industrial machines?",
    "sources": [
        {
            "chunk_content": null,
            "chunk_idx": null,
            "description": "description of file",
            "document_type": "image",
            "filename": "filename.pdf",
            "id": "67e179a76bf5...",
            "object_name": "/example/filename.pdf",
            "page_number": "2",
            "retrieval_mode": "similarity",
            "row_idx": null,
            "usage_score": 10.0
        }
    ],
    "documents_filtered": [],
    "validated_autodocs": null,
    "keywords": [],
    "auto_doc_filtering": true,
    "small_talk": true,
    "previews": [
        {
            "type": "image",
            "url": "http://localhost:8080/_/rs:fit:200:200/aHR0cDovL21pbmlvOjkwM...",
            "title": "Document title"
        }
    ],
    "bot_id": "67a48fae85e360...",
    "tags": {
        "bot_id": "67a48fae85e360...",
        "document_ids": [],
        "paths": [
            {
                "id": "67effa9f3b03...",
                "object_name": "/"
            },
            {
                "id": "67f8485f433e5...",
                "object_name": "/example"
            }
        ],
        "tags": []
    },
}
```

The response is in JSON format contain following properties:

* `chat_id` (string): Id of chat
* `actor` (string): Author of message: \<wilson> or \<user>
* `timestamp` (datetime string): Timestamp of message
* `text` (string): Textual content of message
* `question` (string): Question of user
* `rephrasing` (string): Elaboration of question by Wilson based on context and previous messages
* `auto_doc_filtering` (boolean): Indicate value of `auto_document_selector` in request
* `documents_filtered` (string array): List of documents id selected by auto document selection (if `auto_document_selector = true` in request)
* `validated_autodocs` (boolean): If True, found documents with auto document selection (view in `documents_filtered`
* `keywords` (string array): List of keywords identified
* `small_talk` (boolean): If True, question identified as "chitchat", no need to search response in knowledge base
* `keywords` (string array): List of keywords identified
* `bot_id` (string): Id of bot
* `tags` (object): Description of tags of bot used
  * `bot_id` (string): Description of document
  * `documents_id` (string array): List of documents id selected in bot
  * `paths` (object array): List of paths in bot
    * `id` (string): Document id
    * `object_name` (string): Document full path
  * `tags` (string array): List of tags id in bot
* `sources` (object array): List of identified sources
  * `description` (string): Description of document
  * `chunk_context` (string): Context of chunk
  * `chunk_id` (number): Chunk id
  * `document_type` (string): Document type, for example `image`, `text`, ...
  * `filename` (string): Document filename
  * `id` (string): Document Id
  * `object_name` (string): Document path in knowledge base
  * `page_number` (string): Document page number or range (if pdf document)
  * `row_idx` (string): Document row (if csv document)
  * `retrieval_mode` (string): Mode of retrieval, for example `similarity`, `lookup`
  * `usage_score` (number): Score calculated on retrieval

***

## Code example

{% tabs %}
{% tab title="Python" %}

```python
import requests
import json

url = "https://wilson.40mat.com/apif/v2/chat/<chat_id>/messages"

payload = {
  "message": "Hello, how you can help me?",
  "auto_document_selector": True,
  "document_ids": []
}
headers = {
  'Authorization': '••••••'
}

response = requests.request("POST", url, headers=headers, json=payload)

print(response.text)
```

{% endtab %}

{% tab title="cURL" %}

```powershell
curl --location 'https://wilson.40mat.com/apif/v2/chat/<chat_id>/messages' \
--header 'Authorization: ••••••' \
--data '{
    "message": "Hello, how you can help me?",
    "auto_document_selector": true,
    "document_ids": [],
    "data_analysis": false
}'
```

{% endtab %}
{% endtabs %}
