# 3.3.1-Start Upload File in Chatflow

## 1. Overview

* **Interface Name**: Use websocket protocol to start a chatflow and upload files
* **Version number**: v1.0.0

## 2. Information

* **Request method**: POST
* **Request URL**: wss\://*DOMAIN*/openapi/v2/ws/dialog/
* **Domain**: *Refer to "Service address description"*

## 3. Request parameters

Request header http header field:

| Parameter name        | Type   | Required | Description |
| --------------------- | ------ | -------- | ----------- |
| cybertron-robot-key   | string | Yes      | Robot key   |
| cybertron-robot-token | string | Yes      | Robot token |

Request body field:

| Parameter name  | Type   | Required | Description                                                                        |
| --------------- | ------ | -------- | ---------------------------------------------------------------------------------- |
| username        | string | Yes      | User account                                                                       |
| question        | string | Yes      | If a user problem is identified, you can open the intent, for example: File Upload |
| segment\_code   | string | Yes      | Session ID, a round conversation ID, generated by the client                       |
| message\_source | string | Yes      | Source: "WS"                                                                       |

## 4. Response field description

Response field description:

| Field Name                 | Type   | Description                                                                                                                                  |
| -------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------- |
| code                       | string | "000000" is normal, other exceptions                                                                                                         |
| message                    | string | Status description                                                                                                                           |
| data                       | object | message body                                                                                                                                 |
| instruction                | string | node guide, for example: "Welcome file upload"                                                                                               |
| flow\_uuid                 | string | Dialogflow ID                                                                                                                                |
| session\_id                | string | Conversation id                                                                                                                              |
| node\_id                   | string | Node ID                                                                                                                                      |
| upload\_file\_categories   | array  | List of Upload File Categories                                                                                                               |
| id                         | int    | File Category ID                                                                                                                             |
| name                       | string | The name of the document category, for example, "Contract", "Certificate"                                                                    |
| support\_formats           | string | File categories support formats, for example: "doc,pdf,text"                                                                                 |
| upload\_max\_num           | int    | The maximum number of files that can be uploaded by a category, for example: 1,3                                                             |
| variable\_assign           | string | After parsing the file, assign the variable name (which needs to be defined in the dialog flow in advance), for example: "contract", "cards" |
| customized\_parse\_methods | array  | Custom Model Methods                                                                                                                         |
| file\_format               | string | Specify the format, specify the model and prompt for a specific format, for example: doc, pdf                                                |
| parse\_model               | string | Specify the model name                                                                                                                       |
| parse\_prompt              | string | Custom parsing prompt                                                                                                                        |

## 5. Example

Request packet:

```json
{
    "cybertron_robot_key": "xxx",
    "cybertron_robot_token": "xxx",
    "username": "xxx",
    "question": "File upload",
    "segment_code": "wWkE3bNkL3SzJX9orcO9P1",
    "message_source": "web"
}
```

Response packet:

```json
{
    "code": "000000",
    "message": "success",
    "dialog_id": 1017340986451495206,
    "type": "flow",
    "index": 0,
    "data": {
        "final": true,
        "id": 88043,
        "response_create_time": "2025-03-25 13:34",
        "response_create_time_timestamp": "1742880845978",
        "response_update_time": "2025-03-25 13:34",
        "response_update_time_timestamp": "1742880845978",
        "flow_uuid": "4cc96904-049f-11f0-80e7-0e8133e180cd",
        "history": [
            {
                "timestamp": 1742880846780,
                "time_date": "20250325133406780308",
                "node_id": "start00000000000000000000",
                "robot_user_replying": "",
                "robot_user_asking": "",
                "user_robot_replying": "File upload test"
            },
            {
                "timestamp": 1742880846918,
                "time_date": "20250325133406918821",
                "node_id": "f9b5d4d1-aa99-4c74-96db-642dfaf51f4d",
                "robot_user_replying": "Hello, so are you",
                "robot_user_asking": "",
                "user_robot_replying": "File upload test"
            }
        ],
        "output": {
            "inputs": {},
            "variables": {},
            "entities": {},
            "robot_user_asking": "",
            "user_robot_replying": "",
            "robot_user_replying": ""
        },
        "answer": {
            "type": "upload",
            "data": {
                "instruction": "Please start uploading your files",
                "upload_file_categories": [
                    {
                        "id": 77,
                        "name": "Audio test",
                        "support_formats": "wav",
                        "upload_max_num": 5,
                        "variable_assign_enable": true,
                        "variable_assign": "test_vvv",
                        "customized_parse_methods": [
                            {
                                "file_format": "",
                                "parse_model": "text",
                                "parse_prompt": ""
                            }
                        ]
                    }
                ],
                "flow_uuid": "4cc96904-049f-11f0-80e7-0e8133e180cd",
                "session_id": "c49bcd42-093a-11f0-be2b-820402e05f84",
                "node_id": "21a5fdec-2807-45cd-bc6e-430f26e6f682",
                "language": "zh",
                "steps": 2,
                "is_submit": false
            }
        },
        "content_type": "json",
        "session_id": "c49bcd42-093a-11f0-be2b-820402e05f84",
        "flow_stage": "flow_running",
        "code": "002010",
        "node_stream": 0,
        "node_answer_finish": "y",
        "node_answer_index": 0,
        "target_node_id": "21a5fdec-2807-45cd-bc6e-430f26e6f682",
        "source_node_id": "f9b5d4d1-aa99-4c74-96db-642dfaf51f4d",
        "cur_node_id": "21a5fdec-2807-45cd-bc6e-430f26e6f682",
        "parent_node_id": "f9b5d4d1-aa99-4c74-96db-642dfaf51f4d",
        "file_upload": {
            "instruction": "Please start uploading your files",
            "upload_file_categories": [
                {
                    "id": 77,
                    "name": "Audio test",
                    "support_formats": "wav",
                    "upload_max_num": 5,
                    "variable_assign_enable": true,
                    "variable_assign": "test_vvv",
                    "customized_parse_methods": [
                        {
                            "file_format": "",
                            "parse_model": "text",
                            "parse_prompt": ""
                        }
                    ]
                }
            ],
            "flow_uuid": "4cc96904-049f-11f0-80e7-0e8133e180cd",
            "session_id": "c49bcd42-093a-11f0-be2b-820402e05f84",
            "node_id": "21a5fdec-2807-45cd-bc6e-430f26e6f682",
            "language": "zh",
            "steps": 2,
            "is_submit": false
        }
    },
    "finish": "y",
    "cur_node_id": "21a5fdec-2807-45cd-bc6e-430f26e6f682",
    "node_id": "f9b5d4d1-aa99-4c74-96db-642dfaf51f4d",
    "debug": 0,
    "node_developer": 0,
    "flow_name": "vvvvv",
    "node_type": "file_upload",
    "node_title": "Node 3",
    "node_waiting": false,
    "flow_jump": 0,
    "file_upload": {
        "instruction": "Please start uploading your files",
        "upload_file_categories": [
            {
                "id": 77,
                "name": "Audio test",
                "support_formats": "wav",
                "upload_max_num": 5,
                "variable_assign_enable": true,
                "variable_assign": "test_vvv",
                "customized_parse_methods": [
                    {
                        "file_format": "",
                        "parse_model": "text",
                        "parse_prompt": ""
                    }
                ]
            }
        ],
        "flow_uuid": "4cc96904-049f-11f0-80e7-0e8133e180cd",
        "session_id": "c49bcd42-093a-11f0-be2b-820402e05f84",
        "node_id": "21a5fdec-2807-45cd-bc6e-430f26e6f682",
        "language": "zh",
        "steps": 2,
        "is_submit": false
    },
    "parent_node_id": "f9b5d4d1-aa99-4c74-96db-642dfaf51f4d",
    "node_waiting_input": 0,
    "node_waiting_jump": 0,
    "audio": "api/search-answer-speech/1017340986451495206_1.wav",
    "flow_node_dialog_id": "1017340986451495206_1"
}
```
