Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tencentcloud/chat

Package Overview
Dependencies
Maintainers
12
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tencentcloud/chat

Tencent Cloud Chat SDK for Web

  • 3.2.1
  • npm
  • Socket score

Version published
Weekly downloads
1.2K
decreased by-0.58%
Maintainers
12
Weekly downloads
 
Created
Source

Official JavaScript SDK for Tencent Cloud Chat

About Tencent Cloud Chat

Tencent Cloud Chat provides globally interconnected 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 to your applications and websites.

👉🏻 Free Demo

📄 Documentation

Global Compliance Certifications

Core Capabilities

  • 1 Billion+ Monthly active users
  • 550 Billion+ Daily peak messages
  • 100,000+ Customers worldwid
  • 99.99% Message success rate

Empower chat messaging across applications to create one-to-one chats, group chats, and on-screen commenting and support multiple messages types such as text, images, audio and video messages.

Integrate audio/video call capabilities into your app with a few lines of code through audio/video UI components. Offline call push is also supported to allow your app users get every calls.

Chat supports audio-video groups with unlimited number of members, providing chat, like, gift giving, following, group member management and other functions to help you achieve in-app live streaming.

Scenarios

  • Interactive Live Streaming

  • Social Messaging

  • Influencer Marketing

  • Interactive Game

  • Customer Service

  • Education

  • Healthcare

  • Smart Device

  • OA

  • Meeting

  • Private Cloud Deployment

Installation

npm install @tencentcloud/chat --save
// The upload plugin is required to send messages such as images and files.
npm install tim-upload-plugin --save

Getting started

import TencentCloudChat from '@tencentcloud/chat';
import TIMUploadPlugin from 'tim-upload-plugin';

// Create an SDK instance. 
// The `TencentCloudChat.create()` method returns the same instance for the same `SDKAppID`.
// The SDK instance is usually represented by `chat`.
let chat = TencentCloudChat.create({
  SDKAppID: 0 // Replace `0` with the `SDKAppID` of your Chat app during access.
}); 

// Common level. You are advised to use this level during connection as it covers more logs.
chat.setLogLevel(0);
// Release level, at which the SDK outputs important information.
// You are advised to use this log level in a production environment.
// chat.setLogLevel(1);

// Register the Tencent Cloud Chat upload plugin.
chat.registerPlugin({'tim-upload-plugin': TIMUploadPlugin});

Sending your first message

1. Generate UserSig

UserSig is a password used to log in to Tencent Cloud Chat. It is the ciphertext obtained after data such as UserID is encrypted. This document describes how to generate a UserSig.

2. Listen to the SDK_READY event

// This event is triggered when the SDK enters the ready state.
// When SDK is ready, the access side can call SDK APIs such as the message sending API to use various features of the SDK
let onSdkReady = function(event) {
  // Now you can create a message instance and send it.
};
chat.on(TencentCloudChat.EVENT.SDK_READY, onSdkReady);

let onMessageReceived = function(event) {
  // A newly pushed one-to-one message, group message, group tip, or group system notification is received. You can traverse event.data to obtain the message list and render it to the UI.
  // event.name - TencentCloudChat.EVENT.MESSAGE_RECEIVED
  // event.data - An array that stores Message objects - [Message]
};
chat.on(TencentCloudChat.EVENT.MESSAGE_RECEIVED, onMessageReceived);

3. Login in to the Chat SDK

let promise = chat.login({userID: 'your userID', userSig: 'your userSig'});
promise.then(function(imResponse) {
  console.log(imResponse.data); // Login successful
  if (imResponse.data.repeatLogin === true) {
    // Indicates that the account has logged in and that the current login will be a repeated login.
    console.log(imResponse.data.errorInfo);
  }
}).catch(function(imError) {
  console.warn('login error:', imError); // Error information
});

After successful login, to call APIs that require authentication, such as sendMessage, you must wait until the SDK enters the ready state (you can obtain the status of the SDK by listening to the TencentCloudChat.EVENT.SDK_READY event.

3. Create a message instance

let message = chat.createTextMessage({
  to: 'user1',
  conversationType: TencentCloudChat.TYPES.CONV_C2C,
  payload: {
    text: 'Hello Tencent!'
  },
  // Message custom data (saved in the cloud, will be sent to the peer end, and can still be pulled after the app is uninstalled and reinstalled)
  // cloudCustomData: 'your cloud custom data'
});

4. Send the message instance

let promise = chat.sendMessage(message);
promise.then(function(imResponse) {
  // The message is sent successfully.
  console.log(imResponse);
}).catch(function(imError) {
  // The message fails to be sent.
  console.warn('sendMessage error:', imError);
});

Contact Us

Join a Tencent Cloud Chat developer group for Reliable technical support & Product details & Constant exchange of ideas.

  • Telegram group (EN): join
  • WhatsApp group (EN): join
  • Telegram group (ZH): join
  • WhatsApp group (ZH): join

Supported Browsers

BrowserSupported versions
Chrome16 or higher
Edge13 or higher
Firefox11 or higher
Safari7 or higher
Internet Explorer10 or higher
Opera12.1 or higher
iOS Safari7 or higher
Android Browswer4.4 (Kitkat) or higher

Keywords

FAQs

Package last updated on 18 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc