From 9d78ecc84332fc29137a8b72600da9814232cc1f Mon Sep 17 00:00:00 2001 From: Daniel Shuy Date: Wed, 5 Oct 2022 19:31:54 +0800 Subject: [PATCH] Document accessing Beam state in onNotificationReceived handler --- .../handle-incoming-notifications/web.md | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/beams/guides/handle-incoming-notifications/web.md b/docs/beams/guides/handle-incoming-notifications/web.md index 19c6c4d..a641a91 100644 --- a/docs/beams/guides/handle-incoming-notifications/web.md +++ b/docs/beams/guides/handle-incoming-notifications/web.md @@ -58,3 +58,33 @@ PusherPushNotifications.onNotificationReceived = ({ pushEvent.waitUntil(handleNotification(payload)); }; ``` + +## Accessing Beams state + +If you would like to access the Beams state, you can subscribe to the `statePromise` promise in your `onNotificationReceived` handler. For example, you can customize the notification based on the current user's role. + +```js +PusherPushNotifications.onNotificationReceived = async ({ + pushEvent, + payload, + handleNotification, + statePromise, +}) => { + const { userId } = await statePromise; + pushEvent.waitUntil( + // custom notification handling logic + ); +}; +``` + +Beam state properties: + +| Property | Type | Description | +| --------------------- | ------- | ---------------------------------------------------------------------------------- | +| instanceId | string | Beams instance ID. | +| publishId | string | The ID used to identify the publish request. | +| deviceId | string | The ID used to identify the device. | +| userId | string | The ID of the current User. | +| appInBackground | boolean | Describes if the application was in background when the notification was received. | +| hasDisplayableContent | boolean | Describes if the notification should display a UI element to the user. | +| hasData | boolean | Describes if the payload contains additional data. |