JavaScript SDK Quickstart Guide

Prerequisites

The minimum requirements to use Webex Connect JavaScript SDK are:

Component

Requirement

Apple Push Notification

An APNS certificate, to enable Push Notification services.

Google Push Notification

A FCM certificate, to enable Push Notification services.

Account

  • A valid Google developer account
  • A valid iOS developer account
  • An active account on Webex Connect platform

Configuration Tasks

Add Web Application in Webex Connect

To view how to create Web App Asset for 5.x, visit Web App Asset in Webex Connect

❗️

Note

If you are at a version of Webex Connect which is V4.0, kindly refer to this link to Configure an Webex Connect Web Application.

Download and Integrate JavaScript SDK in your Website

For more information, refer here

Code Integration

Here is a summary of the process required to implement RT.

  1. Include SDK
  2. Startup plugin
  3. Check if user is already registered.
  4. Register User
  5. Connect
  6. Register messageListener
  7. Create a Thread
  8. Send message using publishMessage

Code Sample

  1. Unzip the downloaded SDK and add contents to your project
  2. Import below files in the tag
<script src="assets/js/jquery.min.js"></script>
    <script src="https://www.gstatic.com/firebasejs/4.6.2/firebase-app.js"></script>
    <script src="https://www.gstatic.com/firebasejs/4.6.2/firebase-messaging.js"></script>
    <script type="text/javascript" src="assets/js/mqttws31.js"></script>
    <script type="text/javascript" src="assets/js/aes.js"></script>
    <script type="text/javascript" src="assets/js/imi-environments.js"></script>
    <script type="text/javascript" src="assets/js/IMIClient.js"></script>

📘

Note

Here, sdk is in folder “assets”, please update to project specific location

In Browser Console, verify if the plugin is available by typing IMI. It should output this:

904904

Follow below step to setup In-App Messaging

  1. Call plugin’s startup() method:
IMI.IMIconnect.startup();

📘

Note

Refer Managing Assets for managing multiple assets and paths

  1. Check if user is already registered
IMI.IMIconnect.isRegistered()
  1. Else register user
var userID = 1;
            var deviceID = userID + new Date().getTime(); //any random no.
            var deviceProfile = new IMI.ICDeviceProfile(deviceID, userID);
            var registerCallback = {
                onSuccess: (msg) => {
console.log(msg);
                },
                onFailure: (err) => {
console.log(err);
                },
            };
            IMI.IMIconnect.register(deviceProfile, registerCallback);
  1. Connect
    In registration onSuccess callback, add below code:
var messaging = IMI.ICMessaging.getInstance();
    if (!messaging.isConnected())
        messaging.connect();
  1. Register Listener for in-app messaging
var msgCallBack = {
            onConnectionStatusChanged: (statuscode) => {
                console.log('onConnectionStatusChanged to', statuscode);
            },
            onMessageReceived: (message) => {
                console.log('onMessageReceived ', message);
            }
        };
        var messaging = IMI.ICMessaging.getInstance();
        messaging.setICMessagingReceiver(msgCallBack);
  1. Create a thread
createThread(title) {
        var title = title || "New Conversation";
        var thread = new IMI.ICThread();
        thread.setTitle(title);
        thread.setStatus(IMI.ICThreadStatus.Active);
        thread.setType(IMI.ICThreadType.Conversation);
        var messaging = IMI.ICMessaging.getInstance();
        messaging.createThread(thread, createThreadCallBack);
    }
    createThreadCallBack = {
        onSuccess: (threadObj) => {
        },
        onFailure: (err) => {

        },
    };
  1. Publish a message
var publishMessageCallback = {
  onSuccess: function (msg) {
    console.log("message sent", msg);
  },
  onFailure: function (errormsg) {
    console.log("failed to send message", errormsg);
  },
};
function publish() {
  var text = "Sample message text";
  var message = new IMI.ICMessage();
  message.setMessage(text);
  message.setThread(icThreadObj);
  var messaging = IMI.ICMessaging.getInstance();
  messaging.publishMessage(message, publishMessageCallback);
}