
# 消息推送接口规格
#### 场景描述
AICC将调用此API推送座席回复的消息或系统消息。
#### 接口方法
POST
#### 接口URI
{baseUrl}/webhooks/v1/messages
HTTPS采用TLS1.2及以上版本，确保web应用的敏感数据在传输过程中不被非法截获
#### 请求说明
表1请求头参数 
| 序号 | 名称            | 参数类型   | 是否必选 | 说明                                                        |
|:---|:---|:---|:---|:---|
| 1  | Authorization | string | True | 用于身份验证。值为auth-v2/{accessKey}/{timestamp}/{SignedHeaders}。 |
   
表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 | True  | 0表示成功，如果返回的响应状态码不是200或resultCode不为0，则表示推送消息失败。 |
| 2  | resultDesc | String | False | 开发人员自定义                                        |
   
#### 报文样例
- 请求头：
  ```
  Authorization:Bearer e******************************e
  Content-Type:application/json
  ```
  
- 请求参数：
  ```
  {
      "timestamp": 1625898453913,
      "messages": [//1connected{
          "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[D1]  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[D2] ",
          "simQuestions": null,
          "senderNickname": null,
          "timestamp": 1625898871961,
          "sourceType": "AGENT",
          "messageCode": null,    
      }
  ]
  }
  ```
  
- 响应参数：
  ```
  {
      "resultCode": "0",
      "resultDesc": "success."
  }
  ```
  
 
