> 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.11/rest-api/chat/send-chat-message.md).

# Send chat message

## 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..."],
    "data_analysis": true
}
```

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.
* `data_analysis` (boolean): If True, active Data Analysis (Data Scientist Mode). Use documents listed in documents\_ids for an analytic query.
* `document_ids` (string array): List of documents to use for data\_analysis query. Useful (and needed) only if data\_analysis is True.

***

## 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": [],
  "data_analysis": False
}
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 %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://40factory.gitbook.io/wilson/3.11/rest-api/chat/send-chat-message.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
