Instant Messaging
Send a directional message
Update time: 2023/10/23 15:39:54
Send a directional message in a chat room
Overview
Users can send messages to designated members in the chat room. Message types, such as text, image, audio, video, location, files, alert, and custom messages are supported.
- This API can send or resend a directed messages by setting
resendFlag
. For details, see the description of this parameter in Request Parameters below. - Saving directional messages in message history is not supported.
Request URI
POST https://api.netease.im/nimserver/chatroom/sendMsgToSomeone.action HTTP/1.1
Content-Type:application/x-www-form-urlencoded;charset=utf-8
Request parameters
-
For information about how to set the header in a POST request, see API Call methods.
-
The settings of the body in a POST request:
Parameter | Type | Required | Description |
---|---|---|---|
roomid | Long | Yes | Chat room ID |
msgId | String | Yes | message ID, using random strings such as uuid, messages with the same msgId will be deduplicated by the client.< /td> |
attach | String | No | Message body as the body field in message format example, up to 4,069 characters long. |
fromAccid | String | Yes | user account sending the message, accid |
toAccids | String | Yes | List of recipient accids, JSONArray, up to 100 accounts. |
msgType | Integer | Yes | Message types: 0: Text, 1: image, 2: audio, 3: video, 4: location, 6: file, 10: alert, 100: Custom message |
subType | Integer | No | Custom message subtype, a value greater than 0. |
resendFlag | Integer | No | Flage for resending a message, 0: Non-resent message, 1: Resent message. If a user resends a message, the deduplication logic will be applied based on `msgId`. |
route | Integer | No | Whether the message is synced using webhooks 0: No; 1: Yes (default)< /td> |
ext | String | No | extension field for messages, JSON, up to 4096 characters long. |
useYidun | Integer | No | Whether a message (including custom messages) uses GuardEase moderation service. Set the value to 0. Any other value indicates that the value is unspecified. 0: indicates that the message is not audited by the GuardEase moderation service when the moderation service is activated. If you do not specify this field, the message will be forwarded to GuardEase moderation service for review by default when the service is activated. |
yidunAntiCheating | String | No | The parameter for anti-cheating detection transferred in pass-through mode to GuardEase, JSON, with a maximum length of 1024 characters, (For details, please see GuardEase anti-spam exclusive field) |
yidunAntiSpamExt | String | No | The parameter for anti-spam enhanced transferred in pass-through mode to GuardEase, JSON, with a maximum length of 1024 characters, (for details, see GuardEase moderation service custom extension field) |
bid | String | No | Custom business ID of GuardEase moderation service. Custom moderation allows you to review the content of a single message in addition to the default moderation service. To configure custom moderation rules, contact our technical support using WhatsApp or online support for help. |
antispam | Boolean | No | For applications that have activated GuardEase moderation service, whether the message are reviewed by GuardEase (antispamCustom), default value:false Only valid for custom messages (message type: 100) |
antispamCustom | String | No | Custom moderation rules. Valid when the `antispam` parameter is set to `true`, JSON, length limit is the same as the body field. The maximum length is 5000 characters, the required antispamCustom format is as follows: {"type":1,"data":"custom content"} Field description: 1. type: 1: text; 2: image; 3: video 2. data: Text or image URL |
env | String | No | The environment name specified in the CommsEase console sync webhooks as shown in the figure below. A maximum of 32 characters are allowed. |
Response fields
Parameter | Type | Description |
---|---|---|
code | Integer | Response status code |
desc | String | Detailed description of the sent message. |
desc
representation
Parameter | Type | Description |
---|---|---|
time | Long | Timestamp of a sent message in milliseconds. |
fromAvator | String | Avatar of the message sender. |
msgid_client | Long | Client message ID |
fromClientType | String | Type of the client sending a message. |
roomId | Long | Chat room ID |
fromAccount | String | User account sending a message. accid |
fromNick | String | Nickname of the sender. |
attach | String | Message body |
type | Integer | Message type |
ext | String | Extension field |
highPriorityFlag | Integer | High priority message flag. Normal messages have no such flag. |
Example
Example request (cURL)
curl -X POST -H "CheckSum: 51eb13ea**1c65c7866c366" -H 'AppKey: fe416640c***e1847ad2547' -H "Nonce: 1" -H "CurTime: 1451207708" -H 'Content-Type: application/x-www-form-urlencoded' -d 'roomid=36&fromAccid=zhangsan&msgType=0&attach=This+is+test+msg&msgId=c9e6c306-804f-4ec3-b8f0-573778829419&toAccids=["acc1","acc2"]' 'https://api.netease.im/nimserver/chatroom/sendMsgToSomeone.action'
Example success response
"Content-Type": "application/json; charset=utf-8"
{
"code":200,
"desc":{
"time": "1456396333115",
"fromAvator": "http://b12026.nos.netease.com/MTAxMTAxMA==/bmltYV84NDU4OF8xNDU1ODczMjA2NzUwX2QzNjkxMjI2LWY2NmQtNDQ3Ni0E2LTg4NGE4MDNmOGIwMQ==",
"msgid_client": "111139",
"fromClientType": "REST",
"attach": "This is the message",
"roomId": "36",
"fromAccount": "zhansan",
"fromNick": "Zhangsan",
"type": "0",
"ext": ""
}
}
Example error response
"Content-Type": "application/json; charset=utf-8"
{
"code":414
"desc":"msgContents size exceeded" //Message body exceeded the size limit.
}
Status codes
The following status codes are related to responses of this API. For the complete error codes, see Status codes.
Code | Description | Recommendation |
---|---|---|
200 | Success | - |
414 | Parameter error | Check the format and restrictions of arguments based on the error message |
403 | Illegal operation | Exceptions, such as invalid chat room name, hit moderation rules or without the chat room permission. |
419 | Limit of chat rooms exceeded. | - |
13009 | The scheduled closing of chat rooms is disabled | Enable the chat room scheduled closing function |
Was this page helpful?
Yes
No