Display a notification message in a notification inbox component
PRE-REQUISITES
For the following code examples to work, you will need to add the fliplet-notifications library to your app. To add it follow these steps:
- When in Fliplet Studio’s Edit screen, open the Developer Options from the right hand menu
- With the Developer Options open, click the Libraries button in the top right corner
- In the search field, type in ‘fliplet-notifications’
- Click it to add it to the list
- Click Save
If you’re sending a notification using Fliplet Studio then it will appear in a recipient’s notification inbox component automatically. However, if you’re sending a notification via code you’ll need to add the following code.
First you need to add the Fliplet Notifications API.
JavaScript
var instance = Fliplet.Notifications.init({});
You can then use the ‘instance’ to send a message to the inbox to all users registered to receive them.
JavaScript
instance.insert({
status: 'published',
data: {
title: 'Fliplet notifications',
message: 'Hi Everyone!',
navigate: {
action: 'screen',
page: 12345,
transition: 'fade'
}
}
});
You may also send a notification to specific group of users (or a single user) by specifying their email (the same that is used when they log in to the app):
JavaScript
instance.insert({
status: 'published',
data: {
title: 'Fliplet notifications',
message: 'Hi John!'
},
scope: {
email: {
$in: ["john@example.org", "jane@example.org"]
}
}
});
For more examples and options refer to this article.