Skip to main content

WordPress / BuddyPress

Before getting started

Go through the overview to set up Chat Widget from the CometChat Dashboard

Installation

  1. Download the CometChat Pro plugin
  2. Go to the WordPress Admin section and visit Plugins > Add New
Image
  1. Click on the ‘Upload Plugin’ button, here you need to click on the ‘Choose File’ button and select the plugin zip file. After you have selected the file, you need to click on the ‘Install Now’ button.
Image
  1. WordPress will now upload the plugin file and install it for you.
  2. Once installed, you need to click on the 'Activate Plugin' link to start using the plugin.
Image

Configuration

  1. You can access the App ID, Region, Rest API key and Auth Key from the CometChat Dashboard under Chat Widgets section > Chat Widget App > Under Install tab on the right panel
Image

Visit Settings on WordPress dashboard >> CometChat Pro

  • Add CometChat App ID,
  • Select CometChat Region
  • Add CometChat Rest API Key
  • Add CometChat Auth Key
Image
  1. Once the Update Settings button is clicked, the WordPress login user will automatically be registered as a user in the CometChat dashboard
  2. You have two options to load the chat widget layout of your choice
  • Embedded Layout
  • Docked Layout

Embedded Layout

Image

Use the shortcode to load the Chat Widget in the embedded layout. You need to configure the keys and pass the required values to the keys in the shortcode.

Warning

Replace WIDGET_ID with your Widget ID in the below code.

[cometchat-pro widget-id='WIDGET_ID' widget-height='600px' widget-width='600px' widget-version='v3']

The list below gives the configurable keys and their description

KeysDescription
widget-idThe ID of the widget can be accessed from the CometChat dashboard
widget-widthWidth of the widget
widget-heightHeight of the widget
widget-versionVersion of the Chat Widget

You may pass optional parameters in the short code

Keys (optional)Description
default-usernameThe default user with whom the logged In user can start a conversation
default-idTo show a default user or group in your chat

a.Use UID of a user for one-one conversationsb.Use GUID for group conversations
default-typeEither user or group depending upon the default ID
rounded-cornersBoolean value (true/false) that enables/disables rounded corners

Docked Layout

Image

Use the short code to load the Chat Widget in the docked layout. You need to configure the keys and pass the required values to the keys in the short code.

Warning

Replace WIDGET_ID with your Widget ID in the below code.

[cometchat-pro widget-id='WIDGET_ID' widget-height='600px' widget-width='600px' widget-version='v3' widget-docked='true' widget-docked-position='right' rounded-corners='true']

The list below gives the configurable keys and their description

KeysDescription
widget-idThe ID of the widget can be accessed from the CometChat dashboard
widget-widthWidth of the widget
widget-heightHeight of the widget
widget-versionA version of the Chat Widget
widget-dockedBoolean value to show or hide the docked layout
widget-docked-positionAlignment of the Chat widget to the left or right of the screen

You may pass optional parameters in the short code

Keys (optional)Description
default-usernameThe default user with whom the logged In user can start a conversation
default-idTo show a default user or group in your chat

a.Use UID of a user for one-one conversations b.Use GUID for group conversations
default-typeEither user or group depending upon the default ID
rounded-cornersBoolean value (true/false) that enables/disables rounded corners

Show docked layout on all pages

  1. Visit WordPress Settings and then to CometChat Pro
  2. Copy the above short code and paste under Load CometChat Pro on all pages/sitewide?

If the above steps are followed, you should successfully be able to launch the Chat Widget in your WordPress application

Advanced Features

Open or close chat window

Chat window of docked layout can be opened/closed using the below method. This method can be triggered on the click event of any element of your web page.

CometChatWidget.openOrCloseChat(FLAG); //true or false

It takes the following parameters:

ParameterDescriptionType
FLAGValue could be true or false

true
will open the chat window

false will close the chat window.
Required

Chat with a particular user

This method will open a particular user chat window. This method can be triggered by the click event of any element of your web page.

CometChatWidget.chatWithUser(UID);

It takes the following parameters:

ParameterDescriptionType
UIDThe ID of the user you want to chat withRequired

Chat with a particular group

This method will open a particular group chat window. This method can be triggered by the click event of any element of your web page.

CometChatWidget.chatWithGroup(GUID);

It takes the following parameters:

ParameterDescriptionType
GUIDThe ID of the group you want to chat withRequired

Initiate calls with a particular user

This method will initiate a call with the user. This method can be triggered by the click event of any element of your web page.

CometChatWidget.callUser(UID);

It takes the following parameters:

ParameterDescriptionType
UIDThe ID of the user you want to initiate a call with.Required

Initiate calls with a particular group

This method will initiate a call with the group. This method can be triggered by the click event of any element of your web page.

CometChatWidget.callGroup(GUID);

It takes the following parameters:

ParameterDescriptionType
GUIDThe ID of the group you want to initiate a call withRequired

Message Listener

We have provided a callback that is fired every time a message is received. You can use this to show Custom Notifications on your website or perform some other custom action as per your requirement.

CometChatWidget.on("onMessageReceived", (args) => {
console.log("CometChatWidget onMessageReceived", args);
});

Chat open state listener

We have provided a callback that is fired every time the docked layout of the chat widget is in an open state. You can use this to perform some custom action as per your requirement.

CometChatWidget.launch({
// Embedded or Docked layout configuration
}).then(response => {

// OPTIONAL: This is called in the success callback of launch method
CometChatWidget.on("openChat", (args) => {
console.log("CometChatWidget Chat is open", args);
});
});

Chat closed state listener

We have provided a callback that is fired every time the docked layout of the chat widget is in a closed state. You can use this to perform some custom action as per your requirement.

CometChatWidget.launch({
// Embedded or Docked layout configuration
}).then(response => {

// OPTIONAL: This is called in the success callback of launch method
CometChatWidget.on("closeChat", (args) => {
console.log("CometChatWidget Chat is closed", args);
});
});

Localization

With language localization, our Chat Widget adapts to the language of a specific country or region. Chat Widget allows you to detect the language of your users based on their browser settings and set the language of the widget accordingly. Currently, we support the following 10 languages for localization:

  • English (en, en-US, en-GB)
  • Chinese (zh, zh-TW)
  • Spanish (es)
  • Hindi (hi)
  • Russian (ru)
  • Arabic (ar)
  • Portuguese (pt)
  • Malay (ms)
  • French (fr)
  • German (de)
  • Swedish (sv)
  • Lithuanian (lt)
  • Hungarian (hu)
CometChatWidget.localize(LANGUAGE_CODE); 

It takes the following parameters:

ParameterDescriptionType
LANGUAGE_CODEThe language code the texts to be translated intoRequired