This topic explains how to secure message content when you implement custom messages, such as likes and live comments.
Message type
The message type is defined as an int and can be used flexibly.
The message type must be a positive integer. If you do not specify a message type or set it to 0 when you query or replay messages, the system retrieves all message types by default.
For example, you can define 10001 as a 'like', 10002 as a 'gift', and 10003 as a 'live comment' sent by a viewer. This categorization method lets you accurately classify and efficiently process various types of interactive messages.
Message body
The message body is a string that you can use flexibly. When a client receives a message, it arrives as a string. The SDK then passes the message to your business logic through a callback. For more information, see Listen for messages. For example, you can pass JSON content in the following format as the message body.
{
"flashurl":"xxxxxxxx",
"name":"Grand Voyage",
"xxxx":"xxxxxxxxx",
"backimg":"xxxxxxxxx",
...
}Security review
Messages sent from the server-side through OpenAPI do not undergo the security review process.
If you enable the security review feature during application initialization, messages sent from a client are submitted for review, unless you configure them to skip the review.
Security reviews incur fees. Perform security reviews only on user-input content. For content such as gifts and likes, configure the messages to skip the security review.
If a message fails the security review, the system sends the result to the sender and triggers the client's
onFailurecallback. This callback indicates that the message failed to send because it did not pass the security review.ImSendMessageToGroupReq req = new ImSendMessageToGroupReq(); /** * Set the message level. The default value is NORMAL. For more information, see the description of message priority and throttling. */ req.level = ImMessageLevel.NORMAL; req.type = 88888; req.data = "a test"; req.groupId = groupId; // Make sure you have successfully joined the group (that is, after the AliVCIMGroupInterface.joinGroup callback indicates success) before you send a group message. Otherwise, error code 425 is returned. messageInterface.sendGroupMessage(req, new ImSdkValueCallback<ImSendMessageToGroupRsp>() { @Override public void onSuccess(ImSendMessageToGroupRsp data) { Log.v(ImTag.TAG, "Group message sent successfully:" + data.messageId); } @Override public void onFailure(Error error) { Log.v(ImTag.TAG, "Failed to send group message" + error.code); } });
Prevent custom messages from interfering with security reviews
JSON strings can contain extra information, such as hyperlinks, which the security review service might flag as malicious advertising. The client's message sending interface provides a separate field for security review content. Use this field to separate the content for review from the actual message content that you send.
For example, if the user-input content for review is hello, the full JSON content sent is as follows.
{
"xxxx":"xxxxxxxxx",
"backimg":"xxxxxxxxx",
"content":"hello",
...
}