Push Notification (FCM)

Web Push Notification

Web Push Notification is not supported.

Enable / Disable Push Notification

You can enable or disable user push notification (FCM) by calling the following methods:

// Enable push notification
await client.enablePushNotification();

// Disable push notification
await client.disablePushNotification();

SPA (Single Page Applications)

Registering FCM Token

Registering an FCM token enables you to receive push notifications in hybrid apps (such as React Native):

await client.registerFcmToken({fcmToken: '<YOUR_FCM_TOKEN>'});    

FCM RemoteMessage

You can parse FCM RemoteMessage as follows:

const notification = await client.getNotification(fcmRemoteMessageData);

if (['message', 'messageDeleted'].includes(notification.type)) {
	console.log(notification.data);
	/*
	{
		type: 'message', // or 'messageDeleted'
		data: {
			channel: {<channel object>},
			message: {<message object>},
		},
	}
	 */	
}

if (['channelAdded', 'channelChanged', 'channelRemoved'].includes(notification.type)) {
	console.log(notification.data);
	/*
	{
		type: 'channelAdded', // or 'channelChanged', 'channelRemoved'
		data: {
			channel: {<channel object>},
		},
	}
	 */	
}

if (['memberAdded', 'memberLeft', 'memberMuted', 'memberUnmuted', 'memberBanned', 'memberUnbanned'].includes(notification.type)) {
	console.log(notification.data);
	/*
	{
		type: 'memberAdded', // or 'memberLeft', 'memberMuted', 'memberUnmuted', 'memberBanned', 'memberUnbanned'
		data: {
			channel: {<channel object>},
			users: [{<user object>}],
		},
	}
	 */	
}

Last updated