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:

  1. When in Fliplet Studio’s Edit screen, open the Developer Options from the right hand menu
  2. With the Developer Options open, click the Libraries button in the top right corner
  3. In the search field, type in ‘fliplet-notifications’
  4. Click it to add it to the list
  5. Click Save

It’s possible to trigger a notification to be sent using code. Once you’ve added the ‘fliplet-notifications’ library (see the pre-requisites section) you can send a notification with the following code to all app users (assuming they’ve allowed their app to receive notifications).

var myNotification = Fliplet.Notifications.init();

myNotification.insert({
  type: 'push',
  pushNotification: {
    payload: {
      title: 'My notification',
      body: 'Hi everyone!',
      custom: {
        customData: {
          action: 'screen',
          page: 12345,
          transition: 'fade'
        }
      }
    }
  }
});

The example above sends a notification with the title “My notification” and a message of “Hi everyone!”. It’s also possible to add a link to the notification so that when it’s tapped it opens up a screen within your app. This is done with the customData property. Here we’re sending the user to a screen with the screen ID of ‘12345’.
It’s also possible to schedule a notification to be sent at a future time. You can find more information about this here.

Send a notification to specific recipients

If you don’t want to send the notification to everyone, it’s possible to specify a single recipient or a group of recipients. The code below sends a notification to specific group of users (or a single user) by specifying their emails (the same email that is used when they log in to the app):

// Insert an in-app notification and also send a push notification
instance.insert({
  type: 'push',
  scope: {
    email: {
      $in: ["john@example.org", "jane@example.org"]
    }
  },
  pushNotification: {
    payload: {
      title: 'Fliplet notifications',
      body: 'Hi everyone!'
    }
  }
});
Was this article helpful?
YesNo