# 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.
bool AppDelegate::applicationDidFinishLaunching() {
AIHelpSupport::setOnAIHelpInitializedCallback(AIHelp_onAIHelpInit);
}
void AIHelp_onAIHelpInit() {
// Sync userId info to AIHelp via updateUserInfo API
AIHelpSupport::updateUserInfo(new UserConfigBuilder().setUserId("uid").build());
// Start polling
AIHelpSupport::startUnreadMessageCountPolling(AIHelp_unreadMessageArrived);
}
static void AIHelp_unreadMessageArrived(const int unreadCount) {
// write your code here
}
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.