Intercom React Native Unread Count Issues: getUnreadConversationCount and Listener Not Updating | Community
Skip to main content

Hello Intercom Community,

I'm encountering a persistent issue with retrieving and listening for unread conversation counts in my React Native application using the Intercom SDK. Neither Intercom.getUnreadConversationCount() nor the IntercomUnreadConversationCountDidChangeNotification event listener seems to be working as expected.

Goal: My objective is to display the current unread message count from Intercom within my app's UI (outside of the Intercom messenger itself).

Expected Behavior:

  1. When new messages arrive in Intercom conversations, the IntercomUnreadConversationCountDidChangeNotification listener should fire with the updated count.

  2. Intercom.getUnreadConversationCount() should return the correct number of unread conversations at the time of the call.

Actual Behavior:

  • Intercom.getUnreadConversationCount() consistently returns 0 (or null/undefined, please specify) even when there are clearly unread messages visible when I manually open the Intercom messenger.

  • The Intercom.addEventListener('IntercomUnreadConversationCountDidChangeNotification', ...) callback never seems to fire, even after new messages are received and conversations are marked unread. I've added an alert(count) inside the listener, but it never triggers.

Steps I've Taken & Debugging:

  1. Polling: I've implemented a polling mechanism that calls Intercom.getUnreadConversationCount() every 30 seconds. The value remains 0.

  2. Event Listener: I've set up the IntercomUnreadConversationCountDidChangeNotification listener within a useEffect hook, ensuring proper cleanup on unmount.

  3. Console Logs: I've added console logs around the Intercom calls but receive no errors or relevant output.

  4. App State: I've tested this both with the app in the foreground and background (though for polling, I'd expect foreground to work).

  5. Re-installation: I've tried deleting and reinstalling the app on my test device.

  6. Force Quit: Force-quitting and reopening the app doesn't resolve the issue.

  7. Intercom Messenger: When I open the Intercom messenger within my app, the unread count inside the messenger itself updates correctly.
     

This is my sample code what I doing to get the results

 

// Example of my polling attempt
import { useState, useEffect } from 'react';
import Intercom from '@intercom/intercom-react-native'; // Adjust import path if needed

function MyComponent() {
const tunreadCount, setUnreadCount] = useState(0);

useEffect(() => {
const fetchCount = async () => {
try {
const count = await Intercom.getUnreadConversationCount();
console.log('Fetched Intercom unread count:', count);
setUnreadCount(count);
} catch (error) {
console.error('Error fetching Intercom unread count:', error);
}
};

// Initial fetch
fetchCount();

// Polling every 60 seconds
const intervalId = setInterval(fetchCount, 60000);

return () => clearInterval(intervalId);
}, ,]);

// Event Listener attempt
useEffect(() => {
const listener = Intercom.addEventListener('IntercomUnreadConversationCountDidChangeNotification', ({count}) => {
console.log('Intercom unread conversation count changed via listener:', count);
alert(`Listener fired! Count: ${count}`); // Using alert for quick debugging
setUnreadCount(count); // If this was meant to update state
});

return () => {
listener.remove();
};
}, ,]);

return (
// ... JSX using unreadCount ...
<Text>Unread Messages: {unreadCount}</Text>
);
}

Any guidance or suggestions would be greatly appreciated. Thank you!

Hi ​@Prakhar Jain ! Ebenezer here from Engineering Support👋.

The most common causes for your issue are missing user registration, Messenger not enabled, push notifications not configured, or using an outdated SDK version. Upgrading to the latest SDK, ensuring user registration, enabling Messenger, and setting up push notifications should resolve the problem in most cases. If you are using Expo, version 8.5.0 or later is required for event listeners to work correctly.

Let me know if any of these work


Reply