sendMessage method
dynamic
sendMessage(
- String content
)
Implementation
sendMessage(String content) async {
V2TimValueCallback<V2TimMsgCreateInfoResult> createRes =
await TencentImSDKPlugin.v2TIMManager
.getMessageManager()
.createTextMessage(text: content);
bool? sendFailed;
if (createRes.code == 0) {
if (createRes.data != null) {
if (createRes.data!.id != null) {
var id = createRes.data!.id!;
TencentCloudChatRobotUtils.emitPluginEvent(
TencentCloudChatRobotPluginEventType.onCreateMessageSuccess,
Map<String, dynamic>.from({
"desc": "ok",
"data": json.encode(createRes.data!.messageInfo?.toJson()),
}),
);
var sendRes = await TencentImSDKPlugin.v2TIMManager
.getMessageManager()
.sendMessage(
id: id, receiver: widget.robotData.robotID, groupID: "");
if (sendRes.code == 0 && sendRes.data != null) {
TencentCloudChatRobotUtils.emitPluginEvent(
TencentCloudChatRobotPluginEventType.onSendMessageToRobotSuccess,
Map<String, dynamic>.from({
"desc": "ok",
"data": json.encode(sendRes.data!.toJson()),
}),
);
return;
} else {
sendFailed = false;
}
}
}
}
TencentCloudChatRobotUtils.emitPluginEvent(
TencentCloudChatRobotPluginEventType.onError,
Map<String, dynamic>.from({
"desc": "sendmessage to robot error",
"dara": json.encode(createRes.toJson()),
"sendFailed": sendFailed,
}),
);
}