聊天室消息构建

更新时间: 2024/04/18 18:11:00

NetEase IM SDK(以下简称 NIM SDK)支持多种消息类型,助您快速实现多样化的消息业务场景。在进行消息收发等操作前,您需要先构建消息。

本文中消息指聊天室消息。更多聊天室消息相关功能请参考开发文档聊天室消息

支持平台

Android iOS macOS/Windows Web/uni-app/小程序

API 概览

API 描述
createTextMessage 创建一条文本消息
createImageMessage 创建一条图片消息
createAudioMessage 创建一条语音消息
createVideoMessage 创建一条视频消息
createFileMessage 创建一条文件消息
createLocationMessage 创建一条地理位置消息
createCustomMessage 创建一条自定义消息
createForwardMessage 创建一条转发消息
createTipsMessage 创建一条提示消息

接口类

V2NIMChatroomMessageCreator 类提供聊天室消息构建接口,支持构建多种类型的聊天室消息。

createTextMessage

接口描述

创建一条文本消息。

  • 在加入聊天室后、发送消息前调用该方法。
  • 该方法为同步。

参数说明

Android
javapublic static V2NIMChatroomMessage createTextMessage(String text)
参数名称 类型 是否必填 默认值 描述
text String - 文本消息内容,长度上限为 5000 字符。
iOS
objective-c+ (V2NIMChatroomMessage *)createTextMessage:(NSString *)text;
参数名称 类型 是否必填 默认值 描述
text NSString * - 文本消息内容,长度上限为 5000 字符。
macOS/Windows
cppstatic nstd::optional<V2NIMChatroomMessage> createTextMessage(nstd::string text);
参数名称 类型 是否必填 默认值 描述
text nstd::string - 文本消息内容,长度上限为 5000 字符。
Web/uni-app/小程序
typescriptcreateTextMessage(text: string): V2NIMChatroomMessage
参数名称 类型 是否必填 默认值 描述
text string - 文本消息内容,长度上限为 5000 字符。

示例代码

Android
javaV2NIMChatroomMessage v2TextMessage = V2NIMChatroomMessageCreator.createTextMessage("text content");
iOS
objective-cV2NIMChatroomMessage *v2TextMessage = [V2NIMChatroomMessageCreator createTextMessage:@"text content"];
macOS/Windows
cppauto textMessage = V2NIMChatroomMessageCreator::createTextMessage("hello world");
if(!textMessage) {
    // create text message failed
}
Web/uni-app/小程序
typescripttry {
    const message = chatroom.V2NIMChatroomMessageCreator.createTextMessage('hello world')
} catch(err) {
    // todo error
}

返回值

已创建的聊天室消息对象 V2NIMChatroomMessage

createImageMessage

接口描述

创建一条图片消息。

  • 在加入聊天室后、发送消息前调用该方法。
  • 该方法为同步。

参数说明

Android
javapublic static V2NIMChatroomMessage createImageMessage(String imagePath, String name, String sceneName, Integer width, Integer height) 
参数名称 类型 是否必填 默认值 描述
imagePath String - 图片 URL 地址
name String 文件名 图片文件显示名称,可不同于文件名。
sceneName String V2NIMStorageSceneConfig.DEFAULT_IM 对应的场景名 NOS 文件存储场景名。若使用自定义的存储场景,需要先调用 addCustomStorageScene 添加自定义存储场景。
width Integer null 图片宽度,单位为像素。
height Integer null 图片高度,单位为像素。
iOS
objective-c+ (V2NIMChatroomMessage *)createImageMessage:(NSString *)imagePath
                                name:(nullable NSString *)name
                           sceneName:(nullable NSString *)sceneName
                               width:(int)width
                              height:(int)height;
参数名称 类型 是否必填 默认值 描述
imagePath NSString * - 图片 URL 地址
name NSString * 文件名 图片文件显示名称,可不同于文件名。
sceneName NSString * V2NIMStorageSceneConfig.DEFAULT_IM 对应的场景名 NOS 文件存储场景名。若使用自定义的存储场景,需要先调用 addCustomStorageScene 添加自定义存储场景。
width int null 图片宽度,单位为像素。
height int null 图片高度,单位为像素。
macOS/Windows
cppstatic nstd::optional<V2NIMChatroomMessage> createImageMessage(nstd::string imagePath,
    nstd::string name,
    nstd::string sceneName,
    uint32_t width,
    uint32_t height);
参数名称 类型 是否必填 默认值 描述
imagePath nstd::string - 图片 URL 地址
name nstd::string 文件名 图片文件显示名称,可不同于文件名。
sceneName nstd::string V2NIMStorageSceneConfig.DEFAULT_IM 对应的场景名 NOS 文件存储场景名。若使用自定义的存储场景,需要先调用 addCustomStorageScene 添加自定义存储场景。
width uint32_t null 图片宽度,单位为像素。
height uint32_t null 图片高度,单位为像素。
Web/uni-app/小程序
typescriptcreateImageMessage(imageObj: string | File, name?: string, sceneName?: string, width?: number, height?: number): V2NIMChatroomMessage
参数名称 类型 是否必填 默认值 描述
imageObj Web File/string -
  • 非 Web 小程序:Web File 对象
  • Web 小程序:图片 URL 地址
  • name string 文件名 图片文件显示名称,可不同于文件名。
    sceneName string V2NIMStorageSceneConfig.DEFAULT_IM 对应的场景名 NOS 文件存储场景名。若使用自定义的存储场景,需要先调用 addCustomStorageScene 添加自定义存储场景。
    width number null 图片宽度,单位为像素。
    height number null 图片高度,单位为像素。

    示例代码

    Android
    javaV2NIMChatroomMessage v2ImageMessage = V2NIMChatroomMessageCreator.createImageMessage(imagePath, name, sceneName, width, height);
    
    iOS
    objective-cV2NIMChatroomMessage *v2ImageMessage = [V2NIMChatroomMessageCreator createImageMessage:imagePath
                                                                                     name:name
                                                                                sceneName:sceneName
                                                                                    width:width
                                                                                   height:height];
    
    macOS/Windows
    cppauto imageMessage = V2NIMChatroomMessageCreator::createImageMessage("imagePath", "imageName", V2NIM_STORAGE_SCENE_NAME_DEFAULT_IM, 100, 100);
    if (!imageMessage) {
        // create image message failed
    }
    
    Web/uni-app/小程序
    typescript/**
     * 除 imageObj 外,其它参数均是可选参数
     *
     * 浏览器中,imageObj 为 file 对象。小程序中, imageObj 为文件路径
     */
    const message = chatroom.V2NIMChatroomMessageCreator.createImageMessage(imageObj, name, sceneName, width, height)
    

    返回值

    已创建的聊天室消息对象 V2NIMChatroomMessage

    createAudioMessage

    接口描述

    创建一条语音消息。

    • 在加入聊天室后、发送消息前调用该方法。
    • 该方法为同步。

    参数说明

    Android
    javapublic static V2NIMChatroomMessage createAudioMessage(String audioPath, String name, String sceneName, Integer duration)
    
    参数名称 类型 是否必填 默认值 描述
    audioPath String - 语音文件 URL 地址
    name String null 语音文件显示名称,可不同于文件名。
    sceneName String V2NIMStorageSceneConfig.DEFAULT_IM 对应的场景名 NOS 文件存储场景名。若使用自定义的存储场景,需要先调用 addCustomStorageScene 添加自定义存储场景。
    duration Integer null 语音文件时长,单位为毫秒。
    iOS
    objective-c+ (V2NIMChatroomMessage *)createAudioMessage:(NSString *)audioPath
                                    name:(nullable NSString *)name
                               sceneName:(nullable NSString *)sceneName
                                duration:(int)duration;
    
    参数名称 类型 是否必填 默认值 描述
    audioPath NSString * - 语音文件 URL 地址
    name NSString * null 语音文件显示名称,可不同于文件名。
    sceneName NSString * V2NIMStorageSceneConfig.DEFAULT_IM 对应的场景名 NOS 文件存储场景名。若使用自定义的存储场景,需要先调用 addCustomStorageScene 添加自定义存储场景。
    duration int null 语音文件时长,单位为毫秒。
    macOS/Windows
    cppstatic nstd::optional<V2NIMChatroomMessage> createAudioMessage(nstd::string audioPath,
        nstd::string name,
        nstd::string sceneName,
        uint32_t duration);
    
    参数名称 类型 是否必填 默认值 描述
    audioPath nstd::string - 语音文件 URL 地址
    name nstd::string null 语音文件显示名称,可不同于文件名。
    sceneName nstd::string V2NIMStorageSceneConfig.DEFAULT_IM 对应的场景名 NOS 文件存储场景名。若使用自定义的存储场景,需要先调用 addCustomStorageScene 添加自定义存储场景。
    duration uint32_t null 语音文件时长,单位为毫秒。
    Web/uni-app/小程序
    typescriptcreateAudioMessage(audioObj: string | File, name?: string, sceneName?: string, duration?: number): V2NIMChatroomMessage
    
    参数名称 类型 是否必填 默认值 描述
    audioObj Web File/string -
  • 非 Web 小程序:Web File 对象
  • Web 小程序:语音文件 URL 地址
  • name string null 语音文件显示名称,可不同于文件名。
    sceneName string V2NIMStorageSceneConfig.DEFAULT_IM 对应的场景名 NOS 文件存储场景名。若使用自定义的存储场景,需要先调用 addCustomStorageScene 添加自定义存储场景。
    duration number - 语音文件时长,单位为毫秒。

    示例代码

    Android
    javaV2NIMChatroomMessage v2AudioMessage = V2NIMChatroomMessageCreator.createAudioMessage(audioPath, name, sceneName, duration);
    
    iOS
    objective-cV2NIMChatroomMessage *v2AudioMessage = [V2NIMChatroomMessageCreator createAudioMessage:audioPath
                                                                                      name:name
                                                                                 sceneName:sceneName
                                                                                  duration:duration];
    
    macOS/Windows
    cppauto audioMessage = V2NIMChatroomMessageCreator::createAudioMessage("audioPath", "audioName", V2NIM_STORAGE_SCENE_NAME_DEFAULT_IM, 100);
    if(!audioMessage) {
        // create audio message failed
    }
    
    Web/uni-app/小程序
    typescriptconst message = chatroom.V2NIMChatroomMessageCreator.createAudioMessage(audioObj, name, sceneName, duration)
    

    返回值

    已创建的聊天室消息对象 V2NIMChatroomMessage

    createVideoMessage

    接口描述

    创建一条视频消息。

    • 在加入聊天室后、发送消息前调用该方法。
    • 该方法为同步。

    参数说明

    Android
    javapublic static V2NIMChatroomMessage createVideoMessage(String videoPath, String name, String sceneName, Integer duration, Integer width, Integer height)
    
    参数名称 类型 是否必填 默认值 描述
    videoPath String - 视频文件 URL 地址
    name String null 视频文件显示名称,可不同于文件名。
    sceneName String V2NIMStorageSceneConfig.DEFAULT_IM 对应的场景名 NOS 文件存储场景名。若使用自定义的存储场景,需要先调用 addCustomStorageScene 添加自定义存储场景。
    duration Integer - 视频文件时长,单位为毫秒。
    width Integer null 视频宽度,单位为像素。
    height Integer null 视频高度,单位为像素。
    iOS
    objective-c+ (V2NIMChatroomMessage *)createVideoMessage:(NSString *)videoPath
                                    name:(nullable NSString *)name
                               sceneName:(nullable NSString *)sceneName
                                duration:(int)duration
                                   width:(int)width
                                  height:(int)height;
    
    参数名称 类型 是否必填 默认值 描述
    videoPath NSString * - 视频文件 URL 地址
    name NSString * null 视频文件显示名称,可不同于文件名。
    sceneName NSString * V2NIMStorageSceneConfig.DEFAULT_IM 对应的场景名 NOS 文件存储场景名。若使用自定义的存储场景,需要先调用 addCustomStorageScene 添加自定义存储场景。
    duration int - 视频文件时长,单位为毫秒。
    width int null 视频宽度,单位为像素。
    height int null 视频高度,单位为像素。
    macOS/Windows
    cppstatic nstd::optional<V2NIMChatroomMessage> createVideoMessage(nstd::string videoPath,
        nstd::string name,
        nstd::string sceneName,
        uint32_t duration,
        uint32_t width,
        uint32_t height);
    
    参数名称 类型 是否必填 默认值 描述
    videoPath nstd::string - 视频文件 URL 地址
    name nstd::string null 视频文件显示名称,可不同于文件名。
    sceneName nstd::string V2NIMStorageSceneConfig.DEFAULT_IM 对应的场景名 NOS 文件存储场景名。若使用自定义的存储场景,需要先调用 addCustomStorageScene 添加自定义存储场景。
    duration uint32_t - 视频文件时长,单位为毫秒。
    width uint32_t null 视频宽度,单位为像素。
    height uint32_t null 视频高度,单位为像素。
    Web/uni-app/小程序
    typescriptcreateVideoMessage(videoObj: string | File, name?: string, sceneName?: string, duration?: number, width?: number, height?: number): V2NIMChatroomMessage
    
    参数名称 类型 是否必填 默认值 描述
    videoObj Web File/string -
  • 非 Web 小程序:Web File 对象
  • Web 小程序:视频文件 URL 地址
  • name string null 视频文件显示名称,可不同于文件名。
    sceneName string V2NIMStorageSceneConfig.DEFAULT_IM 对应的场景名 NOS 文件存储场景名。若使用自定义的存储场景,需要先调用 addCustomStorageScene 添加自定义存储场景。
    duration number - 视频文件时长,单位为毫秒。
    width number null 视频宽度,单位为像素。
    height number null 视频高度,单位为像素。

    示例代码

    Android
    javaV2NIMChatroomMessage v2VideoMessage = V2NIMChatroomMessageCreator.createVideoMessage(videoPath, name, sceneName, duration, width, height);
    
    iOS
    objective-cV2NIMChatroomMessage *v2VideoMessage = [V2NIMChatroomMessageCreator createVideoMessage:videoPath
                                                                                      name:name
                                                                                 sceneName:sceneName
                                                                                  duration:duration 
                                                                                     width:width 
                                                                                    height:height];
    
    macOS/Windows
    cppauto videoMessage = V2NIMChatroomMessageCreator::createVideoMessage("videoPath", "videoName", V2NIM_STORAGE_SCENE_NAME_DEFAULT_IM, 100, 100,
    100); if (!videoMessage) {
        // create video message failed
    }
    
    Web/uni-app/小程序
    typescriptconst message = chatroom.V2NIMChatroomMessageCreator.createVideoMessage(videoObj, name, sceneName, duration, width, height)
    

    返回值

    已创建的聊天室消息对象 V2NIMChatroomMessage

    createFileMessage

    接口描述

    创建一条文件消息。

    • 在加入聊天室后、发送消息前调用该方法。
    • 该方法为同步。

    参数说明

    Android
    javapublic static V2NIMChatroomMessage createFileMessage(String filePath, String name, String sceneName)
    
    参数名称 类型 是否必填 默认值 描述
    filePath String - 文件 URL 地址
    name String null 文件显示名称,可不同于文件名。
    sceneName String V2NIMStorageSceneConfig.DEFAULT_IM 对应的场景名 NOS 文件存储场景名。若使用自定义的存储场景,需要先调用 addCustomStorageScene 添加自定义存储场景。
    iOS
    objective-c+ (V2NIMChatroomMessage *)createFileMessage:(NSString *)filePath
                                   name:(nullable NSString *)name
                              sceneName:(nullable NSString *)sceneName;
    
    参数名称 类型 是否必填 默认值 描述
    filePath NSString * - 文件 URL 地址
    name NSString * null 文件显示名称,可不同于文件名。
    sceneName NSString * V2NIMStorageSceneConfig.DEFAULT_IM 对应的场景名 NOS 文件存储场景名。若使用自定义的存储场景,需要先调用 addCustomStorageScene 添加自定义存储场景。
    macOS/Windows
    cppstatic nstd::optional<V2NIMChatroomMessage> createFileMessage(nstd::string filePath, nstd::string name, nstd::string sceneName);
    
    参数名称 类型 是否必填 默认值 描述
    filePath nstd::string - 文件 URL 地址
    name nstd::string null 文件显示名称,可不同于文件名。
    sceneName nstd::string V2NIMStorageSceneConfig.DEFAULT_IM 对应的场景名 NOS 文件存储场景名。若使用自定义的存储场景,需要先调用 addCustomStorageScene 添加自定义存储场景。
    Web/uni-app/小程序
    typescriptcreateFileMessage(fileObj: string | File, name?: string, sceneName?: string): V2NIMChatroomMessage
    
    参数名称 类型 是否必填 默认值 描述
    fileObj Web File/string -
  • 非 Web 小程序:Web File 对象
  • Web 小程序:文件 URL 地址
  • name string null 文件显示名称,可不同于文件名。
    sceneName string V2NIMStorageSceneConfig.DEFAULT_IM 对应的场景名 NOS 文件存储场景名。若使用自定义的存储场景,需要先调用 addCustomStorageScene 添加自定义存储场景。

    示例代码

    Android
    javaV2NIMChatroomMessage v2FileMessage = V2NIMChatroomMessageCreator.createFileMessage(filePath, name, sceneName);
    
    iOS
    objective-cV2NIMChatroomMessage *v2FileMessage = [V2NIMChatroomMessageCreator createFileMessage:filePath
                                                                                    name:name
                                                                               sceneName:sceneName];
    
    macOS/Windows
    cppauto fileMessage = V2NIMChatroomMessageCreator::createFileMessage("filePath", "fileName", V2NIM_STORAGE_SCENE_NAME_DEFAULT_IM);
    if(!fileMessage) {
        // create file message failed
    }
    
    Web/uni-app/小程序
    typescriptconst message = chatroom.V2NIMChatroomMessageCreator.createFileMessage(fileObj, name, sceneName)
    

    返回值

    已创建的聊天室消息对象 V2NIMChatroomMessage

    createLocationMessage

    接口描述

    创建一条地理位置消息。

    • 在加入聊天室后、发送消息前调用该方法。
    • 该方法为同步。

    参数说明

    Android
    javapublic static V2NIMChatroomMessage createLocationMessage(double latitude, double longitude, String address)
    
    参数名称 类型 是否必填 默认值 描述
    latitude double - 位置维度
    longitude double - 位置经度
    address String - 位置描述信息
    iOS
    objective-c+ (V2NIMChatroomMessage *)createLocationMessage:(double)latitude
                                  longitude:(double)longitude
                                    address:(NSString *)address;
    
    参数名称 类型 是否必填 默认值 描述
    latitude double - 位置维度
    longitude double - 位置经度
    address NSString * - 位置描述信息
    macOS/Windows
    cppstatic nstd::optional<V2NIMChatroomMessage> createLocationMessage(double latitude, double longitude, nstd::string address);
    
    参数名称 类型 是否必填 默认值 描述
    latitude double - 位置维度
    longitude double - 位置经度
    address nstd::string - 位置描述信息
    Web/uni-app/小程序
    typescriptcreateLocationMessage(latitude: number, longitude: number, address: string): V2NIMChatroomMessage
    
    参数名称 类型 是否必填 默认值 描述
    latitude number - 位置维度
    longitude number - 位置经度
    address string - 位置描述信息

    示例代码

    Android
    javaV2NIMChatroomMessage v2LocationMessage = V2NIMChatroomMessageCreator.createLocationMessage(latitude,longitude, address);
    
    iOS
    objective-cV2NIMChatroomMessage *v2LocationMessage = [V2NIMChatroomMessageCreator createLocationMessage:latitude
                                                                                       longitude:longitude
                                                                                         address:address];
    
    macOS/Windows
    cppauto locationMessage = V2NIMChatroomMessageCreator::createLocationMessage(100, 100, "address");
    if(!locationMessage) {
        // create location message failed
    }
    
    Web/uni-app/小程序
    typescriptconst message = chatroom.V2NIMChatroomMessageCreator.createLocationMessage(30.25, 120.166664, "HangZhou")
    

    返回值

    已创建的聊天室消息对象 V2NIMChatroomMessage

    createCustomMessage

    接口描述

    创建一条自定义消息。

    • 已注册一个自定义消息解析器。详见聊天室自定义消息收发
    • 在加入聊天室后、发送消息前调用该方法。
    • 该方法为同步。

    参数说明

    Android
    javapublic static V2NIMChatroomMessage createCustomMessage(String rawAttachment)
    
    参数名称 类型 是否必填 默认值 描述
    text String - 自定义消息文本内容,可用于推送及状态栏消息提醒的展示。
    rawAttachment String - 自定义消息附件对象。SDK 会将 JSON 格式的自定义消息解析为附件对象,用于自定义消息收发。长度上限为 4096 字节。
    iOS
    objective-c+ (V2NIMChatroomMessage *)createCustomMessage:(NSString *)rawAttachment;
    
    参数名称 类型 是否必填 默认值 描述
    text NSString * - 自定义消息文本内容,可用于推送及状态栏消息提醒的展示。
    rawAttachment NSString * - 自定义消息附件对象。SDK 会将 JSON 格式的自定义消息解析为附件对象,用于自定义消息收发。长度上限为 4096 字节。
    macOS/Windows
    cppstatic nstd::optional<V2NIMChatroomMessage> createCustomMessage(nstd::string rawAttachment);
    
    参数名称 类型 是否必填 默认值 描述
    text nstd::string - 自定义消息文本内容,可用于推送及状态栏消息提醒的展示。
    rawAttachment nstd::string - 自定义消息附件对象。SDK 会将 JSON 格式的自定义消息解析为附件对象,用于自定义消息收发。长度上限为 4096 字节。
    Web/uni-app/小程序
    typescriptcreateCustomMessage(rawAttachment: string): V2NIMChatroomMessage
    
    参数名称 类型 是否必填 默认值 描述
    text string - 自定义消息文本内容,可用于推送及状态栏消息提醒的展示。
    rawAttachment string - 自定义消息附件对象。SDK 会将 JSON 格式的自定义消息解析为附件对象,用于自定义消息收发。长度上限为 4096 字节。

    示例代码

    Android
    javaV2NIMChatroomMessage v2CustomMessage = V2NIMChatroomMessageCreator.createCustomMessage(rawAttachment);
    
    iOS
    objective-cV2NIMChatroomMessage *v2CustomMessage = [V2NIMChatroomMessageCreator createCustomMessage:rawAttachment];
    
    macOS/Windows
    cppauto customMessage = V2NIMChatroomMessageCreator::createCustomMessage(R"({"key": "value"})");
    if(!customMessage) {
        // create custom message failed
    }
    
    Web/uni-app/小程序
    typescriptconst message = chatroom.V2NIMChatroomMessageCreator.createCustomMessage(JSON.stringify({
        strategy: 1
    }))
    

    返回值

    已创建的聊天室消息对象 V2NIMChatroomMessage

    createForwardMessage

    接口描述

    创建一条转发消息。

    • 转发的消息类型不能为 V2NIM_MESSAGE_TYPE_NOTIFICATION(5)V2NIM_MESSAGE_TYPE_ROBOT(11)V2NIM_MESSAGE_TYPE_TIPS(10)V2NIM_MESSAGE_TYPE_AVCHAT(7)
    • 转发的消息消息必须为发送成功的消息,消息状态必须为 V2NIMMessagesendingState.V2NIM_MESSAGE_SENDING_STATE_SUCCEEDED(1),消息内容与原消息相同。
    • 在加入聊天室后、发送消息前调用该方法。
    • 该方法为同步。

    参数说明

    Android
    javapublic static V2NIMChatroomMessage createForwardMessage(V2NIMChatroomMessage message)
    
    参数名称 类型 是否必填 默认值 描述
    message V2NIMChatroomMessage - 待转发的消息体
    iOS
    objective-c+ (V2NIMChatroomMessage *)createForwardMessage:(V2NIMChatroomMessage *)message;
    
    参数名称 类型 是否必填 默认值 描述
    message V2NIMChatroomMessage - 待转发的消息体
    macOS/Windows
    cppstatic nstd::optional<V2NIMChatroomMessage> createForwardMessage(V2NIMChatroomMessage message);
    
    参数名称 类型 是否必填 默认值 描述
    message V2NIMChatroomMessage - 待转发的消息体
    Web/uni-app/小程序
    typescriptcreateForwardMessage(message: V2NIMChatroomMessage): V2NIMChatroomMessage | null
    
    参数名称 类型 是否必填 默认值 描述
    message V2NIMChatroomMessage - 待转发的消息体

    示例代码

    Android
    javaV2NIMChatroomMessage v2ForwardMessage = V2NIMChatroomMessageCreator.createForwardMessage(v2ChatroomMessage);
    
    iOS
    objective-cV2NIMChatroomMessage *v2ForwardMessage = [V2NIMChatroomMessageCreator createForwardMessage:v2ChatroomMessage];
    
    macOS/Windows
    cppauto forwardMessage = V2NIMChatroomMessageCreator::createForwardMessage(message);
    if(!forwardMessage) {
        // create forward message failed
    }
    
    Web/uni-app/小程序
    typescriptconst newMessage = chatroom.V2NIMChatroomMessageCreator.createForwardMessage(message)
    

    返回值

    已创建的聊天室消息对象 V2NIMChatroomMessage

    createTipsMessage

    接口描述

    创建一条提示消息。

    • 在加入聊天室后、发送消息前调用该方法。
    • 该方法为同步。

    参数说明

    Android
    javapublic static V2NIMChatroomMessage createTipsMessage(String text)
    
    参数名称 类型 是否必填 默认值 描述
    text String - 提示消息内容
    iOS
    objective-c+ (V2NIMChatroomMessage *)createTipsMessage:(NSString *)text;
    
    参数名称 类型 是否必填 默认值 描述
    text NSString * - 提示消息内容
    macOS/Windows
    cppstatic nstd::optional<V2NIMChatroomMessage> createTipsMessage(nstd::string text);
    
    参数名称 类型 是否必填 默认值 描述
    text nstd::string - 提示消息内容
    Web/uni-app/小程序
    typescriptcreateTipsMessage(text: string): V2NIMChatroomMessage
    
    参数名称 类型 是否必填 默认值 描述
    text string - 提示消息内容

    示例代码

    Android
    javaV2NIMChatroomMessage v2TipMessage = V2NIMChatroomMessageCreator.createTipsMessage("tip content");
    
    iOS
    objective-cV2NIMChatroomMessage *v2TipMessage = [V2NIMChatroomMessageCreator createTipsMessage:@"tip content"];
    
    macOS/Windows
    cppauto tipMessage = V2NIMChatroomMessageCreator::createTipsMessage("text");
    if(!tipMessage) {
        // create tip message failed
    }
    
    Web/uni-app/小程序
    typescriptconst message = chatroom.V2NIMChatroomMessageCreator.createTipsMessage('hint')
    

    返回值

    已创建的聊天室消息对象 V2NIMChatroomMessage

    此文档是否对你有帮助?
    有帮助
    去反馈
    • 支持平台
    • API 概览
    • 接口类
    • createTextMessage
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • createImageMessage
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • createAudioMessage
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • createVideoMessage
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • createFileMessage
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • createLocationMessage
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • createCustomMessage
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • createForwardMessage
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值
    • createTipsMessage
    • 接口描述
    • 参数说明
    • 示例代码
    • 返回值