Polyv Help Center

Help Center

Admin Sends Chat Message

Updated: 2023-12-21 14:35:02

API Description

1、通过HTTP接口发送聊天文本内容,可指定发言者的头像、头衔、昵称,无需连接聊天室
2、接口支持https协议
3、文本消息和图片消息必传一个

API URL

http://api.polyv.net/live/v3/channel/chat/send-admin-msg

Online API Call

Request Method

POST

API Constraints

  1. The API supports both HTTP and HTTPS. HTTPS is recommended to ensure interface security. API calls have frequency limits. Click for details

Request Parameter Description

Parameter Required Type Description
appId true String Account appId [See Get Secret Key]
timestamp true Long Current 13-digit millisecond timestamp, valid within 3 minutes
sign true String Signature, a 32-character uppercase MD5 value. The appSecret key used to generate the signature is critical for communication data security. It must not be stored or used directly on the client side. All APIs must be called through the customer's own server to relay requests to the POLYV server for response data. [See Signature Generation Rules]
channelId true String Channel ID
msg false String Text message to send. Either a text message or an image message must be provided. Maximum length is 2000 characters.
imgUrl false String Image message URL to send. The URL does not support parameters. Either a text message or an image message must be provided.
When sending an image message, the set nickname, title, and avatar will not take effect temporarily.
pic true String Admin avatar. The URL does not support parameters.
nickName true String Nickname, maximum length is 8 characters. Excess will be truncated.
adminIndex false Integer Admin index. Multiple admins can be specified to send messages. Default is one admin.
actor false String Title, maximum length is 4 characters. Excess will be truncated. If not provided, no title is displayed.
freeReview false String Whether the message needs to go through review when the channel has review enabled. Default is N.
Y: Not required
N: Required
apiVersion true String API version. Currently available version (3.2). Different versions may have slight differences in returned data. See response examples for details.

Example

http://api.polyv.net/live/v3/channel/chat/send-admin-msg

Form Parameters:

msg=测试发送图文信息&actor=大管理员&apiVersion=3.2&nickName=西瓜籽&appId=frlr1zazn3&freeReview=&sign=03430C8D280F64B4FCF9848D6E3E3993&adminIndex=1&pic=https://thirdwx.qlogo.cn/mmopen/vi_32/3lMXVJoLMLJibnkFuA23lyqj5MOQufhW5ATvHuB8byssutficHKU0u7OMx5OQgg9WNVuHf44AXfbAMMAZejuYFTg/132&channelId=2191569&timestamp=1616641479456

Response Parameter Description

Parameter Type Description
code Integer Response status code. 200 indicates success, non-200 indicates failure. [See Global Error Description]
status String Response status text
message String Response description. When code is 400 or 500, provides additional error reason.
data String Returns "Sent successfully" or message ID on success, depending on the apiVersion parameter. See response examples for details. Returns an empty string on error.

Java Request Example

For quick integration of basic code, please download the relevant dependency source code. Click here to download source code. After downloading, add it to your own source code project. HttpUtil.java and LiveSignUtil.java in the test cases are included in the downloaded file.

It is strongly recommended to use the Live Java SDK for API integration. The Live Java SDK provides unified encapsulation and optimization for API call logic, exception handling, data signing, and HTTP request thread pools.

private static final Logger log = LoggerFactory.getLogger(ChatMessageTest.class);
/**
 * 发送图文信息
 * @throws IOException
 */
@Test
public void testSendMessage() throws IOException, NoSuchAlgorithmException {
        //公共参数,填写自己的实际参数
        String appId = super.appId;
        String appSecret = super.appSecret;
        String timestamp = String.valueOf(System.currentTimeMillis());

        //业务参数
        String url = "http://api.polyv.net/live/v3/channel/chat/send-admin-msg";
        String channelId = "2191569";
        Integer adminIndex = 1;
        String msg = "测试发送图文信息";
        String pic = "https://thirdwx.qlogo.cn/mmopen/vi_32/3lMXVJoLMLJibnkFuA23lyqj5MOQufhW5ATvHuB8byssutficHKU0u7OMx5OQgg9WNVuHf44AXfbAMMAZejuYFTg/132";
        String nickName = "西瓜籽";
        String actor = "大管理员";
        String freeReview = "";
        String apiVersion = "3.2";

        //http 调用逻辑
        Map<String,String> requestMap = new HashMap<>();
        requestMap.put("appId", appId);
        requestMap.put("timestamp",timestamp);
        requestMap.put("channelId",channelId);
        requestMap.put("adminIndex",adminIndex.toString());
        requestMap.put("msg",msg);
        requestMap.put("pic",pic);
        requestMap.put("nickName",nickName);
        requestMap.put("actor",actor);
        requestMap.put("freeReview",freeReview);
        requestMap.put("apiVersion",apiVersion);
        requestMap.put("sign",LiveSignUtil.getSign(requestMap, appSecret));
        String response = HttpUtil.postFormBody(url, requestMap);
        log.info("测试发送聊天室消息接口返回值:{}",response);

}

Response Example

For global system error descriptions, see Global Error Description

Success Example - When apiVersion is not set

{
  "code": 200,
  "status": "success",
  "message": "",
  "data": "发送成功"
}

Success Example - When apiVersion is set to 3.1

{
    "code": 200, 
    "status": "success", 
    "message": "", 
    "data": {
        "msgId":"a16610f0-852f-11eb-b491-81c8f28f8d72"
    }
}

Error Example

{
  "code": 400,
  "status": "error",
  "message": "invalid signature.",
  "data": ""
}
联系客服,在线咨询