NotificationHandler
This object is used to add custom handlers for specific events relating to push notifications.
1import * as TalkRn from '@talkjs/react-native';23const notificationHandler = TalkRn.getNotificationHandler();4notificationHandler.onTokenRefresh((oldToken, newToken) => {5 console.log(oldToken);6 console.log(newToken);7});89notificationHandler.onNotificationPressed((notification) => {10 console.log(notification);11});
Field | Type | Description |
---|---|---|
DeviceToken | Contains information about the currently valid push notification device id |
1onTokenRefresh(handler: TokenRefreshHandler): void;
Specifies a handler that will be called when a new device push notification token has been generated.
Name | Type | Description |
---|---|---|
handler Required | TokenRefreshHandler | The function you want to be called when the push notification token has been refreshed. |
void
1onNotificationPressed(handler: NotificationPressedHandler): void;
Specifies a handler that will be called when the user clicks on a push notification that is currently on display.
Name | Type | Description |
---|---|---|
handler Required | NotificationPressedHandler | The function you want to be called when the user clicks a notification. |
void
1{2 provider: 'apns',3 pushRegistrationId: '03df25c8345d460bcdad7802d2vf6fc1341e97283bf75cc993eb6dca835ea2e2f'4}
Field | Type | Description |
---|---|---|
provider | fcm | apns | Specifies whether the token belongs to Firebase (fcm ) or Apple Push Notification service (apns ). |
pushRegistrationId | string | The push notification device token that has been registered for that device on either Firebase or Apple Push Notification service. |
1type TokenRefreshHandler = (2 oldToken: DeviceToken,3 newToken: DeviceToken4) => void;
Name | Type | Description |
---|---|---|
oldToken | DeviceToken | The previous device token object. |
newToken | DeviceToken | The current device token object. |
void
1{2 id: "128859FC-91AF-4BFC-AB65-ACF817F55E9F",3 title: "Sebastian",4 body: "rklqjtew;",5 data: {6 conversationId: "ff45c61343229e431dca",7 messageId: "msg_5V20MNImL2Np01SlwSBDP3",8 senderId: "4321567890",9 timestamp: 1676040892409,10 }11}
Field | Type | Description |
---|---|---|
id | string | The notification ID. |
isForegroundEvent | boolean | Indicates whether the event occured while the app was in the foreground or background. In iOS, the background event handler is never called. If the app is in the background, it is opened and then the foreground event handler is called. Hence on iOS this is always true |
body (optional) | string | undefined | The text body of the notification. |
title (optional) | string | undefined | The notification title. |
data (optional) | NotificationData | undefined | Extra data providing TalkJS specific information associated with the notification. |
1{2 conversationId: "ff45c61343229e431dca",3 messageId: "msg_5V20MNImL2Np01SlwSBDP3",4 senderId: "4321567890",5 timestamp: 1676040892409,6}
Field | Type | Description |
---|---|---|
senderId | string | The sender's ID. |
conversationId | string | The ID of the conversation where this message was sent. |
messageId | string | The message ID |
timestamp | number | Unix timestamp indicating when the message and subsequently the notification was sent |
1type NotificationPressedHandler = (2 notification: NotificationPressedEvent3) => void;
Name | Type | Description |
---|---|---|
notification | NotificationPressedEvent | An object containing information about the notification the user just clicked. |