Platform publish formats

Each platform supports different options when publishing notifications via the publishToUsers and publishToInterests methods. These are the formats expected by each platform.

FCM format

The full set of options is described by Google in their documentation of FCM downstream HTTP messages

FCM example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
publishToUsers(["SOME_USER"], {
  fcm: {
    notification: {
      title: "You have a new message",
      body: "Hi!"
    },
    data: {
      some: 'metadata',
      of: 'your',
      choosing: 'can',
      go: 'here 😏'
    }
  }
});

APNs format

The full set of options for the APNs section of the notify call is described in Apple's Payload Key Reference. For further examples, see Apple's “Creating the Remote Notification Payload”

APNs example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
publishToUsers(["SOME_USER"], {
  apns: {
    alert: {
      title: "You have a new message",
      body: "Hi!"
    },
    data: {
      some: 'metadata',
      of: 'your',
      choosing: 'can',
      go: 'here 😏'
    }
  }
});

Web format

Pusher Beams offers a bespoke format for sending web notifications that works across all supported browsers.

  • time_to_live (integer|optional): The number of seconds the web push gateway should store the notification for whilst the user is offline. Max: 2419200; Default: 4 weeks.
  • notification (object|optional): See notification object format
  • data (object|optional): Arbritrary object containing any custom metadata you would like to send with the notification. Cannot contain the key "pusher".

notification object format

  • title (string|optional): The title shown when the notification is displayed to the user.
  • body (string|optional): The body shown when the notification is displayed to the user.
  • icon (string|optional): URL of the image shown as the notification icon when the notification is displayed.
  • deep_link (string|optional): If provided, this URL will be opened in a new tab when the notification is clicked.
  • hide_notification_if_site_has_focus (boolean|optional): If set to true, the notification will not be shown if your site has focus. Default: false.

Web example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
publishToUsers(["SOME_USER"], {
  web: {
    time_to_live: 3600,
    notification: {
      title: "You have a new message",
      body: "Hi!",
      icon: "https://example.com/img/notification-icon.png",
      deep_link: "https://example.com/messages?message_id=2342",
      hide_notification_if_site_has_focus: true
    },
    data: {
      some: 'metadata',
      of: 'your',
      choosing: 'can',
      go: 'here 😏'
    }
  }
});