CometChat Pro Documentation

You'll find comprehensive guides and documentation to help you start working with CometChat as quickly as possible. Let's jump right in!

Get your Application Keys

Signup for CometChat and then:

  1. Create a new app
  2. Head over to the API Keys section and click on the Create API Key button
  3. Enter a name and select the scope as Auth Only
  4. Now note the API Key and App ID

Add the CometChat Dependency

Web (Browser)

First,simply connect the JS file as a normal script:

<html>
<!--
 Your html code
  ... 
  ...
 -->
<script type="text/javascript" src="https://unpkg.com/@cometchat-pro/chat@1.8.3/CometChat.js"></script>

<script type="text/javascript">
 window.onload = (function () {
  // window scoped variable called `CometChat` is created.
 })
</script>
</html>

Then a window scoped variable called CometChat is created.

Or install the package as NPM module:

npm install @cometchat-pro/chat --save

And add the script to HTML file from the 'node_modules' folder (as a relative path):

<script src="~/node_modules/@cometchat-pro/chat/CometChat.js" type="text/javascript"></script>

Node.js/NPM

First, install the package as NPM module:

npm install @cometchat-pro/chat@1.8.3 --save

Then start using CometChat

import { CometChat } from "@cometchat-pro/chat";

Initialize CometChat

The init() method initializes the settings required for CometChat.

You need to call init() before calling any other method from CometChat.

<script type="text/javascript" src="https://unpkg.com/@cometchat-pro/chat@1.8.3/CometChat.js"></script>

<script type="text/javascript">
 window.onload = (function () {
  var appId = "APP_ID";
  CometChat.init(appId).then(
   () => {
    console.log("Initialization completed successfully");
    //You can now call login function.
   },
   error => {
    console.log("Initialization failed with error:", error);
    //Check the reason for error and take apppropriate action.
   }
  );
 })
</script>
Parameter
Description

appID

CometChat App ID

Setup


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.