
# 推送消息（pushMsg）
#### 场景描述
推送消息接口，包括连接，发送输入状态，会话，转人工，断连多种类型消息
![](https://support.huaweicloud.com/api-ccfs-cec/public_sys-resources/notice_3.0-zh-cn.png)
仅WEB渠道开启消息推送，且认证方式为OAuth时，可以使用该接口。
#### 接口方法
POST
#### 接口URI
https://域名/apiaccess/ccmessaging/pushMsg，例如域名是service.besclouds.com
HTTPS采用TLS1.2及以上版本，确保web应用的敏感数据在传输过程中不被非法截获
#### 请求说明
表1请求头参数 
| 序号 | 名称            | 参数类型   | 是否必选 | 说明                                                            |
|:---|:---|:---|:---|:---|
| 1  | x-app-key     | string | true | appKey字段，用户标识，在API Fabric上配置                                  |
| 2  | Authorization | string | true | 鉴权字段，内容格式为: Bearer +tokenByAKSK接口的返回值中AccessToken（Bearer后有空格） |
   
表2请求体参数 
| 序号 | 名称        | 参数类型                                                                                                                             | 是否必选 | 说明                |
|:---|:---|:---|:---|:---|
| 1  | messages  | list\[[DownLinkMsg]\] | True | 消息和事件             |
| 2  | timestamp | long                                                                                                                             | True | 发送时间，将用于生成身份验证签名。 |
   
 表3DownLinkMsg参数结构 
| 序号 | 名称              | 参数类型    | 是否必选  | 说明                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
|:---|:---|:---|:---|:---|
| 1  | channel         | string  | True  | 消息通道类型，如WEB。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| 2  | isOfflineStatus | Boolean | False | 用于客户端判断下一步是否可以发送消息。 当用户等待超时时，AICC将推送消息。 如果异步开关打开，则该值将为true。 如果异步开关关闭，则该值将为false。                                                                                                                                                                                                                                                                                                                           |
| 3  | content         | string  | True  | 发送给客户的MT消息的内容。 如果controlType为聊天，则 如果媒体类型为文本， 取值为文本内容。 如果mediaType为图像/视频/AUDIO，则值为资源的id，客户端应使用下载文件流API获取资源。 如果mediaType为LOCATE，则取值为位置信息，格式为纬度/经度/描述。如果controlType为读取，则该值为已读取的messageId数组。 |
| 4  | from            | string  | True  | 消息发送者的ID。渠道ID。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| 5  | mediaType       | string  | True  | 消息媒体类型，例如文本类型（TEXT）、图像（IMAGE）、视频（VIDEO）、语音（AUDIO）、位置（LOCATE）和文档（DOCUMENT）。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| 6  | senderNickname  | string  | False | 消息发送者的昵称。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| 7  | sourceType      | string  | True  | 消息发送者，例如代理（代理）、机器人（机器人）和系统（系统）。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| 8  | controlType     | string  | True  | 消息控制类型，如连接（连接）聊天（聊天）和断开（断开）、转人工服务（Trans2Agent）、读取报告（读取）                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| 9  | timestamp       | long    | True  | 消息发送时间戳。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| 10 | to              | string  | True  | 用户标识                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| 11 | simQuestions    | string  | False | 相似性问题内容。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| 12 | messageCode     | string  | False | 用于标识发送的消息代理的唯一值。最大长度为64。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
   
#### 响应说明
- **响应状态码: 200**
  表4响应体参数 
  | 序号 | 名称         | 参数类型   | 说明                                             |
  |:---|:---|:---|:---|
  | 1  | resultCode | String | 0表示成功，如果返回的响应状态码不是200或resultCode不为0，则表示推送消息失败。 |
  | 2  | resultDesc | String | 开发人员自定义                                        |
     
  

- **响应状态码: 400**
  错误的请求：请检查请求路径及参数。
  
- **响应状态码: 401**
  未授权：1.请确认是否购买了相关服务。2.请联系客服人员检查您账号的当前状态。
  
- **响应状态码: 404**
  请求的内容未找到：请检查请求的路径。
  
- **响应状态码: 500**
  业务失败：请依次确认您请求中各参数的取值。
  
 
#### 错误码
无。
#### 报文样例
- 请求头：
  ```
  Authorization:Bearer e******************************e
  x-app-key:e******************************0
  Content-Type:application/json
  ```
  
- 请求参数：
  ```
  //1connected
  {
      "timestamp": 1625898453913,
      "messages": [{
          "from": "202105284494222653",
          "channel": "WEB",
          "to": "44444444",
          "controlType": "CHAT",
          "mediaType": "TEXT",
          "content": "The call is connected to an agent.",
          "simQuestions": null,
          "senderNickname": "SYSTEM",
          "timestamp": 1625898453913,
          "sourceType": "SYSTEM",
          "callId": null,
          "messageCode": null
      }]
  }
  //queuing
  {
          "from": "202105284494222653",
          "channel": "WEB",
          "to": "44444444",
          "controlType": "CHAT",
          "mediaType": "TEXT",
          "content": "Queuing...",
          "simQuestions": null,
          "senderNickname": "SYSTEM",
          "timestamp": 1625898453913,
          "sourceType": "SYSTEM", 
          "messageCode": null
      }
  //disconnect because of agent
  {
          "from": "202105284494222653",
          "channel": "WEB",
          "to": "44444444",
          "controlType": "DISCONNECT",
          "mediaType": null,
          "content": null,
          "simQuestions": null,
          "senderNickname": null,
          "timestamp": 1625898871961,
          "sourceType": "AGENT",
          "messageCode": null   
      }
  //disconnect because of timeout, and async switch is off
  {
          "from": "202105284494222653",
          "channel": "WEB",
          "to": "44444444",
          "controlType": "DISCONNECT",
          "mediaType": null,
          "content": null,
          "simQuestions": null,
          "senderNickname": null,
          "timestamp": 1625898871961,
          "sourceType": "SYSTEM",
          "messageCode": null    
      }
  //disconnect because of timeout, and async switch is on
  {
          "from": "202105284494222653",
          "channel": "WEB",
          "to": "44444444",
          "controlType": "DISCONNECT",
            "isOfflineStatus":true,
          "mediaType": "TEXT",
          "content": "{TIPS}",
          "simQuestions": null,
          "senderNickname": null,
          "timestamp": 1625898871961,
          "sourceType": "SYSTEM",
          "messageCode": null    
      }
  //read
  {
          "from": "202105284494222653",
          "channel": "WEB",
          "to": "44444444",
          "controlType": "READ",
          "mediaType": null,
          "content": "messageId1,messageId2",
          "simQuestions": null,
          "senderNickname": null,
          "timestamp": 1625898871961,
          "sourceType": "AGENT",
          "messageCode": null   
      }
  ```
  
- 响应参数：
  ```
  {
      "resultCode": "0",
      "resultDesc": "success."
  }
  ```
  
 
