TIMMsgSendMessageV2
功能介绍
发送消息V2
发送新消息,单聊消息和群消息的发送均采用此接口。
V2TimMessage 中可以携带不同类型子类,表示不同类型的消息。
发送消息首先通过createXXXMessage创建不同种类的信息,再通过sendMessage根据消息id发送。
发送单聊消息时 conv_id 为对方的UserID, conv_type 为 Conv_C2C
发送群聊消息时 conv_id 为群ID, conv_type 为 Conv_Group 。
发送消息时不能发送 kTIMElem_GroupTips 、 kTIMElem_GroupReport ,他们由为后台下发,用于更新(通知)群的信息。可以的发送消息内元素
与TIMMsgSendMessage不同的是他的返回值不一样并且增加了callback参数
参数详解
参数名称 | 参数类型 | 是否必填 | 描述 |
---|---|---|---|
msgSendMessageParams | MsgSendMessageParamsV2 | 是 | 发送消息的参数 |
返回模板
Promise<commonResponse>
{
code: TIMResult | TIMErrCode;
desc?: string | undefined;
json_param?: string | undefined;
json_params?: string | undefined; // 兼容
user_data?: string | undefined;
}
返回值详解
名称 | 数值类型 | 描述 |
---|---|---|
code | TIMResult | TIMErrCode | 返回状态码 |
desc | string | undefined | 返回描述 |
json_param | string | undefined | 根据具具体接口返回 |
json_params | string | undefined | 兼容的字段,某些情况下会返回这个,根据具体接口返回 |
user_data | string | undefined | ImSDK负责透传的用户自定义数据,未做任何处理 |
代码示例
import TimRender from "im_electron_sdk/dist/renderer";
const timRenderInstance = new TimRender();
import { MsgSendMessageParamsV2,Json_value_msg,userProfileCustom,userProfile,GroupMemberInfo,GroupMemberInfoCustemString } from "im_electron_sdk/dist/interfaces";
let userProfileCustom:userProfileCustom = {
user_profile_custom_string_info_key: '',
user_profile_custom_string_info_value: 'string;'
}
let groupMemberCustom : GroupMemberInfoCustemString = {
group_member_info_custom_string_info_key: '',
group_member_info_custom_string_info_value: '',
}
let groupMemberInfo:GroupMemberInfo ={
group_member_info_identifier: '',
group_member_info_join_time: 0,
group_member_info_member_role: 0,
group_member_info_msg_flag: 0,
group_member_info_msg_seq: 0,
group_member_info_shutup_time: 0,
group_member_info_name_card: '',
group_member_info_custom_info: [groupMemberCustom]
}
let senderProfile:userProfile = {
user_profile_add_permission: 0,
user_profile_birthday:0,
user_profile_custom_string_array: [userProfileCustom],
user_profile_face_url: '',
user_profile_gender: 0,
user_profile_identifier:'',
user_profile_language: 0,
user_profile_level: 0,
user_profile_location: '',
user_profile_nick_name: '',
user_profile_role: 0,
user_profile_self_signature: '',
}
let params:Json_value_msg = {
message_elem_array: [{
elem_type: 1,
text_elem_content:'',
}],
message_conv_id: '',
message_conv_type: 0,
message_sender: '',
message_priority: 0,
message_client_time: 0,
message_server_time: 0,
message_is_from_self: false,
message_platform: 0,
message_is_read: false,
message_is_online_msg:false,
message_status: 0,
message_custom_int: 0,
message_custom_str: '',
message_is_excluded_from_unread_count: false,
message_group_at_user_array: [''],
message_is_forward_message: false,
message_sender_profile: senderProfile,
message_sender_group_member_info: groupMemberInfo,
message_offline_push_config: {}
}
let convId = ''
let convType=0
let param:MsgSendMessageParamsV2 = {
conv_id:convId,
conv_type: convType,
params: params,
user_data: "",
callback: (data) => {}
}
const {code} = await timRenderInstance.TIMMsgSendMessageV2(param);
if(code == 0){
// 成功
}