please select
  • UIKit
  • SDK
  • Server APIs
Chat/
SDK/
Unity(Game Solution)/
Message/
SDK
  • Run Demo
  • SDK Integration
  • Initialization
  • Login and Logout
  • Message
    • Message Overview
    • Sending Message
    • Receiving Message
    • Historical Message
    • Forwarding Message
    • Modifying Message
    • Deleting Message
    • Clearing Messages
    • Recalling Message
    • Online Message
    • Read Receipt
    • Querying Message
    • Group @ Message
    • Targeted Group Message
    • Notification Muting
    • Message Extension
  • Conversation
    • Conversation Overview
    • Conversation List
    • Getting Conversation
    • Conversation Unread Count
    • Pinning Conversation to the Top
    • Deleting Conversation
    • Conversation Draft
    • Conversation Mark
    • Conversation Group
  • Group
    • Group Overview
    • Group Management
    • Group Profile
    • Group Member Management
    • Group Member Profile
    • Custom Group Attribute
    • Group Counter
  • User
    • User Profile
    • User Status
    • Friend Management
    • Friend List
    • Blocklist
  • Changelog
  • Guideline for Beginners
  • Console Guide
    • Creating and Upgrading an Application
    • Basic Configuration
    • Feature Configuration
    • Account Management
    • Group Management
    • Webhook Configuration
  • Product Introduction
    • Message Management
      • One-to-One Message
      • Message Storage
      • Offline Push
      • Group Message
      • Message Formats
    • Account System
      • Login Authentication
      • Online Status Management
    • Group Related
      • Group System
      • Group Management
    • User Profile and Relationship Chain
      • Profile Management
      • Relationship Chain Management
  • Purchase Guide
    • Billing Overview
    • Pricing
  • Error Codes

Sending Message

Overview

You can send text, custom, and rich media messages, all of which belong to the Message type.

Key APIs

The MsgSendMessage API (details) is the core API for sending a message. It supports sending all types of messages.
The API is detailed as follows:
Type
Name
Description
System.String
conv_id
Conversation ID
TIMConvType
conv_type
Conversation type
Message
message
Message
System.Text.StringBuilder
message_id
Message ID
ValueCallback
| ValueCallback

callback
Async callback

Sending Text Messages

public static void MsgSendMessage() {
string conv_id = ""; // The conversation ID of a one-to-one message is the `userID`, and that of a group message is the `groupID`.
Message message = new Message
{
message_conv_id = conv_id,
message_conv_type = TIMConvType.kTIMConv_C2C, // For a group message, this value is `TIMConvType.kTIMConv_Group`
message_elem_array = new List<Elem>
{
new Elem
{
elem_type = TIMElemType.kTIMElem_Text,
text_elem_content = "This is an ordinary text message"
}
}
};
StringBuilder messageId = new StringBuilder(128);

TIMResult res = TencentIMSDK.MsgSendMessage(conv_id, TIMConvType.kTIMConv_C2C, message, messageId, (int code, string desc, string json_param, string user_data)=>{
// Async message sending result
});
// The message ID messageId returned when the message is sent
}

Sending Image Messages

public static void MsgSendMessage() {
string conv_id = ""; // The conversation ID of a one-to-one message is the `userID`, and that of a group message is the `groupID`.
Message message = new Message
{
message_conv_id = conv_id,
message_conv_type = TIMConvType.kTIMConv_C2C, // For a group message, this value is `TIMConvType.kTIMConv_Group`
message_elem_array = new List<Elem>
{
new Elem
{
elem_type = TIMElemType.kTIMElem_Image,
image_elem_orig_path = "/Users/xxx/xxx.png", // Absolute path to the file
image_elem_level = TIMImageLevel.kTIMImageLevel_Orig // Send an original image
}
}
};
StringBuilder messageId = new StringBuilder(128);

TIMResult res = TencentIMSDK.MsgSendMessage(conv_id, TIMConvType.kTIMConv_C2C, message, messageId, (int code, string desc, string json_param, string user_data)=>{
// Async message sending result
});
// The message ID messageId returned when the message is sent
}

Sending a Voice Message

public static void MsgSendMessage() {
string conv_id = ""; // The conversation ID of a one-to-one message is the `userID`, and that of a group message is the `groupID`.
Message message = new Message
{
message_conv_id = conv_id,
message_conv_type = TIMConvType.kTIMConv_C2C, // For a group message, this value is `TIMConvType.kTIMConv_Group`
message_elem_array = new List<Elem>
{
new Elem
{
elem_type = TIMElemType.kTIMElem_Sound,
sound_elem_file_path = "/Users/xxx/xxx.mp3", // Absolute file path
sound_elem_file_size = 10 // Audio duration

}
}
};
StringBuilder messageId = new StringBuilder(128);

TIMResult res = TencentIMSDK.MsgSendMessage(conv_id, TIMConvType.kTIMConv_C2C, message, messageId, (int code, string desc, string json_param, string user_data)=>{
// Async message sending result
});
// The message ID messageId returned when the message is sent
}

Sending a Video Message

public static void MsgSendMessage() {
string conv_id = ""; // The conversation ID of a one-to-one message is the `userID`, and that of a group message is the `groupID`.
Message message = new Message
{
message_conv_id = conv_id,
message_conv_type = TIMConvType.kTIMConv_C2C, // For a group message, this value is `TIMConvType.kTIMConv_Group`
message_elem_array = new List<Elem>
{
new Elem
{
elem_type = TIMElemType.kTIMElem_Video,
video_elem_video_path = "/Users/xxx/xxx.mp4", // Absolute file path
video_elem_video_type = "mp4", // Video type
video_elem_video_duration = 10, // Video duration

video_elem_image_path = "Absolute path of the local video thumbnail file",
video_elem_image_type = "png", // Type of the video screenshot file
video_elem_image_size = 100, // Size of the video screenshot file
video_elem_image_width = 1920, // Width of the video screenshot file
video_elem_image_height = 1080, // Height of the video screenshot file
}
}
};
StringBuilder messageId = new StringBuilder(128);

TIMResult res = TencentIMSDK.MsgSendMessage(conv_id, TIMConvType.kTIMConv_C2C, message, messageId, (int code, string desc, string json_param, string user_data)=>{
// Async message sending result
});
// The message ID messageId returned when the message is sent
}

Sending a File Message

public static void MsgSendMessage() {
string conv_id = ""; // The conversation ID of a one-to-one message is the `userID`, and that of a group message is the `groupID`.
Message message = new Message
{
message_conv_id = conv_id,
message_conv_type = TIMConvType.kTIMConv_C2C, // For a group message, this value is `TIMConvType.kTIMConv_Group`
message_elem_array = new List<Elem>
{
new Elem
{
elem_type = TIMElemType.kTIMElem_File,
file_elem_file_path = "/Users/xxx/xxx.x", // Absolute file path
file_elem_file_name = "Filename",
}
}
};
StringBuilder messageId = new StringBuilder(128);

TIMResult res = TencentIMSDK.MsgSendMessage(conv_id, TIMConvType.kTIMConv_C2C, message, messageId, (int code, string desc, string json_param, string user_data)=>{
// Async message sending result
});
// The message ID messageId returned when the message is sent
}

Sending a Location Message

public static void MsgSendMessage() {
string conv_id = ""; // The conversation ID of a one-to-one message is the `userID`, and that of a group message is the `groupID`.
Message message = new Message
{
message_conv_id = conv_id,
message_conv_type = TIMConvType.kTIMConv_C2C, // For a group message, this value is `TIMConvType.kTIMConv_Group`
message_elem_array = new List<Elem>
{
new Elem
{
elem_type = TIMElemType.kTIMElem_Location,
location_elem_desc = "Shennan Boulevard, Nanshan District, Shenzhen",// Location information digest
location_elem_longitude = 34, // Longitude
location_elem_latitude = 20 // Latitude
}
}
};
StringBuilder messageId = new StringBuilder(128);

TIMResult res = TencentIMSDK.MsgSendMessage(conv_id, TIMConvType.kTIMConv_C2C, message, messageId, (int code, string desc, string json_param, string user_data)=>{
// Async message sending result
});
// The message ID messageId returned when the message is sent
}

Send an Emoji Message

public static void MsgSendMessage() {
string conv_id = ""; // The conversation ID of a one-to-one message is the `userID`, and that of a group message is the `groupID`.
Message message = new Message
{
message_conv_id = conv_id,
message_conv_type = TIMConvType.kTIMConv_C2C, // For a group message, this value is `TIMConvType.kTIMConv_Group`
message_elem_array = new List<Elem>
{
new Elem
{
elem_type = TIMElemType.kTIMElem_Face,
face_elem_index = 0,
face_elem_buf = ""
}
}
};
StringBuilder messageId = new StringBuilder(128);

TIMResult res = TencentIMSDK.MsgSendMessage(conv_id, TIMConvType.kTIMConv_C2C, message, messageId, (int code, string desc, string json_param, string user_data)=>{
// Async message sending result
});
// The message ID messageId returned when the message is sent
}

Sending Custom Messages

public static void MsgSendMessage() {
string conv_id = ""; // The conversation ID of a one-to-one message is the `userID`, and that of a group message is the `groupID`.
Message message = new Message
{
message_conv_id = conv_id,
message_conv_type = TIMConvType.kTIMConv_C2C, // For a group message, this value is `TIMConvType.kTIMConv_Group`
message_elem_array = new List<Elem>
{
new Elem
{
elem_type = TIMElemType.kTIMElem_Custom,
custom_elem_data = "",
custom_elem_desc = "",
custom_elem_ext = ""
}
}
};
StringBuilder messageId = new StringBuilder(128);

TIMResult res = TencentIMSDK.MsgSendMessage(conv_id, TIMConvType.kTIMConv_C2C, message, messageId, (int code, string desc, string json_param, string user_data)=>{
// Async message sending result
});
// The message ID messageId returned when the message is sent
}