Skip to content

Commit

Permalink
Document accessing Beam state in onNotificationReceived handler
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-shuy committed Oct 27, 2022
1 parent 1202a68 commit 9d78ecc
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions docs/beams/guides/handle-incoming-notifications/web.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |

0 comments on commit 9d78ecc

Please sign in to comment.