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()

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.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.