IM 即时通讯
圈组消息管理
更新时间: 2022/12/06 14:19:39
发送消息
功能介绍
调用 Send
方法发送消息,支持文本、图片、语音、视频、文件、地理位置和会话消息回复(Message Threading)等消息类型。
会话消息回复属于增值功能,需现在云信控制台开通后才能使用。
参数说明
参数 | 类型 | 说明 |
---|---|---|
message.anti_spam_info {} | QChatMessageAntiSpamInfo | 配置安全通(易盾反垃圾)相关的各项参数 |
quote_message | QChatReplyMessageParam | Message Thread 中被回复的消息 |
示例代码
QChatSendMessageParam param;
param.message.server_id = 123456;
param.message.channel_id = 123456;
param.message.msg_body = "message body";
param.message.msg_ext = "message ext";
param.message.resend_flag = false;
param.message.msg_id = ""; // only for resend. if not, leave it empty, we will generate it
param.message.mention_all = false;
param.message.mention_accids = {"accid1", "accid2"}; // if mention_all is true, this will be ignored
param.message.history_enable = true;
param.message.push_enable = false;
param.message.push_payload = "push payload";
param.message.push_content = "push content";
param.message.need_badge = true;
param.message.need_push_nick = true;
param.message.route_enable = true;
// antispam info
param.message.anti_spam_info.use_custom_content = false;
param.message.anti_spam_info.anti_spam_using_yidun = true;
param.message.anti_spam_info.anti_spam_content = "anti spam content";
param.message.anti_spam_info.anti_spam_bussiness_id = "anti spam bussiness id";
param.message.anti_spam_info.yidun_callback_url = "yidun callback url";
param.message.anti_spam_info.yidun_anti_cheating = "yidun anti cheating";
param.message.anti_spam_info.yidun_anti_spam_ext = "yidun anti spam ext";
// thread message
param.quote_message = quote_message; // quote_message is a QChatMessage you received or queried.
param.cb = [this](const QChatSendMsgResp& resp) {
if (resp.res_code != NIMResCode::kNIMResSuccess) {
// error handling
return;
}
// process response
// ...
};
// text message
param.message.msg_type = kNIMQChatMsgTypeText;
auto attach = std::make_shared<QChatDefaultAttach>();
attach->msg_attach = "msg attach";
// image message
param.message.msg_type = kNIMQChatMsgTypeImage;
auto attach = std::make_shared<QChatImageAttach>();
attach->file_path = "image path";
attach->width = 100;
attach->height = 100;
param.message.msg_attach = attach;
Message::Send(param);
// audio message
param.message.msg_type = kNIMQChatMsgTypeAudio;
auto attach = std::make_shared<QChatAudioAttach>();
attach->file_path = "audio path";
attach->duration = 60;
param.message.msg_attach = attach;
// video message
param.message.msg_type = kNIMQChatMsgTypeVideo;
auto attach = std::make_shared<QChatVideoAttach>();
attach->file_path = "video path";
attach->duration = 60;
param.message.msg_attach = attach;
// location message
param.message.msg_type = kNIMQChatMsgTypeLocation;
attach->latitude = 123.456;
attach->longitude = 123.456;
attach->title = "location title";
param.message.msg_attach = attach;
// notification message
param.message.msg_type = kNIMQChatMsgTypeNotification;
auto attach = std::make_shared<QChatNotificationAttach>();
attach->id = 1;
attach->data = "notification data";
param.message.msg_attach = attach;
// file message
param.message.msg_type = kNIMQChatMsgTypeFile;
auto attach = std::make_shared<QChatFileAttach>();
attach->file_path = "file path";
param.message.msg_attach = attach;
// tips message
param.message.msg_type = kNIMQChatMsgTypeTips;
auto attach = std::make_shared<QChatTipsAttach>();
attach->type = 1;
attach->data = "tips data";
param.message.msg_attach = attach;
// custom message
param.message.msg_type = kNIMQChatMsgTypeCustom;
auto attach = std::make_shared<QChatDefaultAttach>();
attach->msg_attach = "msg attach";
Message::Send(param);
更新消息
功能介绍
调用 Update
方法更新消息信息。
参数说明
参数 | 类型 | 说明 |
---|---|---|
message.anti_spam_info {} | QChatMessageAntiSpamInfo | 配置安全通(易盾反垃圾)相关的各项参数 |
示例代码
QChatUpdateMessageParam param;
param.id_info.server_id = 123456;
param.id_info.channel_id = 123456;
param.timestamp = 0;
param.msg_server_id = 123456;
param.status = kMsgStatusNormal;
param.msg_body = "message body";
param.msg_ext = "message ext";
param.update_info.postscript = "postscript";
param.update_info.extension = "extension";
param.update_info.push_content = "push content";
param.update_info.push_payload = "push payload";
param.message.anti_spam_info.use_custom_content = false;
param.message.anti_spam_info.anti_spam_using_yidun = true;
param.message.anti_spam_info.anti_spam_content = "anti spam content";
param.message.anti_spam_info.anti_spam_bussiness_id = "anti spam bussiness id";
param.message.anti_spam_info.yidun_callback_url = "yidun callback url";
param.message.anti_spam_info.yidun_anti_cheating = "yidun anti cheating";
param.message.anti_spam_info.yidun_anti_spam_ext = "yidun anti spam ext";
param.cb = [this](const QChatUpdateMsgResp& resp) {
if (resp.res_code != NIMResCode::kNIMResSuccess) {
// error handling
return;
}
// process response
// ...
};
Message::Update(param);
撤回消息
功能介绍
调用 Revoke
方法撤回消息,撤回未读消息不影响未读数。
撤回圈组消息,目前没有时间限制。
示例代码
QChatRevokeMessageParam param;
param.id_info.server_id = 123456;
param.id_info.channel_id = 123456;
param.timestamp = 123456;
param.msg_server_id = 123456;
param.update_info.postscript = "postscript";
param.update_info.extension = "extension";
param.update_info.push_content = "push content";
param.update_info.push_payload = "push payload";
param.cb = [this](const QChatUpdateMsgResp& resp) {
if (resp.res_code != NIMResCode::kNIMResSuccess) {
// error handling
return;
}
// process response
// ...
};
Message::Revoke(param);
删除消息
功能介绍
调用 Delete
方法删除消息。
删除未读消息将影响未读数。
示例代码
QChatDeleteMessageParam param;
param.id_info.server_id = 123456;
param.id_info.channel_id = 123456;
param.timestamp = 123456;
param.msg_server_id = 123456;
param.update_info.postscript = "postscript";
param.update_info.extension = "extension";
param.update_info.push_content = "push content";
param.update_info.push_payload = "push payload";
param.cb = [this](const QChatUpdateMsgResp& resp) {
if (resp.res_code != NIMResCode::kNIMResSuccess) {
// error handling
return;
}
// process response
// ...
};
Message::Delete(param);
消息标记已读
功能介绍
调用 MarkRead
方法将消息标记为已读。
该方法调用存在频控,200ms 内最多可调用一次。
示例代码
QChatMarkMessageReadParam param;
param.id_info.server_id = 123456;
param.id_info.channel_id = 123456;
param.timestamp = 123456;
param.cb = [this, param](const QChatAckResp& resp) {
if (resp.res_code != NIMResCode::kNIMResSuccess) {
// error handling
return;
}
// process response
// ...
};
Message::MarkRead(param);
查询历史消息
功能介绍
调用 QueryHistory
查询历史消息。
示例代码
QChatQueryHistoryMsgParam param;
param.server_id = 123456;
param.channel_id = 123456;
param.from_time = 0;
param.to_time = 0;
param.exclude_msg_server_id = 123456;
param.limit = 20;
param.reverse = false;
param.cb = [this](const QChatQueryHistoryMsgResp& resp) {
if (resp.res_code != NIMResCode::kNIMResSuccess) {
// error handling
return;
}
// process response
// ...
};
Message::QueryHistory(param);
接收消息回调
功能介绍
调用 RegRecvCb
方法注册接收消息回调。
示例代码
QChatRegRecvMsgCbParam reg_receive_message_cb_param;
reg_receive_message_cb_param.cb = [this](const QChatRecvMsgResp& resp) {
if (resp.res_code != NIMResCode::kNIMResSuccess) {
// error handling
return;
}
// process response
// ...
};
Message::RegRecvCb(reg_receive_message_cb_param);
消息变更回调
功能介绍
调用 RegMsgUpdatedCb
方法注册消息更新回调
示例代码
QChatRegMsgUpdatedCbParam reg_msg_updated_cb_param;
reg_msg_updated_cb_param.cb = [this](const QChatMsgUpdatedResp& resp) {
if (resp.res_code != NIMResCode::kNIMResSuccess) {
// error handling
return;
}
// process response
// ...
};
Message::RegUpdatedCb(reg_msg_updated_cb_param);
添加快捷评论
功能介绍
调用 AddQuickComment
方法添加快捷评论。
快捷评论属于增值功能,需先在云信控制台开通后才能使用。
示例代码
QChatAddQuickCommentParam param;
param.type = 1; // type is a user defined interger
param.message = origin_message; // origin_message is a QChatMessage you received or queried.
param.cb = [this](const QChatAddQuickCommentResp& resp) {
if (resp.res_code != NIMResCode::kNIMResSuccess) {
// error handling
return;
}
// process response
// ...
};
Message::AddQuickComment(param);
删除快捷评论
功能介绍
调用 RemoveQuickComment
方法从某个消息上移除快捷评论。
快捷评论属于增值功能,需先在云信控制台开通后才能使用。
示例代码
QChatRemoveQuickCommentParam param;
param.type = 1; // type is a user defined interger
param.message = origin_message; // origin_message is a QChatMessage you received or queried.
param.cb = [this](const QChatRemoveQuickCommentResp& resp) {
if (resp.res_code != NIMResCode::kNIMResSuccess) {
// error handling
return;
}
// process response
// ...
查询快捷评论
功能介绍
调用GetQuickComments
方法获取指定消息包含的快捷评论列表。
快捷评论属于增值功能,需先在云信控制台开通后才能使用。
示例代码
QChatRemoveQuickCommentParam param;
param.server_id = 123456;
param.channel_id = 123456;
param.msg_server_id_list = {123456, 456789};
param.cb = [this](const QChatGetQuickCommentsResp& resp) {
if (resp.res_code != NIMResCode::kNIMResSuccess) {
// error handling
return;
}
// process response
// ...
};
Message::GetQuickComments(param);
搜索消息
调用SearchMsgByPage
方法,可按照关键字和消息发送者等搜索当前用户所在服务器下的全部频道或单频道的消息,包括文本消息、图片消息、视频消息和文件消息(其他类型消息均不支持搜索)。
已被撤回或删除的消息不可搜索。
示例代码如下:
QChatMessageSearchPageParam param;
param.keyword = "keyword";
param.server_id = 123456;
param.channel_id = 123456;
param.from_accid = "accid";
param.from_time = 0;
param.to_time = 0;
param.msg_types = {kNIMQChatMsgTypeText};
param.sub_types = {};
param.include_self = false;
param.order = kNIMQChatSearchOrderAsc;
param.limit = 10;
param.sort = kNIMQChatMessageSearchSortCreateTime;
param.cursor = params["cursor"].asString();
param.cb = [this](const QChatMessageSearchPageResp& resp) {
if (resp.res_code != NIMResCode::kNIMResSuccess) {
// error handling
return;
}
// process response
// ...
};
Message::SearchMsgByPage(param);
此文档是否对你有帮助?
有帮助
我要吐槽