Polyv Help Center

Help Center

Send Custom Message

Updated: 2025-03-14 11:13:31

During peak platform message traffic, to ensure platform stability, there is a risk of message delay and loss. Use appropriately based on the scenario.

Interface Description

1、发送聊天室自定义消息
2、接口支持https协议

Interface URL

http://api.polyv.net/live/v4/chat/send-custom-message

Online API Call

Request Method

GET

Interface Constraints

  1. The interface supports both HTTP and HTTPS. HTTPS is recommended to ensure interface security. Interface calls have frequency limits. See details

  2. The text content (content) or image (imgUrl) to be sent cannot both be empty. They can be submitted simultaneously.

Request Parameter Description

Parameter Required Type Description
appId true String Account appId See details on obtaining keys]
timestamp true Long Current 13-digit millisecond timestamp, valid for 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 never be used directly on the client side. All APIs must be called through your own server to relay requests to the POLYV server for response data. See signature generation rules]
channelId true String Channel ID
content false String Text content to send, maximum 1000 characters. If special characters exist, they must be URL-encoded. Base64 encoding is not required.
imgUrl false String URL of the image to send
joinHistoryList false Integer Whether to include in chat history data. Default is 1.
1: Include in chat history data
0: Do not include
watchType false Integer The role(s) this message is intended for (default is 1, supports multiple selections, e.g., 4,5)
1: All roles in the channel
2: Only viewers in the channel
3: Only special roles (Instructor, Guest, Teaching Assistant, Admin)
4: Instructor
5: Guest
6: Teaching Assistant
7: Admin
important false String Whether it is an important message. Default is N.
Y: Important message
N: Normal message.
When important is Y, the interface request frequency is limited to a maximum of 30 requests per minute per channel, ensuring no message loss and no severe delay.

Example

http://api.polyv.net/live/v4/chat/send-custom-message?joinHistoryList=1&appId=frlr1zazn3&sign=144AA9135194EFB2DE8ED8071B05146C&channelId=3353399&content=%E6%B5%8B%E8%AF%95%E5%8F%91%E9%80%81%E8%87%AA%E5%AE%9A%E4%B9%89%E6%B6%88%E6%81%AF&timestamp=1662688236288

Response Parameter Description

Parameter Type Description
code Integer Status code, same as HTTP status code, used to determine the basic response status
status String Response result, determined by the business. Returns success on success, error on failure
success Boolean Whether the response was successful
requestId String Request ID, a unique UUID generated for each request. Only for troubleshooting and debugging, should not be tied to business logic
error Object Error information when the status code is not 200 See Error field description]
data Object Returns null on successful response

Error Parameter Description

Parameter Type Description
code Integer Error code, used to determine the specific error reason
desc String Error description, corresponding to error.code

Java Request Example

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

It is strongly recommended to use the Live Java SDK for API functionality 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(getClass());
/**
 * 发送聊天室自定义消息
 * @throws IOException
 * @throws NoSuchAlgorithmException
 */
@Test
public void sendCustomMessageTest() throws IOException, NoSuchAlgorithmException {
    //公共参数,填写自己的实际参数
    String appId = super.appId;
    String appSecret = super.appSecret;
    String timestamp = String.valueOf(System.currentTimeMillis());
    
    //业务参数
    String url = "http://api.polyv.net/live/v4/chat/send-custom-message";
    String channelId = "3353399";
    String content = "测试发送自定义消息";
    String joinHistoryList = "1";
    
    //http 调用逻辑
    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("appId", appId);
    requestMap.put("timestamp", timestamp);
    requestMap.put("channelId", channelId);
    requestMap.put("content", content);
    requestMap.put("joinHistoryList", joinHistoryList);
    
    requestMap.put("sign", LiveSignUtil.getSign(requestMap, appSecret));
    
    String response = HttpUtil.get(url, requestMap);
    
    log.info("测试发送聊天室自定义消息成功:{}", response);
    //do somethings
    
}

Response Example

For system-wide global error descriptions, see Global Error Description

Success Example

{
    "code": 200,
    "status": "success",
    "requestId": "61b9319c9e3b42979f8a152dfa6b3f40.66.16626882395269539",
    "data": null,
    "success": true
}

Error Example

{
    "code": 400,
    "status": "error",
    "requestId": "d310b70bc329403f87f77f9203d50f89.128.16360831552223589",
    "error": {
        "code": 20001,
        "desc": "application not found."
    },
    "success": false
}
联系客服,在线咨询