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

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.

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

Setup APNs for Safari Browser

The following steps will guide you through the process of APNs setup, certificate creation, and configuration.

  1. Go to the Apple Developer Portal.
  2. Proceed to Certificates, Identifiers & Profiles. The screen will display all the certificates configured for your applications.

Certificates are configured within the Certificates section.

  1. Click the + button to add a new certificate. A screen is displayed to select a certificate for your environment.
iOS certificate display

iOS certificate display

  1. Select the Apple Push Notification service SSL (Production) option.
SSLProduction setting

SSLProduction setting

  1. Select your App ID from the drop-down list.

If an App ID is not available, a new App ID must be created.

App ID

App ID

  1. Click Continue.

Create Certificate Signing Request (CSR)


  1. Follow the on-screen instructions to create a Certificate Signing Request, Generate, and Approval.
  2. Click Continue.
Certificate  Signing Request

Certificate Signing Request

Follow the below steps if you need further assistance in Certificate Signing Request, Generate, and Approval explained in the above screen.

Launch Keychain Access

  1. To launch Keychain Access from an Apple Mac:
    a. Open spotlight: cmd + space key.
    b. Type Keychain Access. The Keychain Access screen is displayed.
  2. Select Request a Certificate from a Certificate Authority option.
Request certificate

Request certificate

The Certificate Assistant will appear to help you create the request.

Create Certificate

Within the Certificate Assistant complete the following steps:

  1. Enter the following details for your certificate:
    a. User Email Address: Enter an email address that matches with the Apple developer account ID.
    b. Common Name: A name for your certificate.

Do not enter CA Email.

  1. Select Request is: -> Saved to disk option.
Create certificate

Create certificate

  1. Click Continue to save the certificate on to your Mac.

Submit Request

To submit a Certificate Signing request, return to the Apple Developer Portal.

  1. Click Choose File and select the certificate file that was created in the previous step.
Generate certificate

Generate certificate

  1. Click Generate.

The Apple Push Notification service SSL certificate is generated.

Download Certificate


Once the APNs SSL certificate has been generated it is ready to be downloaded.

  1. Click Download to download the certificate.
Certificate created

Certificate created

Add Certificate to Keychain

  1. Open the certificate to install it to your Keychain.
  2. Within Keychain Access:
    • Select the login keychain and the category as My Certificates.
    • Locate and select the certificate.
    • Right-click and select Export <your certificate>.
    • Save the certificate as a .p12 file.
Adding certificate to Keychain

Adding certificate to Keychain

  1. A password screen appears. Click OK. The certificate must be saved without a password.

When the certificate is created, it is used in IMIconnect to configure push notification service.

Add Web Application in IMIconnect

To add a web application in IMIconnect, follow these steps:

  1. From the IMIconnect menu, click Apps. The Application screen appears.
  2. Click CONFIGURE APPS > MOBILE / WEB.
Adding to IMIconnect

Adding to IMIconnect

  1. Enter the application name and click NEXT.
  1. Select the Web platform and click NEXT. Based on the selected platform, supported browsers screen appears.
  2. Select browser and click NEXT. The app configuration screen appears.
  3. Select Push Messaging or Real-Time Messaging channel.
  4. Enter the following fields to configure Chrome and Firefox browsers:
    a. Site Name: Enter the URL of the website to configure Web Push notification.
    b. API Key: Enter the API key generated in the section Setup FCM for Chrome and Firefox Browsers.
    c. Project number: Enter the project number generated in the section Setup FCM for Chrome and Firefox Browsers .
    d. Notification Icon: Enter the path of the notification icon. The size of the icon should be 80x80.
    e. Click Save.
Configuration screen for Chrome and Firefox browsers

Configuration screen for Chrome and Firefox browsers

  1. Enter the following fields to configure Safari browser:
    a. Site Name: The name that is entered is displayed on the notification.
    b. Site URL: The URL that is used to validate the identity of the website requesting push notifications using your ID. Only the website that matches the URL can use your IMIconnect ID for push notifications.
    c. APNs keys: Click the button to upload the .p12 file that is generated in the section Setup APNs for Safari Browser.
    d. Password: Enter the password that is set while generating the certificate in the section Setup APNs for Safari Browser. Leave this field blank if the certificate was generated without a password.
    e. Notification Icon: It is mandatory to upload all five icons. Click the respective buttons to upload the icons.
    f. Click Save.
Configuration screen for Safari browser

Configuration screen for Safari browser

  1. Configure RTM's Transport and Security settings.
Feature
Settings

Real-time messaging

Transport protocols
Two transport protocols are available for establishing RTM connection with IMIconnect. They are Web Socket and MQTT. You can configure them as primary and secondary. In case the connection is not established on the primary protocol, it will fall back to secondary protocol.
Security settings
Enable secured ports to establish RTM connection on the secured port for MQTT and WebSocket as an extra layer of security.
Enable RTM payload encryption to encrypt the RTM payload in transit.

  1. Click Save.

A confirmation message appears when the application is created successfully.

Download and Integrate JavaScript SDK

  1. When the web app is added successfully, you can notice a DOWNLOAD link under Web configuration section. Click the link to download the JavaScript SDK.
App download page

App download page

  1. Extract the zip file, to a location on your local computer. You will notice js, manifest folders and sw.js file.
  2. Copy sw.js file, js, and manifest folder to the root folder of your web application.
  3. Copy the below code and paste it in the header or body of your default web page. Replace appId with your actual value.

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.

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.