Skip to main content
Version: 1.3.x

Javascript Core In-App Inbox Library

Javascript Core package wraps the REST API calls into easy to use functions for any Javascript app. With this package, you can build Notification Inbox, Subscribe users to web push, build preference manager etc.


Javascript core library doesn't provide any UI components. If you're looking for UI-Kit for Javascript, you should use our React component or Browser Javascript UI Kit.

Quick Setup

Before we start, make sure you have Engagespot API Key from your dashboard. Now, let's install the core package, and initialize.

npm install @engagespot/core

Initializing the SDK

import Engagespot from '@engagespot/core';

const engagespot = new Engagespot('YOUR_ENGAGESPOT_API_KEY', {
userId: '',

Fetching notifications

const notificationList = engagespot.getNotificationList();
await notificationList.fetch(); => {
console.log(notification.title, notification.message);

To fetch notification list, you should use the getNotificationList() method, which returns the NotificationList object. Note that, the NotificationList object will be empty, and you need to call the fetch() method to pull the latest notification data from server.

We've seen this in the example above. After calling fetch() which returns Promise<this>, you can access the notifications from data[]

Let's learn more about NotificationList class below.

Engagespot Class

This class is used to create a new Engagespot instance.


The constructor accepts the following arguments.

apiKeystringEngagespot API Key
optionsObjectOptions Object. (Properties explained below)
options.userIdstringAny unique identifier to identify your app user
options.userSignaturestringRequired if your app has HMAC Authentication turned on.
options.serviceWorkerRegistrationServiceWorkerRegistrationUse this if your app has an existing Service Worker Registration

Web Push Notification

Core Javascript API also includes methods to enable web push notifications via the default_webpush provider. If you have enabled default_webpush provider in your Engagespot, you can make use of the following methods to work with the web push functionality.

The following methods are available in the Engagespot class.


This function triggers the web push subscription prompt and attaches the subscription with Engagespot. After this, the user can receive web push notifications.


Make sure you have enabled web push for your app in Engagespot dashboard, and the service worker setup is completed. Otherwise, this error will be shown - ES1005 - A service worker must be registered before push can be subscribed

Preference Manager

Using Core Javascript API, you can build a custom notification preference manager for your users. To learn more about how to build a notification preference manager, read this guide.

Event Listeners

Engagespot Core emits several events which you can susbcribe to do custom actions.


import Engagespot from '@engagespot/core';

const engagespot = new Engagespot('YOUR_ENGAGESPOT_API_KEY', {
userId: '',

engagespot.onNotificationReceive(notification => {
//You'll get the notification object.



onNotificationClick() is deprecated. Use onNotificationRead instead.


import Engagespot from '@engagespot/core';

const engagespot = new Engagespot('YOUR_ENGAGESPOT_API_KEY', {
userId: '',

engagespot.onNotificationRead(notification => {
//You'll get the notification object.


import Engagespot from '@engagespot/core';

const engagespot = new Engagespot('YOUR_ENGAGESPOT_API_KEY', {
userId: '',

engagespot.onNotificationDelete(notification => {
//You'll get the notification object.


import Engagespot from '@engagespot/core';

const engagespot = new Engagespot('YOUR_ENGAGESPOT_API_KEY', {
userId: '',

engagespot.onNotificationSee(notification => {
//You'll get the notification object.

NotificationList Class

Notification list is a collection of Notifications. It implements the NotificationItem interface.

export interface NotificationList {
unreadCount: number;
totalCount: number;

data: NotificationItem[];

fetch: (page: number, itemsPerPage: number) => Promise<this>;
markAllAsSeen: () => Promise<this>;


The NotificationList interface has the following properties.


Number of unseen notifications in the list.


Total number of notifications in the list



Fetches the notifications from the server and add them to the data[] property.

NotificationItem Interface

NotificationItem interface represents a single notification entity. It has several properties and methods to do actions on that particular notification.

interface NotificationItem {
id: string;
title: string;
message?: string | null;
icon?: string | null;
url?: string | null;
seenAt?: string | null;
clickedAt?: string | null;
createdAt?: string | null;
data?: T | null;

fetch?: () => Promise<this> // This will mark the notification as seen.
markAsClicked?: () => Promise<this> //@deprecated. Use markAsRead() instead.
markAsRead?: () => Promise<this>
markAsUnSeen?: () => Promise<this>
markAsUnRead? () => Promise<this>
delete? () => Promise<this>


The NotificationItem interface has the following properties.


Id of the notification


Title of the notification


Body of notification. This can be null.


URL of the notification icon. This can be null.


Timestamp of seen event of this notification. This can be null.


Timestamp of click event of this notification. This can be null.


Timestamp of created event of this notification.


The data object passed to the send notifications API.


The NotificationItem interface has the following methods.


Calls GET /notifications/:notificationId API and sets the properties of this class.



markAsClicked() method is deprecated. Use markAsRead() instead


Calls POST /notifications/:notificationId/click API and marks this notification as read.


Calls DELETE /notifications/:notificationId/views API and marks this notification as unseen.


Calls DELETE /notifications/:notificationId/reads API and marks this notification as unread.


Calls DELETE /notifications/:notificationId API and deletes this notification.