NotificationHandler

This object is used to add custom handlers for specific events relating to push notifications.

Example

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);
});

Properties

FieldTypeDescription
deviceToken
DeviceTokenContains information about the currently valid push notification device id

Methods

onTokenRefresh

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.

Parameters

NameTypeDescription
handler RequiredTokenRefreshHandlerThe function you want to be called when the push notification token has been refreshed.

Returns

void

onNotificationPressed

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.

Parameters

NameTypeDescription
handler RequiredNotificationPressedHandlerThe function you want to be called when the user clicks a notification.

Returns

void

Used by


Type Definitions

DeviceToken

Example

{
provider: 'apns',
pushRegistrationId: '03df25c8345d460bcdad7802d2vf6fc1341e97283bf75cc993eb6dca835ea2e2f'
}

Properties

FieldTypeDescription
providerfcm | apnsSpecifies whether the token belongs to Firebase (fcm) or Apple Push Notification service (apns).
pushRegistrationIdstringThe push notification device token that has been registered for that device on either Firebase or Apple Push Notification service.

TokenRefreshHandler

type TokenRefreshHandler = (
oldToken: DeviceToken,
newToken: DeviceToken
) => void;

Parameters

NameTypeDescription
oldTokenDeviceTokenThe previous device token object.
newTokenDeviceTokenThe current device token object.

Returns

void

NotificationPressedEvent

Example

{
id: "128859FC-91AF-4BFC-AB65-ACF817F55E9F",
title: "Sebastian",
body: "rklqjtew;",
data: {
conversationId: "ff45c61343229e431dca",
messageId: "msg_5V20MNImL2Np01SlwSBDP3",
senderId: "4321567890",
timestamp: 1676040892409,
}
}

Properties

FieldTypeDescription
idstringThe notification ID.
body (optional)string | undefinedThe text body of the notification.
title (optional)string | undefinedThe notification title.
data (optional)NotificationData | undefinedExtra data providing TalkJS specific information associated with the notification.

NotificationData

Example

{
conversationId: "ff45c61343229e431dca",
messageId: "msg_5V20MNImL2Np01SlwSBDP3",
senderId: "4321567890",
timestamp: 1676040892409,
}

Properties

FieldTypeDescription
senderIdstringThe sender's ID.
conversationIdstringThe ID of the conversation where this message was sent.
messageIdstringThe message ID
timestampnumberUnix timestamp indicating when the message and subsequently the notification was sent

NotificationPressedHandler

type NotificationPressedHandler = (
notification: NotificationPressedEvent
) => void;

Parameters

NameTypeDescription
notificationNotificationPressedEventAn object containing information about the notification the user just clicked.