NotificationHandler
This object is used to add custom handlers for specific events relating to push notifications.
import * as TalkRn from '@talkjs/react-native';const notificationHandler = TalkRn.getNotificationHandler();notificationHandler.onTokenRefresh((oldToken, newToken) => {console.log(oldToken);console.log(newToken);});notificationHandler.onNotificationPressed((notification) => {console.log(notification);});
Field | Type | Description |
---|---|---|
DeviceToken | Contains information about the currently valid push notification device id |
onTokenRefresh(handler: TokenRefreshHandler): void;
Specifies a handler that will be called when a new device push notification token has been generated.
You can call this method multiple times with different handlers. They will each be called when the event occurs.
Name | Type | Description |
---|---|---|
handler Required | TokenRefreshHandler | The function you want to be called when the push notification token has been refreshed. |
void
onNotificationPressed(handler: NotificationPressedHandler): void;
Specifies a handler that will be called when the user clicks on a push notification that is currently on display.
You can call this method multiple times with different handlers. They will each be called when the event occurs.
Name | Type | Description |
---|---|---|
handler Required | NotificationPressedHandler | The function you want to be called when the user clicks a notification. |
void
{provider: 'apns',pushRegistrationId: '03df25c8345d460bcdad7802d2vf6fc1341e97283bf75cc993eb6dca835ea2e2f'}
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. |
type TokenRefreshHandler = (oldToken: DeviceToken,newToken: DeviceToken) => void;
Name | Type | Description |
---|---|---|
oldToken | DeviceToken | The previous device token object. |
newToken | DeviceToken | The current device token object. |
void
{id: "128859FC-91AF-4BFC-AB65-ACF817F55E9F",title: "Sebastian",body: "rklqjtew;",data: {conversationId: "ff45c61343229e431dca",messageId: "msg_5V20MNImL2Np01SlwSBDP3",senderId: "4321567890",timestamp: 1676040892409,}}
Field | Type | Description |
---|---|---|
id | string | The notification ID. |
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. |
{conversationId: "ff45c61343229e431dca",messageId: "msg_5V20MNImL2Np01SlwSBDP3",senderId: "4321567890",timestamp: 1676040892409,}
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 |
type NotificationPressedHandler = (notification: NotificationPressedEvent) => void;
Name | Type | Description |
---|---|---|
notification | NotificationPressedEvent | An object containing information about the notification the user just clicked. |