@cometchat-pro/chat

中文文档
3.0.13发布于 2023/07/24SEE LICENSE IN LICENSE.mdTypeScriptCommonJS零依赖近 30 天下载 1.2万

A complete chat solution.

原始使用文档
文档目录14 节
  1. Features
  2. Extensions
  3. Prerequisites :star:
  4. Installing CometChat Javascript SDK
  5. Setup :wrench:
  6. i. Get your Application Keys :key:
  7. ii. Add the CometChat Dependency
  8. Configure CometChat Javascript SDK
  9. i. Initialize CometChat 🌟
  10. ii. Create User 👤
  11. iii. Login User 👤
  12. Learn more about UI-Kit
  13. Contributors :clap:
  14. Contact :mailbox:



CometChat Javascript SDK

CometChat Pro enables you to add voice, video & text chat for your website & app. This guide demonstrates how to add chat to a WebSite using CometChat Pro.

Features

  • 1-1 & Group Conversations
  • Voice & video calling & conferencing
  • Rich Media Attachments
  • Typing Indicators
  • Custom Messages
  • Read receipts
  • Online Presence Indicators
  • Message History
  • Single Sign-on
  • Webhooks
  • Bots
  • Users & Friends List
  • Groups List
  • Conversations List
  • Threaded Conversations

Extensions

Push Notification | Email Notification | SMS Notification | Thumbnail Generation | Link Preview | Rich Media Preview | Voice Transcription | Smart Reply | Message Translation | Emojis | Polls | Reactions | Stickers | Video Broadcasting | Collaborative Documents | Collaborative Whiteboards | Data Masking Filter | Profanity Filter | Image Moderation| Sentiment Analysis | In-flight Message Moderation | Virus & Malware Scanner | XSS Filter

Platform GitHub repo size GitHub contributors GitHub stars Twitter Follow


Prerequisites :star:

Before you begin, ensure you have met the following requirements:
✅   You have Visual Studio Code or any other code editor installed in your machine.
✅   You have npm installed in your machine.
✅   You have read CometChat Key Concepts.


Installing CometChat Javascript SDK

Setup :wrench:

To setup Javascript SDK, you need to first register on CometChat Dashboard. Click here to sign up.

i. Get your Application Keys :key:

Signup for CometChat and then:

  1. Create a new app: Click Add App option available → Enter App Name & other information → Create App
  2. At the Top in QuickStart section you will find Auth Key & App ID or else you can head over to the API & Auth Keys section and note the Auth Key and App ID

ii. Add the CometChat Dependency

  • Install via NPM
    1. Run the following command to install the CometChat Pro Javascript SDK
        npm install @cometchat-pro/[email protected] --save
    
  • Import via CDN
    1. Include the CometChat Pro Javascript library in your HTML code.
      <script type="text/javascript" src="https://unpkg.com/@cometchat-pro/[email protected]/CometChat.js"></script>
    

    You can refer to the below link for instructions on how to do so:
    📝 Add CometChat Dependency


Configure CometChat Javascript SDK

i. Initialize CometChat 🌟

We suggest you call the init() method on app startup, preferably in the index.js file.

var appID = "APP_ID";
var region = "REGION";
var appSetting = new CometChat.AppSettingsBuilder().subscribePresenceForAllUsers().setRegion(region).build();
CometChat.init(appID, appSetting).then(
  () => {
    console.log("Initialization completed successfully");
  },
  error => {
    console.log("Initialization failed with error:", error);
  }
);
:information_source:   Note: Make sure to replace region and appID with your credentials.

ii. Create User 👤

Once initialisation is successful, you will need to create a user. You need to use createUser() method to create user on the fly.

let authKey = "AUTH_KEY";
var uid = "user1";
var name = "Kevin";

var user = new CometChat.User(uid);

user.setName(name);

CometChat.createUser(user, authKey).then(
  user => {
    console.log("user created", user);
  },error => {
    console.log("error", error);
  }
);

:information_source: Note: Make sure that UID and name are specified as these are mandatory fields to create a user.


iii. Login User 👤

Once you have created the user successfully, you will need to log the user into CometChat using the login() method.

var UID = "SUPERHERO1";
var authKey = "AUTH_KEY";

CometChat.getLoggedinUser().then(
  user => {
    if(!user){
      CometChat.login(UID, authKey).then(
        user => {
          console.log("Login Successful:", { user });    
        },
        error => {
          console.log("Login failed with exception:", { error });    
        }
      );
    }else{
      // User already logged in
    }
  }, error => {
    console.log("getLoggedinUser failed with exception:", { error });
  }
);
:information_source:   Note - The login() method needs to be called only once. Also replace AUTH_KEY with your App Auth Key.

📝 Please refer to our Developer Documentation for more information on how to configure the CometChat Pro SDK and implement various features using the same.


Learn more about UI-Kit

Angular UI Kit | React UI Kit | Vue UI Kit

Contributors :clap:

Thanks to the following people who have contributed to this project: 👨‍💻 @ajaygajra 👨‍💻 @mayur-bhandari


Contact :mailbox:

Contact us via real time support present in CometChat Dashboard.


版本与发布记录

@cometchat-pro/chat 共发布 145 个版本,首次发布于 2019/01/15;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.0.13latest2023/07/243 年前
3.0.13-beta22023/07/243 年前
3.0.13-beta12023/07/243 年前
3.0.122023/05/223 年前
3.0.112023/01/253 年前
3.0.102022/07/204 年前

其他发布通道:beta → 3.0.2-beta1。

关于 @cometchat-pro/chat 的常见问题

@cometchat-pro/chat 是什么?

A complete chat solution.

如何安装 @cometchat-pro/chat?

在项目目录运行 npm install @cometchat-pro/chat,或使用 pnpm add / yarn add / bun add。

@cometchat-pro/chat 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cometchat-pro/chat 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@cometchat-pro/chat 可以商用吗?

@cometchat-pro/chat 使用 SEE LICENSE IN LICENSE.md 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@cometchat-pro/chat 的下载量有多少?

根据 npm 官方下载统计,@cometchat-pro/chat 在 2026/10/11 – 2026/11/09 这 30 天内被下载 11,576 次,日均约 386 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cometchat-pro/chat 还在维护吗?

最新版本 3.0.13 发布于 2023/07/24(3 年前);至今共发布 145 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/01/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。