TencentCloudChat 1.0.1

dotnet add package TencentCloudChat --version 1.0.1                
NuGet\Install-Package TencentCloudChat -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TencentCloudChat" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TencentCloudChat --version 1.0.1                
#r "nuget: TencentCloudChat, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TencentCloudChat as a Cake Addin
#addin nuget:?package=TencentCloudChat&version=1.0.1

// Install TencentCloudChat as a Cake Tool
#tool nuget:?package=TencentCloudChat&version=1.0.1                

Tencent Cloud Chat SDK

Globally interconnected In-App Chat, user profile and relationship chains and offline push.

More languages: 简体中文 한국어 日本語

alternate text is missing from this package README image

This document will guide you through the whole process of intergating Tencent Cloud IM SDK into your C# project.

About Tencent Cloud Chat

Tencent Cloud Chat provides globally connected chat APIs, multi-platform SDKs, and UIKit components to help you quickly bring messaging capabilities such as one-to-one chat, group chat, chat rooms, and system notifications into your applications and websites.

With the official c# sdk im_csharp_sdk you can efficiently integrate live chat into your applications.

You can register a Tencent Cloud account here.

Explore more documents about Tencent Cloud Instant Messenger.

Supported platforms

Platform Version
MacOs OS X 10.10+.
Windows Minimum requirement is Windows 7.

Environment Requirements

Platform Version
MacOs Xcode 9.0+ / Visual Studio For Mac 2019+
Windows The minimum version requirement is Visual Studio 2010, and Visual Studio 2019 is recommended.
.Net version 7.0+

.Net Standard

  • standard 2.1
  • standard 2.0
  • And the above corresponding .Net Core, .Net Framework, Xamarin.Mac

Prerequisites

  1. You have signed up for a Tencent Cloud account and completed identity verification.
  2. Create an application by the guide Creating and Upgrading an Application, and keep record of your SDKAppID.

Part 1. Create an IM app

  1. Log in to the IM console

?If you already have an app, record its SDKAppID and obtain key information。 A Tencent Cloud account can create a maximum of 300 IM apps. If you want to create a new app, disable and delete an unwanted app first. Once an app (along with its SDKAppID) is deleted, the service it provides and all its data are lost. Proceed with caution.

  1. Click Create Application, enter your app name, and click Confirm. alternate text is missing from this package README image
  2. Select Auxiliary Tools > UserSig Generation and Verification on the left sidebar. Create a UserID and the corresponding UserSig, and copy the signature information for login. alternate text is missing from this package README image

Part 2. Integrate Tencent Cloud Chat into your C# Projects

By Visual Studio
  1. Right-click on your project in the Solution Explorer and select "Manage NuGet Packages".
  2. Select Tencent Cloud Chat and install it to your project
By dotnet
  1. Navigate to your project or your directory
  2. Run the following command to add Nuget package dotnet add package <package-name>

Part 3. Initialize and Login to Tencent Cloud Chat

Initialize

Detailed document for the section

Invoke TencentIMSDK.Init to initialize SDK, by passing your SDKAppID.

using com.tencent.imsdk.enums;
using com.tencent.imsdk.types;
using com.tencent.imsdk;
SdkConfig sdkConfig = new SdkConfig();
TIMResult timSucc = TencentIMSDK.Init(long.Parse(""), sdkConfig);

After Init, you are able to add event listeners to listen to network status changes, user information modifications and so on, check more on here. Tencent cloud chat c# sdk shares api with Tencent cloud chat Unity sdk and C sdk.

Login

Detailed document for the section

Now, you can login the testing account created on the web console.

Invoke TencentIMSDK.Login to login your account.

When return res.code equals to 0, login succeeded.

public static void Login() {
  if (userid == "" || user_sig == "")
  {
      return;
  }
  TIMResult res = TencentIMSDK.Login(userid, user_sig, (int code, string desc, string json_param, string user_data)=>{

  });
}

Send Message

Detailed document for the section

Here is the example code for sending text 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, // It is `TIMConvType.kTIMConv_Group` for a group message.
        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
}

Acquire Conversation List

Detailed document for the section

In the last step, you have successfully sent testing messages, and now you can login to another account to retrieve the conversation list.

Two ways to acquire conversation list:

  1. Listen to the conversation event.
  2. Call API to get conversation list.

Common scene is:

After init the app, retrieve the conversation list immediately, and then listen to the conversation events.

Get conversaion list from API
TIMResult res = TencentIMSDK.ConvGetConvList((int code, string desc, List<ConvInfo> info_list, string user_data)=>{

});
Listen to the conversation updates
TencentIMSDK.SetConvEventCallback((TIMConvEvent conv_event, List<ConvInfo> conv_list, string user_data)=>{

});

Receive Message

Detailed document for the section

There are two ways to receive messages:

  1. Set message receiver listener.
  2. Call API to retrieve messages.
Pulling Historical One-to-One Messages
// Pull historical one-to-one messages
// Set `msg_getmsglist_param_last_msg` to `null` for the first pull
// `msg_getmsglist_param_last_msg` can be the last message in the returned message list for the second pull.
var get_message_list_param = new MsgGetMsgListParam
 {
   msg_getmsglist_param_last_msg = LastMessage
 };
TIMResult res = TencentIMSDK.MsgGetMsgList(conv_id, TIMConvType.kTIMConv_C2C, get_message_list_param, (int code, string desc, string user_data) => {
// Process the callback logic
});

Pulling Historical Group Messages
// Pull historical group messages
// Set `msg_getmsglist_param_last_msg` to `null` for the first pull
// `msg_getmsglist_param_last_msg` can be the last message in the returned message list for the second pull.
var get_message_list_param = new MsgGetMsgListParam
 {
   msg_getmsglist_param_last_msg = LastMessage
 };
TIMResult res = TencentIMSDK.MsgGetMsgList(conv_id, TIMConvType.kTIMConv_Group, get_message_list_param, (int code, string desc, string user_data) => {
// Process the callback logic
});

Set listener for receiving new messages
TencentIMSDK.AddRecvNewMsgCallback((List<Message> message, string user_data) => {

});

Now, you have tested the basic functionality of Tencent Cloud IM.

other problems

  1. nullable not supported You can add the following content to the project's .csproj
     <PropertyGroup>
      <Nullable>enable</Nullable>
    </PropertyGroup>
    

Contact Us

Please do not hesitate to contact us in the following place, if you have any further questions or tend to learn more about the use cases.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 149 1/17/2024