Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document accessing Beam state in onNotificationReceived handler #218

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. |