> For the complete documentation index, see [llms.txt](https://platform-business.gitbook.io/klat/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://platform-business.gitbook.io/klat/javascript/push-notification-fcm.md). Agents can also search and read this documentation through its [MCP server](https://platform-business.gitbook.io/klat/~gitbook/mcp).

# Push Notification (FCM)

### Web Push Notification

현재 브라우저 Web Push Notification 기능을 제공하고 있지 않습니다.

### Enable / Disable Push Notification

사용자가 Push Notification을 받을 지 여부를 설정할 수 있습니다.

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

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

### SPA (Single Page Applications)

#### FCM 토큰 등록

react-native와 같은 hybrid app에서 사용하는 FCM 토큰은 다음과 같이 등록할 수 있습니다:

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

#### FCM RemoteMessage 파싱

FCM remote message를 읽기 위해서는 다음 코드 예제와 같이 추가 처리가 필요합니다.

```javascript
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>}],
		},
	}
	 */	
}

if (['botJoinChannel', 'botLeaveChannel'].includes(notification.type)) {
	console.log(notification.data);
	/*
	{
		type: 'botJoinChannel', // or 'botLeaveChannel'
		data: {
			channel: {<channel object>},
			bots: [{<bot object>}],
		},
	}
	*/
}
```
