Quickstart Guide

To send web push notifications, the client website must be configured to show the popup. The pop-up appears when the customer's 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.

758

Figure 1: Show Notifications

599

Figure 2: Sample Notifications

📘

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 develoepr account
  • A valid iOS developer account
  • An active account on IMIconnect platform
SoftwareIMIconnect JavaScript SDK

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

OSChromeFirefoxSafari
Windows Desktop (Version 7 ,8,10)YesYesNo
Mac OS X 10.11 (EI Captain)YesYesYes
Linux (Fedora 24)YesYesNo
iOS (9.x)NoNoNo
Android (5.x)YesNoNo

Configuration Tasks

Setup FCM for Chrome and Firefox Browsers

To create Google API project, follow these steps:

  1. Go to Google Firebase Console.
  2. Click Add Proejc.
1597

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

Figure 4: Create Project

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

Figure 5: Project Created

  1. On overview page, Click icon text toProject Overview
1082

Figure 6: Add Firebase to web app

  1. The project setting details are displayed, copy the Web API Keyin IMIconnect Web APP setting Page
1380

Figure 6: General setting page

  1. Click on Cloud Messaging.
    While creating 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.
1277

Figure 7: Project Credentials

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

998

Figure 8: User Interface

The snippet contains initialization information to configure the Firebase JavaScript SDK to use Authentication, Cloud Storage and the Realtime Database.
User 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.
982

Figure 9: iOS certificate display

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

Figure 10: 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.

986

Figure 11: 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.
978

Figure 12: 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.
939

Figure 13: 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 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.
661

Figure 14: 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.
982

Figure 15: 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.
983

Figure 16: 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 .
    • Save the certificate as a .p12 file.
1155

Figure 17: 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.
1034

Figure 18: Adding to IMIconnect

  1. Enter the application name and click NEXT.

532

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

Figure 19: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 with 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.
995

Configuration screen for Safari browser

  1. Configure RTM's Transport and Security settings.
FeatureSettings
Real-time messagingTransport 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 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.
791

Figure 20: App download page

  1. Extract the zip file, to a location in 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 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 user clicks on Allow, unique ids are generated and stored in profile manager. The ids generated are:
BrowserIDs
Chromechrome_pushid
Firefoxfirefox_pushid and key
Safarisafari_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 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.

Copyright © 2000 - 2021 IMImobile Limited | All Rights Reserved