Chatwee JavaScript API

Chatwee JavaScript API is a client-side API which allows you to control the Chatwee app in the runtime.

Introduction

The Chatwee app comes along with its own dedicated framework and a set of classes contained within the ChatweeLib namespace object. To use Chatwee, you have to include the main script in your HTML document.


<script src="https://static.chatwee-api.com/v2/script.js"></script>
	

Notice that the script above is somewhat different from the Chatwee installation script that you can find in your Chatwee Dashboard. The installation script is just a preloader which basically embeds the common Chatwee library into the HTML document and runs a single instance of the chat using its configuration fetched from the backend. Its purpose is to make the chat installation as easy as possible, but there’s nothing that prevents the developer from actually installing and instantiating the chat manually. This becomes possible thanks to JavaScript API and the ChatweeLib.ChatweeManager object.

ChatweeManager

Once the Chatwee script is embedded, the ChatweeLib namespace becomes available in the global namespace. The entire ChatweeLib package is minimized and obfuscated, except for the ChatweeLib.ChatweeManager object, which is used for exposing the internal JavaScript logic, and which has method names that can be read by humans.

ChatweeManager(chatId)

This is a constructor for the ChatweeManager object. It takes one parameter, which is the ID of a chat instance.


  var chatId = "5817d4ba9da1fb0065000029";
  var chatweeManager = new ChatweeLib.ChatweeManager(chatId);
	
Name Description Type Mandatory Remarks
chatId ID of your chat string yes available in 'INTEGRATION' section of the Chatwee Dashboard

ChatweeManager.SetChatProperty(propertyName, propertyValue)

Overwrites any chat property configured in the Chatwee Client Panel customize form. Use this method if you want to display the chat with custom properties (for instance, if you want to show the chat differently on a given subpage of your website).


  var chatId = "5817d4ba9da1fb0065000029";
  var chatweeManager = new ChatweeLib.ChatweeManager(chatId);
  chatweeManager.SetChatProperty("chatweeLayout", "embedded");
  chatweeManager.Run();
	
Name Description Type Mandatory Remarks
propertyName name of the property string yes -
propertyValue the new property value mixed yes -
Name Description Type Remarks
chatweeLabel the chat name displayed in the top left corner of the chat window string -
chatweeIsActive a flag indicating whether the chat should be enabled boolean -
chatweeMobileIsActive a flag indicating wheher the chat should be enabled for mobile devices boolean -
chatweeForceViewport a flag indicating whether to apply the responsive layout for mobile devices boolean -
chatweeLayout defines the display mode for the chat string "embedded" and "fixed" values allowed
chatweeAutoStart whether to start the fixed chat maximized by default boolean valid for chatweeLayout set to "fixed" only
chatweeDefaultPosition default fixed chat window position string "left" and "right" values allowed, valid for chatweeLayout set to "fixed" only
chatweeDefaultWidth default window width for fixed mode number valid for chatweeLayout set to "fixed" only
chatweeDefaultHeight default window height for fixed mode number valid for chatweeLayout set to "fixed" only
chatweeEmbeddedContainerSelector DOM selector for the embedded chat's parent string valid for chatweeLayout set to "embedded" only
chatweeEmbeddedSize sizing mode for the embedded chat string "auto" and "manual" values allowed, valid for chatweeLayout set to "embedded" only
chatweeDefaultEmbeddedWidth fixed window width for the embedded chat number valid for chatweeLayout set to "embedded" only, valid for chatweeEmbeddedSize set to "manual" only
chatweeDefaultEmbeddedHeight fixed window height for the embedded chat number valid for chatweeLayout set to "embedded" only, valid for chatweeEmbeddedSize set to "manual" only
chatweeSound a flag indicating whether to allow sound notifications boolean -
chatweeConversationsEnabled a flag indicating whether to allow private conversations boolean -
chatweeSmiles a flag indicating whether to allow emojis boolean -
chatweeSharing a flag indicating whether to allow file sharing boolean -
chatweeFacebookEnabled a flag indicating whether to allow Facebook login boolean -
chatweeLoginEnabled a flag indicating whether to allow Chatwee login boolean -
chatweeGuestEnabled a flag indicating whether to allow guest users boolean -
chatweeLoggedUsersOnly if set the chat is available for logged users only boolean -
chatweeAutoLogin a flag indicating whether to allow auto-login for the guest users boolean -
chatweeGuestNamesList a list of default guest names used for auto-login feature string comma separated list of values
chatweeProfanityListEnabled a flag indicating whether the profanity censorship is enabled boolean
chatweeStrictProfanity a flag indicating whether to block messages containing profanity boolean
chatweeProfanityList a profanity list string comma separated list of values

ChatweeManager.GetVersion()

Gets the version of the Chatwee script.


  var chatId = "5817d4ba9da1fb0065000029";
  var chatweeManager = new ChatweeLib.ChatweeManager(chatId);
  var chatweeVersion = chatweeManager.GetVersion();
  console.log("current Chatwee version:", chatweeVersion);
	
This method takes no parameters.

ChatweeManager.Run()

Initializes and runs the Chatwee chat app. Call this method whenever you need to run the chat for the user (for instance, when the user logs in to your Single Page Application and the XHR request responsible for logging the user in has terminated).


  var chatId = "5817d4ba9da1fb0065000029";
  var chatweeManager = new ChatweeLib.ChatweeManager(chatId);
  chatweeManager.Run();
	
This method takes no parameters.

ChatweeManager.Dispose()

Removes the chat completely from the DOM. Call this method whenever the chat is no longer needed (for instance, when the user logs out from your Single Page Application).


  var chatId = "5817d4ba9da1fb0065000029";
  var chatweeManager = new ChatweeLib.ChatweeManager(chatId);
  chatweeManager.Dispose();
	
This method takes no parameters.