Skip to content

Commit 992831a

Browse files
committed
Document accessing Beam state in onNotificationReceived handler
1 parent 1202a68 commit 992831a

File tree

1 file changed

+30
-0
lines changed
  • docs/beams/guides/handle-incoming-notifications

1 file changed

+30
-0
lines changed

docs/beams/guides/handle-incoming-notifications/web.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,33 @@ PusherPushNotifications.onNotificationReceived = ({
5858
pushEvent.waitUntil(handleNotification(payload));
5959
};
6060
```
61+
62+
## Accessing Beams state
63+
64+
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.
65+
66+
```js
67+
PusherPushNotifications.onNotificationReceived = async ({
68+
pushEvent,
69+
payload,
70+
handleNotification,
71+
statePromise,
72+
}) => {
73+
const { userId } = await
74+
pushEvent.waitUntil(
75+
// custom notification handling logic
76+
);
77+
};
78+
```
79+
80+
Beam state properties:
81+
82+
| Property | Type | Description |
83+
| --------------------- | ------- | ---------------------------------------------------------------------------------- |
84+
| instanceId | string | Beams instance ID. |
85+
| publishId | string | The ID used to identify the publish request. |
86+
| deviceId | string | The ID used to identify the device. |
87+
| userId | string | The ID of the current User. |
88+
| appInBackground | boolean | Describes if the application was in background when the notification was received. |
89+
| hasDisplayableContent | boolean | Describes if the notification should display a UI element to the user. |
90+
| hasData | boolean | Describes if the payload contains additional data. |

0 commit comments

Comments
 (0)