CometChat Developer Documentation

Welcome Ninja!

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

Get Started    

Quick Start

The simplest voice, video and text chat SDK for your website.

First, create a sample!

Let's start by creating two simple HTML files and adding the basic CometChat code to it. This will be sufficient to see a working sample.

<!DOCTYPE html>
<html>
<head>
  <title>CometChat Test</title>
</head>
<body>


<script type="text/javascript">

  var chat_appid = 'XXXXX';
  var chat_id = 'SUPERHERO1';

  (function() {
    var css = document.createElement('link'); css.rel = 'stylesheet'; css.type = 'text/css'; css.href = 'https://fast.cometondemand.net/'+chat_appid+'x_xchat.css';
    document.getElementsByTagName("head")[0].appendChild(css);
    var js = document.createElement('script'); js.type = 'text/javascript'; js.src = 'https://fast.cometondemand.net/'+chat_appid+'x_xchat.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(js, s);
  })();
</script>

</body>
</html>
<!DOCTYPE html>
<html>
<head>
  <title>CometChat Test</title>
</head>
<body>


<script type="text/javascript">

  var chat_appid = 'XXXXX';
  var chat_id = 'SUPERHERO2';

  (function() {
    var css = document.createElement('link'); css.rel = 'stylesheet'; css.type = 'text/css'; css.href = 'https://fast.cometondemand.net/'+chat_appid+'x_xchat.css';
    document.getElementsByTagName("head")[0].appendChild(css);
    var js = document.createElement('script'); js.type = 'text/javascript'; js.src = 'https://fast.cometondemand.net/'+chat_appid+'x_xchat.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(js, s);
  })();
</script>

</body>
</html>

Be sure to replace chat_appid with your App ID from the CometChat Admin Panel -> Settings -> API Key.

Save both the files and then access them using two different browsers like Firefox and Chrome. You will be able to see CometChat at the bottom right corner of your site page.

Integrating CometChat with an existing website

Now, you're ready to add CometChat to your site.

Before you add the CometChat code, you need to know the code that you can use to output (e.g. echo $_SESSION['name']) the logged in user's unique ID and name.

Once you have this information handy, add the following code to your site template-

<script type="text/javascript">

  var chat_appid = 'XXXXX';
  var chat_id = '1';
  var chat_name = 'John Doe';

  (function() {
    var css = document.createElement('link'); css.rel = 'stylesheet'; css.type = 'text/css'; css.href = 'https://fast.cometondemand.net/'+chat_appid+'x_xchat.css';
    document.getElementsByTagName("head")[0].appendChild(css);
    var js = document.createElement('script'); js.type = 'text/javascript'; js.src = 'https://fast.cometondemand.net/'+chat_appid+'x_xchat.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(js, s);
  })();
</script>

Once you've done this, CometChat will log you in and allow you to chat with other online users.

Below is the list of optional parameters of CometChat

  • chat_link
    This variable is used to set the user profile page URL in CometChat. Once you set this variable user can easily redirect to the other user’s profile page.

Example :
var chat_link = ‘https://www.xyz.com/user/2/profile’;

  • chat_avatar
    This variable is used to set the user profile image URL in CometChat. You have to pass the profile image URL to the chat_avatar variable.

Example:
var chat_avatar = ‘https://www.xyz.com/user/2/profile/profile.png’;

  • chat_friends
    This variable is used to set the friends of the logged-in user in CometChat. You have to pass the list of friends ids in a comma-separated format.

Example:
var chat_friends = ‘23,2548,458,300’;

  • chat_language
    This variable is used to set the language of your chat_box. By default the language is English. If you want to translate your chatbox messages in different languages like France, Arabic, Chinese. You have to pass the google translate language code to this variable.

Please note: Before using this variable you have to add the specific language in languages Section in your CometChat Admin Panel.
Go to your CometChat Admin Panel-->Localization-->Languages add the languages from available languages.

Example:
var chat_language = ‘fr’;

  • chat_email
    This variable is used to set the email address of logged in user in CometChat. You have to pass the email ID of a logged-in user to this variable. This variable is available only when the Offline Email Notification feature is enabled.

Example:
var chat_email = ‘xyz@gmail.com’;

Please refer to the below-mentioned example to implement these variables.

<script>
    var chat_appid = 'APP_ID';
    var chat_auth = 'AUTH_KEY';
    var chat_id = 'SUPERHERO1';
    var chat_name = 'Iron Man';
    var chat_avatar = 'https://www.xyz.com/user/12/profile.png';
    var chat_link = 'https://www.xyz.com/user/12/profile/';
    var chat_friends = ‘SUPERHERO2,SUPERHERO3,223,21;
    var chat_language = ‘fr’;
    var chat_email = ‘xyz123@gmail.com’;
</script>

You're ready to explore more

There is a lot more to CometChat!. You can synchronize your users' friends list, restrict features using role based access control, launch a single private chat window, display our Embedded Layout (instead of Docked Layout) and a lot more.


Quick Start


The simplest voice, video and text chat SDK for your website.

Suggested Edits are limited on API Reference Pages

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