Instructor Replies to Student Questions via HTTP
Interface Description
Called by the business server to reply to a viewer's "private question" record as an instructor within a specified channel. Behavior aligns with the chat room WebSocket event T_ANSWER (writes question records, updates list data, and pushes messages to relevant online users). The interface supports the HTTPS protocol.
Interface URL
https://api.polyv.net/live/v5/chat/redirect/channel/teacher-answer/post
Request Method
POST
Interface Constraints
- The interface supports both HTTP and HTTPS; HTTPS is recommended for security.
viewerUserIdis the user ID of the viewer being replied to within the business system. If the viewer is currently online in the target channel as a viewer (connected to the chat room), the system can identify their connection and prioritize it for real-time push. If not online, the record will still be saved to the database, but real-time push may not reach the viewer.- Instructor Display Information: If an online instructor identity can be identified within the channel (consistent with the channel's agreed rules), the instructor's nickname, avatar, etc., will be used. If no online instructor information can be identified,
teacherNickandteacherPicmust be passed in the request, otherwise the display fields may be empty. msgTypeis optional; if not passed or empty, it is treated as text. Passingimageindicates an image reply, in which casecontentmust be a JSON string, with object fields:width(number),height(number),url(string),id(string, optional), consistent with the WebSocketT_ANSWERand in-site image question format; the server will perform image validation logic.
Request Body Parameters
| Parameter Name | Required | Type | Description |
|---|---|---|---|
| appId | true | String | Account appId See Get Secret Key |
| 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 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 to obtain response data. See Signature Generation Rules |
| roomId | true | String(1,100) | Channel ID (consistent with the channelId/roomId used by viewers/instructors when logging into the chat room) |
| content | true | String(1,10000) | The body text for text replies; when msgType is image, it must be a JSON string, serialized object format is { "width": number, "height": number, "url": string, "id"?: string } |
| viewerUserId | true | String(1,2000) | The userId of the viewer being replied to (the student's business ID on the questioning side) |
| teacherNick | false | String | Instructor nickname; recommended to pass when no online instructor information can be identified in the channel, otherwise the display may be empty |
| teacherPic | false | String | Instructor avatar URL; recommended to pass when no online instructor information can be identified in the channel |
| msgType | false | String | Optional. Pass image for image reply, consistent with WebSocket T_ANSWER; if not passed, it is treated as a text reply |
Examples
Request Body JSON:
{
"roomId": "412738",
"content": "同学你好,这个问题我们在第二节课会讲到。",
"viewerUserId": "user_abc_001",
"teacherNick": "王老师",
"teacherPic": "https://liveimages.videocc.net/defaultImg/avatar/viewer.png"
}
Image Reply Example (msgType is image, content is a JSON string):
{
"roomId": "412738",
"viewerUserId": "user_abc_001",
"msgType": "image",
"content": "{\"width\":640,\"height\":360,\"url\":\"https://example.com/img.png\",\"id\":\"img_001\"}",
"teacherNick": "王老师",
"teacherPic": "https://liveimages.videocc.net/defaultImg/avatar/viewer.png"
}
Response Body JSON (Success):
{
"code": 200,
"status": "success",
"message": "发送成功",
"data": {
"id": 123456
}
}
Where data.id is the record ID after the reply is written into the question flow (consistent with the id meaning in the T_ANSWER callback of the socket).
WebSocket Push Description
After a successful call, the server will push the message event to the chat room. The content is a JSON string. After parsing, EVENT is T_ANSWER. Main fields include: roomId, content, user (instructor display information), s_userId (the userId of the viewer being replied to), id (this reply's id), msgType, etc.
- Viewer: If the viewer is currently online in the channel's chat room, they can generally receive the above push. If they are offline or not connected, they will not receive the real-time message, but this reply can still appear in the historical question list (subject to each client's list interface).
- Instructor: If the instructor is currently online in the channel as an instructor, they can generally receive the push. If the instructor is not online or not connected with an identifiable identity, they may not receive the real-time push, but the record will still be written.
When sending T_ANSWER via the instructor-side WebSocket, it may also broadcast to the entire channel room. This HTTP interface primarily relies on the server to determine online connections and perform targeted pushes, consistent with the implementation.
Response Parameters
| Parameter Name | Type | Description |
|---|---|---|
| code | Integer | 200 indicates success; 400 mostly indicates parameter validation failure; 500 mostly indicates business errors or server exceptions |
| status | String | success / fail / error |
| message | String | Prompt text, such as "Sent successfully" or specific error description |
| data | Object | Contains id (reply record ID) on success; can be empty or include validation information on failure |
Error Examples
Parameter Validation Failure (consistent with checkDataType return):
{
"code": 400,
"status": "fail",
"message": "缺少参数roomId"
}
Channel and Account Mismatch (x-auth-user-id and roomId do not belong to the same entity):
{
"code": 400,
"status": "fail",
"message": "roomId非法"
}
x-auth-user-id Not Passed (middleware returns directly, HTTP status code is mostly 500, body is still JSON):
{
"code": 400,
"status": "fail",
"message": "accountId is required"
}
Server Exception:
{
"code": 500,
"status": "error",
"message": "unknown error"
}
(The specific message depends on the actual error message.)
