sendMessage method
- ChatMessage message
~english Sends a message.
Note For attachment messages such as voice, image, or video messages, the SDK automatically uploads the attachment. You can set whether to upload the attachment to the chat sever using ChatOptions.serverTransfer.
To listen for the status of sending messages, call ChatManager.addMessageEvent.
Param message
The message object to be sent: ChatMessage
.
Throws A description of the exception. See ChatError. ~end
~chinese 发消息
Note 对于语音、图片、视频等附件消息,SDK会自动上传附件。 可以使用 ChatOptions.serverTransfer 设置是否将附件上传到聊天服务器。
添加发送状态监听使用 ChatManager.addMessageEvent.
Param message
需要发送的消息 ChatMessage
.
Throws 如果有异常会在这里抛出,包含错误码和错误描述,详见 ChatError。 ~end
Implementation
Future<ChatMessage> sendMessage(ChatMessage message) async {
message.status = MessageStatus.PROGRESS;
Map result = await ChatChannel.invokeMethod(
ChatMethodKeys.sendMessage, message.toJson());
try {
ChatError.hasErrorFromResult(result);
ChatMessage msg =
ChatMessage.fromJson(result[ChatMethodKeys.sendMessage]);
message.from = msg.from;
message.to = msg.to;
message.status = msg.status;
return message;
} on ChatError catch (e) {
throw e;
}
}