Send a notification/alert to users on mobiles (not browsers) at a specified time
It’s possible to schedule a notification to be sent at a specified time. This is best done from Fliplet Studio but it can also be done with code.
Schedule a notification in Fliplet Studio
To schedule a notification in Fliplet Studio you first need to publish your app via the Fliplet Studio’s Publish page and configure push notifications (more details here).
Then on the Publish page in Fliplet Studio take the following steps:
- Select ‘Notification’
- Click ‘New’
- Enter a title and a message
- Optionally add a link (for when the notification is tapped/clicked)
- Click ‘Select recipients’
- Select the type of users you want the Notification to be sent to
- Click ‘Prepare for send’
- Select ‘Later’ under ‘Send notification…’
- Select a date and time
- Click ‘Review’
- Click ‘Schedule Notification’
Schedule a notification using code
We can also schedule a notification using code. In the following example we’re scheduling a notification to go out today at 4:30pm (ie, in the current year, in the current month, on the current day at 16:30). Note that this will be the local time of the user that runs the code (not the recipient if the recipient happened to be in a different timezone).
JavaScript
var now = new Date();
var UTCDate = Date.UTC(now.getFullYear(), now.getMonth(), now.getDate(), 16, 30);
var dateOfEvent = new Date(UTCDate).getTime();
var instance = Fliplet.Notifications.init({});
instance.insert({
type: 'push',
pushNotification: {
payload: {
title: 'Fliplet notifications',
body: 'Hi everyone!',
custom: {
customData: {
action: 'screen',
page: 12345,
transition: 'fade'
}
}
},
delayUntilTimestamp: dateOfEvent
}
});
The message being sent will have:
A title of “Fliplet notifications”
A body message of “Hi everyone!”
A link to a screen with the screen ID of ‘12345’
Please note, the above notification will be sent to all users that have accepted notifications on their devices. If you’d like to send the notification to just one person or a group of people, you can use the following example:
JavaScript
var now = new Date();
var UTCDate = Date.UTC(now.getFullYear(), now.getMonth(), now.getDate(), 16, 30);
var dateOfEvent = new Date(UTCDate).getTime();
var instance = Fliplet.Notifications.init({});
instance.insert({
type: 'push',
pushNotification: {
payload: {
title: 'Fliplet notifications',
body: 'Hi everyone!',
custom: {
customData: {
action: 'screen',
page: 12345,
transition: 'fade'
}
}
},
delayUntilTimestamp: dateOfEvent
},
scope: {
email: {
$in: ["john@example.org", "jane@example.org"]
}
}
});
If you’ve created an app with a Notification Inbox component and you’d also like the notification to appear in the inbox then you can get more information here.