NIM PC Cross Platform SDK
载入中...
搜索中...
未找到
nim::Talk类 参考

聊天功能,主要包括消息收发、消息撤回、消息回复(Thread 场景)等功能 更多...

#include <nim_cpp_talk.h>

Public 类型

typedef std::function< void(const SendMessageArc &)> SendMsgAckCallback
 发送消息回执通知回调
 
typedef std::function< void(const IMMessage &)> ReceiveMsgCallback
 接收消息通知回调
 
typedef std::function< void(const std::list< IMMessage > &)> ReceiveMsgsCallback
 批量接收消息通知回调
 
typedef std::function< void(int64_t, int64_t)> FileUpPrgCallback
 发送多媒体消息文件上传过程回调
 
typedef std::function< bool(const IMMessage &)> TeamNotificationFilter
 群通知过滤器
 
typedef std::function< void(const NIMResCode, const std::list< RecallMsgNotify > &)> RecallMsgsCallback
 消息撤回通知回调
 
typedef std::function< void(const BroadcastMessage &)> ReceiveBroadcastMsgCallback
 接收广播消息通知回调
 
typedef std::function< void(const std::list< BroadcastMessage > &)> ReceiveBroadcastMsgsCallback
 批量接收广播消息通知回调
 
typedef std::function< bool(const IMMessage &)> MessageFilter
 消息过滤器
 

静态 Public 成员函数

static void RegSendMsgCb (const SendMsgAckCallback &cb, const std::string &json_extension="")
 
static void SendMsg (const std::string &json_msg, const std::string &json_extension="", FileUpPrgCallback *pcb=nullptr)
 
static void SendMsg (const IMMessage &message, const std::string &json_extension="", FileUpPrgCallback *pcb=nullptr)
 
static void SendMsg (const IMMessage &message, const std::string &json_extension="", FileUpPrgCallback pcb=nullptr)
 
static bool StopSendMsg (const std::string &client_msg_id, const NIMMessageType &type, const std::string &json_extension="")
 
static void RegReceiveCb (const ReceiveMsgCallback &cb, const std::string &json_extension="")
 
static void RegReceiveMessagesCb (const ReceiveMsgsCallback &cb, const std::string &json_extension="")
 
static std::string CreateTextMessage (const std::string &receiver_id, const NIMSessionType session_type, const std::string &client_msg_id, const std::string &content, const MessageSetting &msg_setting, int64_t timetag=0, int32_t sub_type=0)
 
static std::string CreateImageMessage (const std::string &receiver_id, const NIMSessionType session_type, const std::string &client_msg_id, const IMImage &image, const std::string &file_path, const MessageSetting &msg_setting, int64_t timetag=0, int32_t sub_type=0)
 
static std::string CreateFileMessage (const std::string &receiver_id, const NIMSessionType session_type, const std::string &client_msg_id, const IMFile &file, const std::string &file_path, const MessageSetting &msg_setting, int64_t timetag=0, int32_t sub_type=0)
 
static std::string CreateAudioMessage (const std::string &receiver_id, const NIMSessionType session_type, const std::string &client_msg_id, const IMAudio &audio, const std::string &file_path, const MessageSetting &msg_setting, int64_t timetag=0, int32_t sub_type=0)
 
static std::string CreateVideoMessage (const std::string &receiver_id, const NIMSessionType session_type, const std::string &client_msg_id, const IMVideo &video, const std::string &file_path, const MessageSetting &msg_setting, int64_t timetag=0, int32_t sub_type=0)
 
static std::string CreateLocationMessage (const std::string &receiver_id, const NIMSessionType session_type, const std::string &client_msg_id, const IMLocation &location, const MessageSetting &msg_setting, int64_t timetag=0, int32_t sub_type=0)
 
static std::string CreateTipMessage (const std::string &receiver_id, const NIMSessionType session_type, const std::string &client_msg_id, const std::string &tip, const MessageSetting &msg_setting, int64_t timetag=0, int32_t sub_type=0)
 
static std::string CreateBotRobotMessage (const std::string &receiver_id, const NIMSessionType session_type, const std::string &client_msg_id, const std::string &content, const IMBotRobot &bot_msg, const MessageSetting &msg_setting, int64_t timetag=0, int32_t sub_type=0)
 
static std::string CreateG2NetCallMessage (const std::string &receiver_id, const NIMSessionType session_type, const std::string &client_msg_id, const std::string &msg_attach, const MessageSetting &msg_setting, int64_t timetag=0, int32_t sub_type=0)
 
static std::string CreateRetweetMessage (const std::string &src_msg_json, const std::string &client_msg_id, const NIMSessionType retweet_to_session_type, const std::string &retweet_to_session_id, const MessageSetting &msg_setting, int64_t timetag=0)
 
static bool ParseIMMessage (const std::string &json_msg, IMMessage &msg)
 
static bool ParseImageMessageAttach (const IMMessage &msg, IMImage &image)
 
static bool ParseFileMessageAttach (const IMMessage &msg, IMFile &file)
 
static bool ParseAudioMessageAttach (const IMMessage &msg, IMAudio &audio)
 
static bool ParseVideoMessageAttach (const IMMessage &msg, IMVideo &video)
 
static bool ParseLocationMessageAttach (const IMMessage &msg, IMLocation &location)
 
static bool ParseBotRobotMessageAttach (const IMMessage &msg, IMBotRobot &robot_msg)
 
static void UnregTalkCb ()
 
static void RegTeamNotificationFilter (const TeamNotificationFilter &filter, const std::string &json_extension="")
 
static void RegMessageFilter (const MessageFilter &filter, const std::string &json_extension="")
 
static void RegRecallMsgsCallback (const RecallMsgsCallback &cb, const std::string &json_extension="")
 
static void RecallMsg (const IMMessage &msg, const std::string &notify, const RecallMsgsCallback &cb, const std::string &json_extension="")
 
static void RecallMsg2 (const IMMessage &msg, const std::string &notify, const RecallMsgsCallback &cb, const std::string &apnstext="", const std::string &pushpayloadconst="", const std::string &json_extension="")
 
static void RecallMsgEx (const IMMessage &msg, const std::string &notify, const RecallMsgsCallback &cb, nim_talk_recall_extra_params &extra_param)
 
static std::string GetAttachmentPathFromMsg (const IMMessage &msg)
 
static void RegReceiveBroadcastMsgCb (const ReceiveBroadcastMsgCallback &cb, const std::string &json_extension="")
 
static void RegReceiveBroadcastMsgsCb (const ReceiveBroadcastMsgsCallback &cb, const std::string &json_extension="")
 
static void ReplyMessage (const IMMessage &msg, const std::string &json_reply_msg, FileUpPrgCallback *prg_cb=nullptr)
 
static void ReplyMessage (const IMMessage &former_msg, const IMMessage &reply_msg, FileUpPrgCallback *prg_cb=nullptr)
 

详细描述

聊天功能,主要包括消息收发、消息撤回、消息回复(Thread 场景)等功能

成员类型定义说明

◆ FileUpPrgCallback

typedef std::function<void(int64_t, int64_t)> nim::Talk::FileUpPrgCallback

发送多媒体消息文件上传过程回调

◆ MessageFilter

typedef std::function<bool(const IMMessage&)> nim::Talk::MessageFilter

消息过滤器

◆ RecallMsgsCallback

typedef std::function<void(const NIMResCode, const std::list<RecallMsgNotify>&)> nim::Talk::RecallMsgsCallback

消息撤回通知回调

◆ ReceiveBroadcastMsgCallback

typedef std::function<void(const BroadcastMessage&)> nim::Talk::ReceiveBroadcastMsgCallback

接收广播消息通知回调

◆ ReceiveBroadcastMsgsCallback

typedef std::function<void(const std::list<BroadcastMessage>&)> nim::Talk::ReceiveBroadcastMsgsCallback

批量接收广播消息通知回调

◆ ReceiveMsgCallback

typedef std::function<void(const IMMessage&)> nim::Talk::ReceiveMsgCallback

接收消息通知回调

◆ ReceiveMsgsCallback

typedef std::function<void(const std::list<IMMessage>&)> nim::Talk::ReceiveMsgsCallback

批量接收消息通知回调

◆ SendMsgAckCallback

typedef std::function<void(const SendMessageArc&)> nim::Talk::SendMsgAckCallback

发送消息回执通知回调

◆ TeamNotificationFilter

typedef std::function<bool(const IMMessage&)> nim::Talk::TeamNotificationFilter

群通知过滤器

成员函数说明

◆ CreateAudioMessage()

static std::string nim::Talk::CreateAudioMessage ( const std::string &  receiver_id,
const NIMSessionType  session_type,
const std::string &  client_msg_id,
const IMAudio audio,
const std::string &  file_path,
const MessageSetting msg_setting,
int64_t  timetag = 0,
int32_t  sub_type = 0 
)
static

生成语音消息内容,生成的字符串在调用 SendMsg 时直接传入即可发送语音消息

调用时机

登录 IM 后调用该 API。如果需在群组或超大群中发送消息,用户需要已加入群组/超大群

参数
[in]receiver_id聊天对象的 ID
  • 单聊场景下为对方的 IM 账号(accid)
  • 群聊场景下为群 ID
[in]session_type会话类型,单聊、群组或超大群,详情参见 NIMSessionType
[in]client_msg_id客户端生成的消息 ID,建议采用 uuid
[in]audio语音文件信息,详情参见 IMAudio
[in]file_path文件本地绝对路径
[in]msg_setting消息属性设置,包括离线推送、内容审核、未读计数等设置,详情参见 MessageSetting
[in]timetag消息时间
[in]sub_type消息子类型( > 0 ),由开发者自定义,云信服务端只负责透传。SDK v7.8 起开始支持该参数
返回
std::string 语音消息 JSON 字符串
相关 API

ParseAudioMessageAttachGetAttachmentPathFromMsg

◆ CreateBotRobotMessage()

static std::string nim::Talk::CreateBotRobotMessage ( const std::string &  receiver_id,
const NIMSessionType  session_type,
const std::string &  client_msg_id,
const std::string &  content,
const IMBotRobot bot_msg,
const MessageSetting msg_setting,
int64_t  timetag = 0,
int32_t  sub_type = 0 
)
static
弃用:
该接口已废弃

生成机器人消息内容,生成的字符串在调用SendMsg时直接传入

参数
[in]receiver_id聊天对象的 ID,如果是单聊,为用户帐号,如果是群聊,为群组 ID
[in]session_typeNIMSessionType,聊天类型,单聊或群组
[in]client_msg_id客户端消息id,建议uuid
[in]content内容
[in]bot_msg机器人消息信息
[in]msg_setting消息属性设置
[in]timetag消息时间
[in]sub_type消息子类型( > 0 ),由开发者自定义,服务端只负责透传 v7.8
返回
std::string 位置消息Json字符串

◆ CreateFileMessage()

static std::string nim::Talk::CreateFileMessage ( const std::string &  receiver_id,
const NIMSessionType  session_type,
const std::string &  client_msg_id,
const IMFile file,
const std::string &  file_path,
const MessageSetting msg_setting,
int64_t  timetag = 0,
int32_t  sub_type = 0 
)
static

生成文件消息内容,生成的字符串在调用 SendMsg 时直接传入即可发送文件消息

调用时机

登录 IM 后调用该 API。如果需在群组或超大群中发送消息,用户需要已加入群组/超大群

参数
[in]receiver_id聊天对象的 ID
  • 单聊场景下为对方的 IM 账号(accid)
  • 群聊场景下为群 ID
[in]session_type会话类型,单聊、群组或超大群,详情参见 NIMSessionType
[in]client_msg_id客户端生成的消息 ID,建议采用 uuid
[in]file文件信息,详情参见IMFile
[in]file_path文件本地绝对路径
[in]msg_setting消息属性设置,包括离线推送、内容审核、未读计数等设置,详情参见 MessageSetting
[in]timetag消息时间
[in]sub_type消息子类型( > 0 ),由开发者自定义,云信服务端只负责透传。SDK v7.8 起开始支持该参数
返回
std::string 文件消息 JSON 字符串
相关 API

ParseFileMessageAttachGetAttachmentPathFromMsg

◆ CreateG2NetCallMessage()

static std::string nim::Talk::CreateG2NetCallMessage ( const std::string &  receiver_id,
const NIMSessionType  session_type,
const std::string &  client_msg_id,
const std::string &  msg_attach,
const MessageSetting msg_setting,
int64_t  timetag = 0,
int32_t  sub_type = 0 
)
static

生成话单(Android/iOS/Web)消息内容,生成的字符串在调用SendMsg时直接传入即可发送话单消息

调用时机

登录 IM 后调用该 API。如果需在群组或超大群中发送消息,用户需要已加入群组/超大群

参数
[in]receiver_id聊天对象的 ID
  • 单聊场景下为对方的 IM 账号(accid)
  • 群聊场景下为群 ID
[in]session_type会话类型,单聊、群组或超大群,详情参见 NIMSessionType
[in]client_msg_id客户端生成的消息 ID,建议采用 uuid
[in]msg_attach话单 JSON 体包含type、channel、status 以及 durations 数组
[in]msg_setting消息属性设置,包括离线推送和未读计数等设置,详情参见 MessageSetting
[in]timetag消息时间
[in]sub_type消息子类型( > 0 ),由开发者自定义,云信服务端只负责透传。SDK v7.8 起开始支持该参数
返回
std::string 话单消息 JSON 字符串

◆ CreateImageMessage()

static std::string nim::Talk::CreateImageMessage ( const std::string &  receiver_id,
const NIMSessionType  session_type,
const std::string &  client_msg_id,
const IMImage image,
const std::string &  file_path,
const MessageSetting msg_setting,
int64_t  timetag = 0,
int32_t  sub_type = 0 
)
static

生成图片消息内容,生成的字符串在调用 SendMsg 时直接传入即可发送图片消息

调用时机

登录 IM 后调用该 API。如果需在群组或超大群中发送消息,用户需要已加入群组/超大群

参数
[in]receiver_id聊天对象的 ID
  • 单聊场景下为对方的 IM 账号(accid)
  • 群聊场景下为群 ID
[in]session_type会话类型,单聊、群组或超大群,详情参见 NIMSessionType
[in]client_msg_id客户端生成的消息 ID,建议采用 uuid
[in]image图片文件信息,详情参见 IMImage
[in]file_path文件本地绝对路径
[in]msg_setting消息属性设置,包括离线推送、内容审核、未读计数等设置,详情参见 MessageSetting
[in]timetag消息时间
[in]sub_type消息子类型( > 0 ),由开发者自定义,云信服务端只负责透传。SDK v7.8 起开始支持该参数
返回
std::string 图片消息 JSON 字符串
相关 API

ParseImageMessageAttachGetAttachmentPathFromMsg

◆ CreateLocationMessage()

static std::string nim::Talk::CreateLocationMessage ( const std::string &  receiver_id,
const NIMSessionType  session_type,
const std::string &  client_msg_id,
const IMLocation location,
const MessageSetting msg_setting,
int64_t  timetag = 0,
int32_t  sub_type = 0 
)
static

生成地理位置消息的内容,生成的字符串在调用 SendMsg 时直接传入即可发送地理位置消息

调用时机

登录 IM 后调用该 API。如果需在群组或超大群中发送消息,用户需要已加入群组/超大群

参数
[in]receiver_id聊天对象的 ID
  • 单聊场景下为对方的 IM 账号(accid)
  • 群聊场景下为群 ID
[in]session_type会话类型,单聊、群组或超大群,详情参见 NIMSessionType
[in]client_msg_id客户端生成的消息 ID,建议采用 uuid
[in]location位置信息,详情参见 IMLocation
[in]msg_setting消息属性设置,包括离线推送、内容审核、未读计数等设置,详情参见 MessageSetting
[in]timetag消息时间
[in]sub_type消息子类型( > 0 ),由开发者自定义,云信服务端只负责透传。SDK v7.8 起开始支持该参数
返回
std::string 地理位置消息 JSON 字符串
相关 API

ParseLocationMessageAttach

◆ CreateRetweetMessage()

static std::string nim::Talk::CreateRetweetMessage ( const std::string &  src_msg_json,
const std::string &  client_msg_id,
const NIMSessionType  retweet_to_session_type,
const std::string &  retweet_to_session_id,
const MessageSetting msg_setting,
int64_t  timetag = 0 
)
static

由其他消息生成转发消息,调用该 API 后还需要调用 SendMsg 将生成的转发消息发送至目标对象

调用时机

登录 IM 后调用该 API。如果需在群组或超大群中发送消息,用户需要已加入群组/超大群

参数
[in]src_msg_json原消息 JSON 字符串
[in]client_msg_id新的消息 ID(客户端生成的消息 ID),建议采用 uuid
[in]retweet_to_session_type转发至的目标会话类型,包括单聊、群组和超大群,详情参见 NIMSessionType
[in]retweet_to_session_id转发至的对象的 ID,
  • 如果对象为某个用户,则为对方的 IM 账号(accid)
  • 如果对象为群组或超大群,则为群 ID
[in]msg_setting消息属性设置,包括离线推送、内容审核、未读计数等设置,详情参见 MessageSetting
[in]timetag消息时间
返回
std::string 转发消息 JSON 字符串

◆ CreateTextMessage()

static std::string nim::Talk::CreateTextMessage ( const std::string &  receiver_id,
const NIMSessionType  session_type,
const std::string &  client_msg_id,
const std::string &  content,
const MessageSetting msg_setting,
int64_t  timetag = 0,
int32_t  sub_type = 0 
)
static

生成文字消息内容,生成的字符串在调用 SendMsg 时直接传入即可发送文本消息

调用时机

登录 IM 后调用该 API。如果需在群组或超大群中发送消息,用户需要已加入群组/超大群

参数
[in]receiver_id聊天对象的 ID
  • 单聊场景下为对方的 IM 账号(accid)
  • 群聊场景下为群 ID
[in]session_type会话类型,单聊、群组或超大群,详情参见 NIMSessionType
[in]client_msg_id客户端生成的消息 ID,建议采用 uuid
[in]content文本内容
[in]msg_setting消息属性设置,包括离线推送、内容审核、未读计数等设置,详情参见 MessageSetting
[in]timetag消息时间
[in]sub_type消息子类型( > 0 ),由开发者自定义,云信服务端只负责透传。SDK v7.8 起开始支持该参数
返回
std::string 文字消息 JSON 字符串

◆ CreateTipMessage()

static std::string nim::Talk::CreateTipMessage ( const std::string &  receiver_id,
const NIMSessionType  session_type,
const std::string &  client_msg_id,
const std::string &  tip,
const MessageSetting msg_setting,
int64_t  timetag = 0,
int32_t  sub_type = 0 
)
static

生成提示(Tips)消息内容,生成的字符串在调用 SendMsg 时直接传入即可发送提示消息

调用时机

登录 IM 后调用该 API。如果需在群组或超大群中发送消息,用户需要已加入群组/超大群

参数
[in]receiver_id聊天对象的 ID
  • 单聊场景下为对方的 IM 账号(accid)
  • 群聊场景下为群 ID
[in]session_type会话类型,单聊、群组或超大群,详情参见 NIMSessionType
[in]client_msg_id客户端生成的消息 ID,建议采用 uuid
[in]tip提示消息的文本内容
[in]msg_setting消息属性设置,包括离线推送、内容审核、未读计数等设置,详情参见 MessageSetting
[in]timetag消息时间
[in]sub_type消息子类型( > 0 ),由开发者自定义,云信服务端只负责透传。SDK v7.8 起开始支持该参数
返回
std::string 提示消息 JSON 字符串

◆ CreateVideoMessage()

static std::string nim::Talk::CreateVideoMessage ( const std::string &  receiver_id,
const NIMSessionType  session_type,
const std::string &  client_msg_id,
const IMVideo video,
const std::string &  file_path,
const MessageSetting msg_setting,
int64_t  timetag = 0,
int32_t  sub_type = 0 
)
static

生成视频消息内容,生成的字符串在调用 SendMsg 时直接传入即可发送视频消息

调用时机

登录 IM 后调用该 API。如果需在群组或超大群中发送消息,用户需要已加入群组/超大群

参数
[in]receiver_id聊天对象的 ID
  • 单聊场景下为对方的 IM 账号(accid)
  • 群聊场景下为群 ID
[in]session_type会话类型,单聊、群组或超大群,详情参见 NIMSessionType
[in]client_msg_id客户端生成的消息 ID,建议采用 uuid
[in]video视频文件信息,详情参见 IMVideo
[in]file_path文件本地绝对路径
[in]msg_setting消息属性设置,包括离线推送、内容审核、未读计数等设置,详情参见 MessageSetting
[in]timetag消息时间
[in]sub_type消息子类型( > 0 ),由开发者自定义,云信服务端只负责透传。SDK v7.8 起开始支持该参数
返回
std::string 视频消息 JSON 字符串
相关 API

ParseVideoMessageAttachGetAttachmentPathFromMsg

◆ GetAttachmentPathFromMsg()

static std::string nim::Talk::GetAttachmentPathFromMsg ( const IMMessage msg)
static

从消息体中获取附件(图片、语音、视频等)的本地路径

调用时机

接收到消息时

参数
[in]msg消息
返回
char * 消息如果有附件,不管是否已下载,返回附件的本地路径;消息如果没有附件,返回空字符串。

◆ ParseAudioMessageAttach()

static bool nim::Talk::ParseAudioMessageAttach ( const IMMessage msg,
IMAudio audio 
)
static

通过得到的消息获得语音信息

参数
[in]msg消息
[out]audio语音信息
返回
bool 解析是否成功

◆ ParseBotRobotMessageAttach()

static bool nim::Talk::ParseBotRobotMessageAttach ( const IMMessage msg,
IMBotRobot robot_msg 
)
static
弃用:
该接口已废弃

通过得到的消息获得机器人消息

参数
[in]msg消息
[out]robot_msg机器人消息
返回
bool 解析是否成功

◆ ParseFileMessageAttach()

static bool nim::Talk::ParseFileMessageAttach ( const IMMessage msg,
IMFile file 
)
static

通过得到的消息获得文件信息

参数
[in]msg消息
[out]file文件信息
返回
bool 解析是否成功

◆ ParseImageMessageAttach()

static bool nim::Talk::ParseImageMessageAttach ( const IMMessage msg,
IMImage image 
)
static

通过得到的消息获得图片信息

参数
[in]msg消息
[out]image图片信息
返回
bool 解析是否成功

◆ ParseIMMessage()

static bool nim::Talk::ParseIMMessage ( const std::string &  json_msg,
IMMessage msg 
)
static

解析消息 JSON 字符串

参数
[in]json_msg消息内容 JSON 字符串
[out]msg消息内容
返回
bool 解析是否成功

◆ ParseLocationMessageAttach()

static bool nim::Talk::ParseLocationMessageAttach ( const IMMessage msg,
IMLocation location 
)
static

通过得到的消息获得地理位置信息

参数
[in]msg消息
[out]location位置信息
返回
bool 解析是否成功

◆ ParseVideoMessageAttach()

static bool nim::Talk::ParseVideoMessageAttach ( const IMMessage msg,
IMVideo video 
)
static

通过得到的消息获得视频信息

参数
[in]msg消息
[out]video视频信息
返回
bool 解析是否成功

◆ RecallMsg()

static void nim::Talk::RecallMsg ( const IMMessage msg,
const std::string &  notify,
const RecallMsgsCallback cb,
const std::string &  json_extension = "" 
)
static

撤回消息

使用场景

消息发送后的可撤回时长内(默认 2 分钟),用户撤回已发送的单聊消息或者群消息

注解
消息可撤回时长可在云信控制台配置。配置路径:选择应用,进入IM 免费版/专业版 > 功能配置 > 消息撤回配置

注意事项

单聊和群聊消息的撤回功能存在些许区别:

  • 单聊:用户只能撤回自己发送的消息
  • 群聊:普通成员只能撤回自己发送的消息。管理员可撤回其他群成员的消息
影响范围

调用该方法将触发 RecallMsgsCallback 回调

  • 单聊场景下,发送方撤回之后,对应的离线消息、漫游消息和历史消息将被删除,消息接收方会收到消息撤回通知 RecallMsgNotify
  • 群聊场景下, 所有群成员都会收到消息撤回通知 RecallMsgNotify
  • 如果接收方同时在多个设备端登录了同一个 IM 账号, 那么其它端也会收到消息撤回通知 RecallMsgNotify
参数
[in]msg待撤回的消息
[in]notify自定义通知消息
[in]json_extensionJSON 扩展参数(备用,目前不需要)
[in]cb回调
返回
void 无返回值
错误码
  • 200:成功
  • 414:参数错误
  • 508:撤回时间超过配制有效期,默认是 2 分钟
  • 10414:本地错误码,参数错误
  • 10508:本地错误码,超过配置有效期或者所需参数不存在

◆ RecallMsg2()

static void nim::Talk::RecallMsg2 ( const IMMessage msg,
const std::string &  notify,
const RecallMsgsCallback cb,
const std::string &  apnstext = "",
const std::string &  pushpayloadconst = "",
const std::string &  json_extension = "" 
)
static

撤回消息

使用场景

消息发送后的可撤回时长内(默认 2 分钟),用户撤回已发送的单聊消息或者群消息

注解
消息可撤回时长可在云信控制台配置。配置路径:选择应用,进入IM 免费版/专业版 > 功能配置 > 消息撤回配置

注意事项

单聊和群聊消息的撤回功能存在些许区别:

  • 单聊:用户只能撤回自己发送的消息
  • 群聊:普通成员只能撤回自己发送的消息。管理员可撤回其他群成员的消息
影响范围

调用该方法将触发 RecallMsgsCallback 回调

  • 单聊场景下,发送方撤回之后,对应的离线消息、漫游消息和历史消息将被删除,消息接收方会收到消息撤回通知 RecallMsgNotify
  • 群聊场景下, 所有群成员都会收到消息撤回通知 RecallMsgNotify
  • 如果接收方同时在多个设备端登录了同一个 IM 账号, 那么其它端也会收到消息撤回通知 RecallMsgNotify
参数
[in]msg待撤回消息
[in]notify自定义通知消息
[in]cb回调
[in]apnstext透传消息推送文本,不填则不推送
[in]pushpayloadconst第三方自定义的推送属性,限制 JSON,长度 2048
[in]json_extensionJSON 扩展参数(备用,目前不需要)
返回
void 无返回值
错误码
-200:成功 -414:参数错误 -508:撤回时间超过配制有效期,默认是2分钟 -10414:本地错误码,参数错误 -10508:本地错误码,超过配置有效期或者所需参数不存在

◆ RecallMsgEx()

static void nim::Talk::RecallMsgEx ( const IMMessage msg,
const std::string &  notify,
const RecallMsgsCallback cb,
nim_talk_recall_extra_params extra_param 
)
static

撤回消息

使用场景

消息发送后的可撤回时长内(默认 2 分钟),用户撤回已发送的单聊消息或者群消息

注解
消息可撤回时长可在云信控制台配置。配置路径:选择应用,进入IM 免费版/专业版 > 功能配置 > 消息撤回配置

注意事项

单聊和群聊消息的撤回功能存在些许区别:

  • 单聊:用户只能撤回自己发送的消息
  • 群聊:普通成员只能撤回自己发送的消息。管理员可撤回其他群成员的消息
影响范围

调用该方法将触发 RecallMsgsCallback 回调

  • 单聊场景下,发送方撤回之后,对应的离线消息、漫游消息和历史消息将被删除,消息接收方会收到消息撤回通知 RecallMsgNotify
  • 群聊场景下, 所有群成员都会收到消息撤回通知 RecallMsgNotify
  • 如果接收方同时在多个设备端登录了同一个 IM 账号, 那么其它端也会收到消息撤回通知 RecallMsgNotify
参数
[in]msg待撤回的消息
[in]notify自定义通知消息
[in]cb回调
[in]extra_param额外的参数,包含:
参数 类型 描述
apnstext const char* APNs 自定义推送文案
pushpayload const char* 第三方自定义的推送属性,限制使用 JSON 格式化的字符串,长度限制 2048 字符。更多说明及相关示例请参见推送payload配置
json_extension const char* JSON 扩展字段
attach const char* 附加信息
env_config const char* 指定当前消息需要抄送到或者回调到的环境的名称(见下图)。开通消息抄送或第三方回调后,该环境名称可在云信控制台中配置,最大 32 个字符。
开通与配置消息抄送功能的详情,请参见开通消息抄送,第三方回调相关详情,请参见第三方回调概述
错误码
  • 200:成功
  • 414:参数错误
  • 508:撤回时间超过配制有效期
  • 10414:本地错误码,参数错误
  • 10508:本地错误码,超过配置有效期或者所需参数不存在

◆ RegMessageFilter()

static void nim::Talk::RegMessageFilter ( const MessageFilter filter,
const std::string &  json_extension = "" 
)
static

(全局回调)注册消息过滤回调。注册后,接收到消息前将先触发本回调,开发者可自行决定是否过滤消息

注解
可能堵塞线程,请谨慎使用,并避免耗时行为。
调用时机

登录 IM 前注册该回调

参数
[in]json_extensionJSON 扩展参数(备用,目前不需要)
[in]filter过滤接口
返回
void 无返回值

◆ RegRecallMsgsCallback()

static void nim::Talk::RegRecallMsgsCallback ( const RecallMsgsCallback cb,
const std::string &  json_extension = "" 
)
static

(全局回调)注册消息撤回通知的回调

调用时机

登录 IM 前注册该回调

参数
[in]json_extensionJSON 扩展参数(备用,目前不需要)
[in]cb回调
返回
void 无返回值
错误码
200:成功

◆ RegReceiveBroadcastMsgCb()

static void nim::Talk::RegReceiveBroadcastMsgCb ( const ReceiveBroadcastMsgCallback cb,
const std::string &  json_extension = "" 
)
static

(全局回调)注册接收在线广播消息的回调(全局注册)

注解
仅支持通过 IM 服务端 API 发送广播消息
调用时机

登录 IM 前注册该回调

参数
[in]json_extensionJSON 扩展参数(备用,目前不需要)
[in]cb接收消息的回调函数
返回
void 无返回值
错误码
  • 200:成功
  • 10414:本地错误码,参数错误
  • 10417:本地错误码,对象已经存在/重复操作

◆ RegReceiveBroadcastMsgsCb()

static void nim::Talk::RegReceiveBroadcastMsgsCb ( const ReceiveBroadcastMsgsCallback cb,
const std::string &  json_extension = "" 
)
static

(全局回调)注册批量接收离线广播消息的回调 (全局注册)

注解
仅支持通过 IM 服务端 API 发送广播消息
调用时机

登录 IM 前注册该回调

参数
[in]json_extensionJSON 扩展参数(备用,目前不需要)
[in]cb接收消息的回调函数
返回
void 无返回值
错误码 200:成功

◆ RegReceiveCb()

static void nim::Talk::RegReceiveCb ( const ReceiveMsgCallback cb,
const std::string &  json_extension = "" 
)
static

(全局回调)注册接收在线消息的回调

注解
建议全局注册,统一接受回调后分发消息到具体的会话。
调用时机

登录 IM 前注册该回调

参数
[in]json_extensionJSON 扩展参数(备用,目前不需要)
[in]cb接收消息的回调函数
返回
void 无返回值
错误码
  • 200:成功
  • 10414:本地错误码,参数错误
  • 10417:本地错误码,对象已经存在/重复操作

◆ RegReceiveMessagesCb()

static void nim::Talk::RegReceiveMessagesCb ( const ReceiveMsgsCallback cb,
const std::string &  json_extension = "" 
)
static

(全局回调)注册批量接收离线消息的回调

注解
建议全局注册,统一接受回调后分发消息到具体的会话
调用时机

登录 IM 前注册该回调

参数
[in]json_extensionJSON 扩展参数(备用,目前不需要)
[in]cb接收消息的回调函数
返回
void 无返回值
错误码
200:成功

◆ RegSendMsgCb()

static void nim::Talk::RegSendMsgCb ( const SendMsgAckCallback cb,
const std::string &  json_extension = "" 
)
static

(全局回调)注册发送消息回调函数,可通过该回调判断消息是否发送成功

注解
  • 必须全局注册,统一接受回调后分发消息到具体的会话。
  • 客户端发包之后,服务器不一定会返回
调用时机

登录 IM 前注册该回调函数

参数
[in]json_extensionJSON 扩展参数(备用,目前不需要)
[in]cb发送消息的回调函数
返回

void 无返回值

错误码
  • 200:消息发送成功
  • 408:请求超时
  • 414:参数错误
  • 802:没有权限(群错误码)
  • 811:强推列表中帐号数量超限(群错误码)
  • 812:群禁言(群错误码)
  • 10200:发送文件消息,网易云存储(NOS)上传暂停
  • 10404:本地资源不存在
  • 10414:本地错误码,参数错误
  • 10502:发送消息,上传网易云存储(NOS)失败

◆ RegTeamNotificationFilter()

static void nim::Talk::RegTeamNotificationFilter ( const TeamNotificationFilter filter,
const std::string &  json_extension = "" 
)
static

(全局回调)注册群通知过滤回调。注册后,群通知触发前将先触发本回调,开发者可自行决定是否过滤群通知

注解
可能堵塞线程,请谨慎使用,并避免耗时行为。
调用时机

登录 IM 前注册该回调

参数
[in]json_extensionJSON 扩展参数(备用,目前不需要)
[in]filter过滤接口
返回
void 无返回值

◆ ReplyMessage() [1/2]

void nim::Talk::ReplyMessage ( const IMMessage former_msg,
const IMMessage reply_msg,
FileUpPrgCallback prg_cb = nullptr 
)
static

◆ ReplyMessage() [2/2]

void nim::Talk::ReplyMessage ( const IMMessage msg,
const std::string &  json_reply_msg,
FileUpPrgCallback prg_cb = nullptr 
)
static

回复消息(Thread 聊天场景)

调用前提

已在控制台开通会话消息回复功能。配置路径:选择应用,进入IM 免费版/专业版 > 功能权限开通 > 拓展配置 > 全局 > 会话消息回复

使用场景

用户引用接收到的某一条消息进行针对性的回复(见如下示例图),形成起始于该消息的消息回复树状结构。通过该功能,用户可针对某一条消息进行提问、反馈或补充相关背景信息,且不会对会话内的消息流造成干扰。

影响范围

调用该 API 将触发被回复方的ReceiveMsgCallbackReceiveMsgsCallback回调

参数
[in]msg被回复消息的消息体
[in]json_reply_msg回复消息的消息体,可通过各种 CreatexxxMessage 接口创建
[in]prg_cb传进度的回调函数, 如果发送的消息里包含了文件资源,则通过此回调函数通知上传进度
返回
void 无返回值

◆ SendMsg() [1/3]

static void nim::Talk::SendMsg ( const IMMessage message,
const std::string &  json_extension = "",
FileUpPrgCallback pcb = nullptr 
)
static

发送消息

使用场景

向目标用户、目标群组或目标超大群发送消息

调用前提

已调用 CreateXXXMessage 方法创建消息体,具体的方法见如下列出的创建消息体相关 API

相关 API
参数
[in]json_msg消息体 JSON 字符串,可以通过 CreateXXXMessage 方法自动创建
[in]json_extensionjson扩展参数(备用,目前不需要)
[in]pcb多媒体资源(语音、视频和文件)上传进度的回调函数, 如果发送的消息里包含了多媒体资源,则可通过此回调函数获取上传进度
返回
void 无返回值
相关回调

◆ SendMsg() [2/3]

void nim::Talk::SendMsg ( const IMMessage message,
const std::string &  json_extension = "",
FileUpPrgCallback  pcb = nullptr 
)
static

◆ SendMsg() [3/3]

static void nim::Talk::SendMsg ( const std::string &  json_msg,
const std::string &  json_extension = "",
FileUpPrgCallback pcb = nullptr 
)
static

发送消息

使用场景

向目标用户、目标群组或目标超大群发送消息

调用前提

已调用 CreateXXXMessage 方法创建消息体,具体的方法见如下列出的创建消息体相关 API

相关 API
参数
[in]json_msg消息体 JSON 字符串,可以通过 CreateXXXMessage 方法自动创建
[in]json_extensionJSON 扩展参数(备用,目前不需要)
[in]pcb多媒体资源(语音、视频和文件)上传进度的回调函数, 如果发送的消息里包含了多媒体资源,则可通过此回调函数获取上传进度
返回
void 无返回值
相关回调

◆ StopSendMsg()

static bool nim::Talk::StopSendMsg ( const std::string &  client_msg_id,
const NIMMessageType type,
const std::string &  json_extension = "" 
)
static

停止正在发送中的消息

注解
目前只支持终止发送文件消息。
参数
[in]client_msg_id停止发送的消息的 ID(客户端生成的消息 ID)
[in]type停止发送的消息类型
[in]json_extensionJSON 扩展参数(备用,目前不需要)
返回
void 无返回值

◆ UnregTalkCb()

void nim::Talk::UnregTalkCb ( )
static

反注册 Talk 类中提供的所有回调

返回
void 无返回值

该类的文档由以下文件生成: