sendMessageNotOss
Feature Introduction
Description
Send a message.
Note
You need to first invoke createXXXMessage
to create a message. Messages created by createXXXMessageByURL
must be sent through this interface.
Related Callbacks:
onConversationChanged
onRecvNewMessage
onRecvNewMessages
- iOS
- Android
- Flutter
- uni-app
- Browser/Electron/MiniProgram
- React-Native
- Unity
Function Prototype
Future<Message> sendMessageNotOss({
required Message message,
required OfflinePushInfo offlinePushInfo,
String? userID,
String? groupID,
String? operationID,
})
Input Parameters
Parameter Name | Parameter Type | Required | Description |
---|---|---|---|
message | Message | Yes | Message body |
userID | String | No | User ID of the message recipient |
groupID | String | No | Group ID of the message recipient |
offlinePushInfo | OfflinePushInfo | No | Offline message body |
Return Result
Name | Type | Description |
---|---|---|
~ | Message | Successful return |
Code Example
Message msg = await OpenIM.iMManager.messageManager.sendMessageNotOss(message: message, offlinePushInfo: offlinePushInfo);
// todo
Function Prototype
- (void)sendMessageNotOss:(OIMMessageInfo *)message
recvID:(NSString * _Nullable)recvID
groupID:(NSString * _Nullable)groupID
offlinePushInfo:(OIMOfflinePushInfo * _Nullable)offlinePushInfo
onSuccess:(nullable OIMMessageInfoCallback)onSuccess
onProgress:(nullable OIMNumberCallback)onProgress
onFailure:(nullable OIMFailureCallback)onFailure;
Input Parameters
Parameter Name | Parameter Type | Required | Description |
---|---|---|---|
message | OIMMessageInfo | Yes | Message body |
recvID | NSString | No | User ID of the message recipient |
groupID | NSString | No | Group ID of the message recipient |
offlinePushInfo | OIMOfflinePushInfo | No | Offline message body |
Return Result
Name | Type | Description |
---|---|---|
onSuccess | OIMMessageInfo | Successful return |
onProgress | NSInteger | Sending progress |
onFailure | OIMFailureCallback | Failed return |
Code Example
OIMMessageInfo *testMessage = [OIMMessageInfo createSoundMessageByURL:@"https://xxx"
duration:1
size:1];
[OIMManager.manager sendMessageNotOss:testMessage
recvID:@""
groupID:@""
offlinePushInfo:nil
onSuccess:^(OIMMessageInfo * _Nullable message) {
} onProgress:^(NSInteger number) {
} onFailure:^(NSInteger code, NSString * _Nullable msg) {
}];
Function Prototype
public void sendMessageNotOss(OnMsgSendCallback base, Message message, String recvUid, String recvGid, OfflinePushInfo offlinePushInfo)
Input Parameters
Parameter Name | Parameter Type | Required | Description |
---|---|---|---|
base | OnMsgSendCallback | Yes | callback |
message | Message | Yes | Message body |
userID | String | No | User ID receiving the message |
groupID | String | No | Group ID receiving the message |
offlinePushInfo | OfflinePushInfo | No | Offline message body |
Return Result
Name | Type | Description |
---|---|---|
~ | Message | Returns on success |
Code Example
OpenIMClient.getInstance().messageManager.sendMessageNotOss( new OnMsgSendCallback(){
public void onError(int code, String error) {
//Send failed
}
public void onProgress(long progress) {
//Sending progress
}
public void onSuccess(Message s) {
//Sent successfully
}
}, message, recvUid, recvGid, offlinePushInfo);
Function Prototype
IMSDK.sendMessageNotOss({
recvID: string;
groupID: string;
offlinePushInfo?: OfflinePush;
message: MessageItem;
}, operationID?: string): Promise<WsResponse<MessageItem>>
Input Parameters
Parameter Name | Parameter Type | Required | Description |
---|---|---|---|
message | MessageItem | Yes | Message body |
recvID | string | Yes | User ID receiving the message, pass an empty string when sending group messages |
groupID | string | Yes | Group ID receiving the message, pass an empty string when sending private messages |
offlinePushInfo | OfflinePushInfo | No | Offline message body |
Return Result
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<WsResponse<MessageItem>> | Successful callback |
Promise.catch() | Promise<WsResponse> | Failed callback |
Code Example
import { getSDK } from '@openim/wasm-client-sdk';
const IMSDK = getSDK();
// use in electron with ffi
// import { getWithRenderProcess } from '@openim/electron-client-sdk/lib/render';
// const { instance: IMSDK } = getWithRenderProcess();
// use in mini program
// import { getSDK } from '@openim/client-sdk';
// const IMSDK = getSDK();
IMSDK.sendMessageNotOss({
recvID: "userID",
groupID: "",
message: {
// MessageItem details
...
}
})
.then(({ data }) => {
// Call successful
})
.catch(({ errCode, errMsg }) => {
// Call failed
});
Function Prototype
IMSDK.asyncApi('sendMessageNotOss', operationID: string, {
recvID: string;
groupID: string;
offlinePushInfo?: OfflinePush;
message: MessageItem;
}): Promise<void>
Input Parameters
Parameter Name | Parameter Type | Required | Description |
---|---|---|---|
operationID | string | Yes | Operation ID for problem tracking, unique, recommended to use the current time and random number |
message | MessageItem | Yes | Message body |
recvID | string | Yes | User ID receiving the message, pass an empty string when sending group messages |
groupID | string | Yes | Group ID receiving the message, pass an empty string when sending private messages |
offlinePushInfo | OfflinePushInfo | Yes | Offline message body |
Return Result
Using the
openim-uniapp-polyfill
package, the function is Promisified. Usethen
andcatch
to judge and handle the successful and failed callbacks respectively.
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<void> | Successful callback |
Promise.catch() | Promise<CatchResponse> | Failed callback |
Code Example
import IMSDK from 'openim-uniapp-polyfill';
IMSDK.asyncApi('sendMessageNotOss', IMSDK.uuid(), {
recvID: "userID",
groupID: "",
message: {
// MessageItem details
...
},
offlinePushInfo: {
title: 'you have a new message',
desc: 'new message',
ex: '',
iOSPushSound: '+1',
iOSBadgeCount: true,
}
})
.then((data) => {
// Call successful
})
.catch(({ errCode, errMsg }) => {
// Call failed
});
Function Prototype
OpenIMSDKRN.sendMessageNotOss({
recvID: string;
groupID: string;
offlinePushInfo?: OfflinePush;
message: MessageItem;
}, operationID: string): Promise<void>
Input Parameters
Parameter Name | Parameter Type | Required | Description |
---|---|---|---|
operationID | string | Yes | Operation ID for problem tracking, unique, recommended to use the current time and random number |
message | MessageItem | Yes | Message body |
recvID | string | Yes | User ID receiving the message, pass an empty string when sending group messages |
groupID | string | Yes | Group ID receiving the message, pass an empty string when sending private messages |
offlinePushInfo | OfflinePushInfo | Yes | Offline message body |
Return Result
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<void> | Callback on successful call |
Promise.catch() | Promise<CatchResponse> | Callback on failed call |
Code Example
import OpenIMSDKRN from "open-im-sdk-rn";
OpenIMSDKRN.sendMessageNotOss({
recvID: "userID",
groupID: "",
message: {
// MessageItem
...
},
offlinePushInfo: {
title: 'you have a new message',
desc: 'new message',
ex: '',
iOSPushSound: '+1',
iOSBadgeCount: true,
}
}, 'operationID')
.then((data) => {
// Call successful
})
.catch(({ errCode, errMsg }) => {
// Call failed
});
Function Prototype
public static void SendMessageNotOSS(IMsgSendCallBack cb, Message message, string recvId, string groupId, OfflinePushInfo offlinePushInfo, bool isOnlineOnly)
Input Parameter
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
cb | IMsgSendCallBack | Yes | Callback |
message | Message | Yes | Message body |
userId | string | Yes | User ID receiving the message, pass an empty string when sending group messages |
groupId | string | Yes | Group ID receiving the message, pass an empty string when sending private messages |
offlinePushInfo | OfflinePushInfo | Yes | Offline message body |
isOnlineOnly | bool | Yes | The receiver must be online to receive it, otherwise it will be lost. |
Return Result
Parameter Name | Type | Description |
---|---|---|
~ | Message | Message Struct |
Code Example
var callback = new MsgSendCallBack();
IMSDK.SendMessageNotOSS(callback,msg ,recvId,groupId,new OfflinePushInfo(){},false);