Skip to main content

Push Notifications

buildfire.notifications.pushNotification#

This is a built-in API that allows your control or widget to schedule push notifications to be sent out to devices. If you wish to schedule a Notification to be sent to the device you are currently on use Local Notifications.

Running Example: https://github.com/BuildFire/simpleBuildFireJSExamples/blob/master/examplePushNotifications/widget/index.html

Requirements#

Widget#

Include pushNotifications.js file in widget header right after the buildfire.min.js

<head>
<!-- ... -->
<script src="../../../scripts/buildfire/buildfire.min.js"></script>
<script src="../../../scripts/buildfire/services/notifications/pushNotifications.js"></script>
</head>

Control#

Include pushNotifications.js file in control header right after the buildfire.min.js

<head>
<!-- ... -->
<script src="../../../../scripts/buildfire/buildfire.min.js"></script>
<script src="../../../../scripts/buildfire/services/notifications/pushNotifications.js"></script>
</head>

Methods#

schedule()
#

buildfire.notifications.pushNotification.schedule(options, callback)

Used to schedule push notification

buildfire.notifications.pushNotification.schedule(
{
title: "Push notification",
text: "Hello there!",
},
(err, result) => {
if (err) return console.error(err);
console.log("Push notification scheduled", result);
}
);

options#

NameTypeRequiredDescriptionDefault
titlestringyesA short string describing the purpose of the notification
textstringyesPush notification text
inAppMessagestringnoThe HTML text of the message displayed if the push notification is received in app
atDatenoTime to send the push notification atnow
users[string]noArray of userIds to send the push notification to specific users
userTags[string]noArray of user tags to send push notification to users with specific tags
groupNamestringnoSend the push notification to specific group
queryStringstringnoWill be added to the plugin when the push notification triggers the plugin to open
sendToSelfbooleannoIf false, the device scheduling the push notification will not receive ittrue

callback(err, result)#

Callback function after the push notification scheduling is completed.

NameTypeDescription
errstringerror string, null when operation is successfull
resultobjectResult contains notificationId, which is the id of the newly scheduled push notification.

cancel()
#

buildfire.notifications.pushNotification.cancel(notificationId, callback)

Used to cancel a scheduled push notification

buildfire.notifications.pushNotification.cancel(
"608adde30af35105452a3c96",
(err, isCancelled) => {
if (err) return console.error(err);
console.log("Notification cancelled", isCancelled);
}
);

notificationId#

NameTypeRequiredDescriptionDefault
notificationIdstringyesThe id of the notification that you wish to cancel. Can be obtained from schedule result object

callback(err, result)#

NameTypeDescription
errstringerror string, null when operation is successfull
isCancelledbooleanIndicates whether notification was cancelled successfully

subscribe()
#

buildfire.notifications.pushNotification.subscribe(options, callback)

Use to subscribe current user to group. You can use this to create custom push notification groups within the app.

buildfire.notifications.pushNotification.subscribe(
{ groupName: "testGroup" },
(err, subscribed) => {
if (err) return console.error(err);
console.log("User subscribed to group", subscribed);
}
);

options#

NameTypeRequiredDescriptionDefault
groupNamestringyesName of the group to subscribe user to

callback(err, subscribed)#

Callback function when the subscribtion is completed.

NameTypeDescription
errstringerror string, null when operation is successfull
subscribedbooleanIndicated whether user was successfully subscribed to group

unsubscribe()
#

buildfire.notifications.pushNotification.unsubscribe(options, callback)

Use to unsubscribe current user from group.

buildfire.notifications.pushNotification.unsubscribe(
{ groupName: "testGroup" },
(err, unsubscribed) => {
if (err) return console.error(err);
console.log("User unsubscribed from group", unsubscribed);
}
);

options#

NameTypeRequiredDescriptionDefault
groupNamestringyesName of the group to subscribe user to

callback(err, unsubscribed)#

Callback function when the unsubscription is completed.

NameTypeDescription
errstringerror string, null when operation is successfull
unsubscribedbooleanIndicated whether user was successfully unsubscribed from group