imiconnect Developer Hub

Welcome to the imiconnect developer hub. You'll find all the resources to help you get started with imiconnect quickly. We are here to support you if you get stuck. Let's jump right in!

Get Started    API Reference

JavaScript SDK Quickstart Guide

To send web push notifications, the client website must be configured to show the popup. The pop-up appears when the customers navigate to the website. When the customers accept to receive web push notifications, a service worker is created in the browser's background. The service worker constantly listens to the push messaging server and shows the notification even when the website is closed.

Sample Notifications

Sample Notifications

Private Browsing Mode

Web push notifications are not supported in private browsing mode.

Option to download SDK initialization config file from web app asset configuration page

The JavaScript SDK will have a single file containing all configurations required to initialize the SDK.

Prerequisites

The minimum requirements to use imiconnect 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 imiconnect platform

Software

imiconnect JavaScript SDK

Web push notifications are supported on the following OS and browsers:

OS
Chrome
Firefox
Safari

Windows Desktop (Version 7 ,8,10)

Yes

Yes

No

Mac OS X 10.11 (EI Captain)

Yes

Yes

Yes

Linux (Fedora 24)

Yes

Yes

No

iOS (9.x)

No

No

No

Android (5.x)

Yes

No

No

Configuration Tasks

Setup FCM for Chrome and Firefox Browsers

To create a Google API project, follow these steps:

  1. Go to Google Firebase Console.
  2. Click Add Project.
Figure 3: Welcome to Firebase

Figure 3: Welcome to Firebase

  1. Add the following in the screen that appears:
    • Project name: Enter a name for your project.
    • Country/region: Select the country name.
    • Select the Default setting and Terms and conditions check-box
  2. Click Create Project to continue.
Create Project

Create Project

  • The console will create a project with the given details.
  • Click Continue to proceed.
Project Created

Project Created

  1. On the overview page, Click icon text toProject Overview
Add Firebase to web app

Add Firebase to web app

  1. The project setting details are displayed, copy the Web API Keyin imiconnect Web APP setting Page
General setting page

General setting page

  1. Click on Cloud Messaging.
    While creating a chrome/Firefox app, you can enter either the Legacy server key or the Server Key in the API Key and Sender ID for Project number.
Project Credentials

Project Credentials

The API Key can either be the Legacy server key or the Server Key.

User Interface

User Interface

The snippet contains initialization information to configure the Firebase JavaScript SDK to use Authentication, Cloud Storage and the Realtime Database.
Users can take the apikey and messagingSenderId to create a web push chrome application.

Add Web Application in imiconnect

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

Note:

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

Web Push Popup

For example, to show the web push popup on loading the index.html page, copy the below code and paste it in header or body of your index.html page. Replace the appId with the id that is generated in imiconnect for the web application.

<script src="../js/jquery.min.js"></script>
<script src="//www.gstatic.com/firebasejs/4.6.2/firebase-app.js"></script>
<script src="//www.gstatic.com/firebasejs/4.6.2/firebase-messaging.js"></script>
<script src="../js/mqttws31.js"></script>
<script src="../js/IMIClient.js"></script>
<script>
    try {
        var config = new IMI.ICConfig(appId, clientKey);
        IMI.IMIconnect.startup(config);

        if (!IMI.IMIconnect.isRegistered()) {
            var callback = {
                onSuccess: function() {
                    console.log("reg success");
                    //logic to subscribe to topics or publish messages
                },
                onFailure: function(errormsg) {
                    console.log("reg failed");
                }

            };
            var deviceProfile=new IMI.ICDeviceProfile(deviceId, userId);  
           //here user id is  optional (If user id not there user can call deviceID,  
             userId will be generated by IMIConnect and passed to callback function)//
          //var  deviceProfile = new IMI.ICDeviceProfile(deviceId);//
          IMI.IMIconnect.register(deviceProfile, callback);
        }
    } catch (err) {
        console.log(err);
    }
</script>
<script src="../js/jquery.min.js"></script>
<script src="../js/mqttws31.js"></script>
<script src="../js/IMIClient.js"></script>
<script>
    try {
        var config = new IMI.ICConfig(appId, clientKey);
        IMI.imiconnect.startup(config);

        if (!IMI.imiconnect.isRegistered()) {
            var callback = {
                onSuccess: function() {
                    console.log("reg success");
                    //logic to subscribe to topics or publish messages
                },
                onFailure: function(errormsg) {
                    console.log("reg failed");
                }

            };
            var deviceProfile=new IMI.ICDeviceProfile(deviceId, userId);  
           //here user id is  optional (If user id not there user can call deviceID,  
             userId will be generated by IMIConnect and passed to callback function)//
          //var  deviceProfile = new IMI.ICDeviceProfile(deviceId);//
          IMI.imiconnect.register(deviceProfile, callback);
        }
    } catch (err) {
        console.log(err);
    }
</script>

Now the web push configuration is complete to display a popup when the default web page is loaded.

  1. When the web page is loaded a popup appears. When a user clicks on Allow, unique ids are generated and stored in the profile manager. The ids generated are:
Browser
IDs

Chrome

chrome_pushid

Firefox

firefox_pushid and key

Safari

safari_pushid

  1. To send messages without a customerid, you must use browser-specific pushids.

Sending Push Messages to Customers

You can send push messages to customers in many methods. Below is one of them:

  1. When the customers click Allow button, the push details are stored in the profile manager.
  2. Get the profiles based on appid using getAppProfile API. You will get all the browser-specific push ids.
  3. Use Messaging API, to send push messages to the push ids.

Sending In-app Messages to Customers

Prerequisites

  1. Follow steps from here to download JS SDK specific to your App.
  2. Ensure your app asset in IMIClient.js
  3. Ensure manifest<your_app_id>.json is present in /manifest
  4. In Chrome Inspect, verify on console that plugin is available by typing:
    IMI

Code Integration

Here is a summary of the process required to implement RT. Following these steps is JavaScript code for each step.

  1. Startup Plugin with Asset Details
  2. Check if user is already registered.
  3. Register User
  4. Connect for RTM
  5. Register messageListener
  6. Send message using publishMessage

Code Examples

  1. Startup Plugin:
    a. Default setup:
 var appId = "#####";
    var appSecret = "#####";
    var config = new IMI.ICConfig(appId, appSecret);
    IMI.IMIconnect.startup(config);

b. Specify pathConfig:
If the website is hosted within a sub-folder, use pathConfig parameter to specify folders:
assets: folder where all JS SDK files are located including ‘manifest’ folder. By default, this is derived as:
window.location.origin + '/assets';
root: folder where sw.js file is located
Important! sw.js file should always be in website root for Push notifications to work properly.

//Within 'your-app-folder'
var pathConfig = {
 "assets": "/your-app-folder/assets/",
 "root": "/your-app-folder/"
}
 
//Default pathConfig
var pathConfig = {
 "assets": "",
 "root": ""
}
var config = new IMI.ICConfig(appId, appSecret, pathConfig);

Provide contextPath only if using any other folder that ‘assets’. By default, contextPath is:

window.location.origin + '/assets';

To provide contextPath:

var config = new IMI.ICConfig(appId, appSecret, contextPath);

  1. Check if user is already registered.
var isRegistered = IMI.IMIconnect.isRegistered();
  1. To register user, call:
function register() {
var deviceID = IMI.ICDeviceProfile.getDefaultDeviceId();
   var deviceProfile = new IMI.ICDeviceProfile(deviceID,userId);
    IMI.IMIconnect.register(deviceProfile, registerCallback);
    }
  }
registerCallback = {
    onSuccess: (msg) => {
      console.log('registerCallback onSuccess');
    },
    onFailure: (err) => {
      err = err || {};
      console.log(err);
    }
  };
  1. Connect for In-app messages.
var messaging = IMI.ICMessaging.getInstance();
    if (!messaging.isConnected())
        messaging.connect();
  1. Register messageListener.
var messaging = IMI.ICMessaging.getInstance();
    messaging.setICMessagingReceiver(msgCallBack);

msgCallBack = {
    onConnectionStatusChanged: (statuscode) => {
      console.log('onConnectionStatusChanged to', statuscode);
    },
    onMessageReceived: (message) => {
      console.log('onMessageReceived ', message);
      this.addReceivedMessage(message);//perform action ex: update UI.
    }
  };

In this particular SDK, even republished messages are received from messageListener.

  1. Send message using publishMessage.
publishMessage = function(thread, msg, mediaIds, callback) {
    var messaging = IMI.ICMessaging.getInstance();
    var message = new IMI.ICMessage();
    message.setMessage(msg);
    message.setThread(thread);
    if (mediaIds && mediaIds.length > 0) {
        var mediaArray = [];
        mediaIds.map(m => {
            var icAttach = new IMI.ICAttachment();
            icAttach.setMediaId(m);
            mediaArray.push(icAttach);
        })
        message.setAttachments(mediaArray);
    }
    messaging.publishMessage(message, callback);
}

Parameters:

Parameter
Type

thread

ICThread

msg

String

mediaIds

Array

Updated 3 months ago

JavaScript SDK Quickstart Guide


Suggested Edits are limited on API Reference Pages

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