# Unread Message Count
When the customer service replies user's message, user can receive a notification of unread messages, even if the AIHelp page is not currently displayed.
You can implement this function either by every-5-minutes' polling or by third-party push.
TIP
This feature is disabled by default, please contact us before your integration.
# By Polling
WARNING
By default, AIHelp uses a randomly generated deviceId as userId to poll for the count of unread messages.
So, until you sync the correct userId to AIHelp, the unread message count may be inaccurate.
# API
# StartUnreadMessageCountPolling()
Call this method to start a polling job for the count of unread messages. Please ensure that you are calling this method after the initialization is finished.
void onAIHelpInit() {
// Sync userId info to AIHelp via updateUserInfo API
FAIHelpForUEModule::Get().GetAIHelp()->UpdateUserInfo(
UserId,
UserName,
ServerId,
UserTags,
CustomDataInJsonFormat,
IsSyncCrmInfo
);
// Start polling
FAIHelpForUEModule::Get().GetAIHelp()->StartUnreadMessageCountPolling(unreadMessageArrived);
}
void unreadMessageArrived(const int unreadCount) {
// write your code here
}
FAIHelpForUEModule::Get().GetAIHelp()->SetOnAIHelpInitializedCallback(onAIHelpInit);
The count of unread messages is pulled every 5 minutes within the function, the result will be returned to the caller in the following conditions:
- When user with ongoing tickets receives a new message, accumulated number of unread messages will be returned;
- When users open AIHelp session, a returning with number 0 indicates they have read all messages.
# Definition
# OnUnreadMessageCountCallback
- Type:
void (*OnMessageCountArrivedCallback)(int unreadCount)
- Detail: Required. Callback for unread message count.