> For the complete documentation index, see [llms.txt](https://bothub.gitbook.io/project/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bothub.gitbook.io/project/advanced-tool/api/fa-song-livechat-qing-qiu.md).

# 发送liveChat请求

发送liveChat请求，开启或关闭liveChat

## 发送请求，开启或关闭liveChat <a href="#fa-song-mo-ban-xiao-xi-shi-yong-zi-zhu-ding-yi-de-bian-liang" id="fa-song-mo-ban-xiao-xi-shi-yong-zi-zhu-ding-yi-de-bian-liang"></a>

用户可以在whatsapp上进行智能对话或进行人工对话。当需要人工对话时，Botchat发起开启livechat(状态)请求；若太久未有人工接通，则botchat可发送关闭liveChat(状态)请求；而如果等待到真正接起人工时，livechat向botchat发送start\_licechat信号，通知其已接通人工，不用再理会用户的操作；当人工对话结束时livechat向botchat发起关闭liveChat(状态)请求，继续进行智能对话。

![chat status](https://3545383198-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LBxiFMKIFEMsz8J7IuU%2F-LfOFpjaSO_P8UNXdbro%2F-LfOFuVUtDanGUq2JEOZ%2Fchat%20status.png?alt=media\&token=d5b43dee-2320-4b13-b88b-69deadd93bb3)

### 发送请求

您可以用任意一个已经启用的API Key([怎样申请APIKey](https://bothubdocs.gitbook.io/project/~/edit/drafts/-LCWfeDNA9QGt2vCxD8D/untitled-2/api-jie-shao/kai-shi-shi-yong-api)) 向Moli发起关闭liveChat请求、向Bot发起开启livechat请求。这个请求的说明如下：

| 请求属性      | 属性名          | 说明                                                                                    |
| --------- | ------------ | ------------------------------------------------------------------------------------- |
| 地址        |              | [https://api.bothub.ai/channels/{bot\_phone}/switch\_livechat](https://api.bothub.ai) |
| 请求方式      | POST         |                                                                                       |
| Header    | APIKEY       | 您的API KEY.                                                                            |
| Header    | Content-Type | application/json                                                                      |
| Form Data | id           | 由WhatsApp分配的消息ID                                                                      |
| Form Data | user\_id     | 用户的手机号                                                                                |
| Form Data | source       | 信号来源(botchat/livechat)                                                                |
| Form Data | signal       | 信号(start\_livechat或stop\_livechat)                                                    |
| Form Data | meta         | 先决条件信息　json (当signal为start\_livechat时为必须)                                             |

### **请求样例**

{% code title="" %}

```javascript
{
    "id" : "<unique request identifier>",
    "user_id" : "<phone number of the user>",
    "source" : "<botchat / livechat>",
    "signal" : "<start_livechat / stop_livechat>",
    "meta" : {
        "selected_email" : "<email of the user>"
    }
}
```

{% endcode %}

### 请求返回值

* 成功返回值样例

```javascript
{
    "result": true,
    "data": {}
}
```

* 失败返回值样例

```javascript
{
    "error": {
        "code": 10011,
        "error_subcode": 0,
        "type": "",
        "message": "Request already processed",
        "request_id": 35122312158
    }
}
```

### 错误码列表

| 返回值   | 内容                           |
| ----- | ---------------------------- |
| 10000 | 内部错误                         |
| 10001 | 未指定API KEY                   |
| 10002 | 无效的API KEY                   |
| 10003 | 未指定Request id                |
| 10004 | 未指定调用API的种类                  |
| 10005 | 无效的API种类                     |
| 10005 | 无效的API种类                     |
| 10006 | Bot不存在或者已经被删除                |
| 10011 | Request id与之前的重复             |
| 10100 | 参数无效                         |
| 18000 | 内部错误                         |
| 19000 | 回调超时                         |
| 41006 | 未指定id                        |
| 41026 | 未指定user\_id                  |
| 41027 | 未指定signal                    |
| 41033 | 未指定meta                      |
| 41034 | meta类型错误，应为json              |
| 41035 | 未指定source                    |
| 41036 | source值错误，应为botchat/livechat |
| 90001 | livechat subscriber error    |
| 90002 | network error                |
| 90003 | livechat请求不在人工作息时间内          |

###
