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:
-
When new messages arrive in Intercom conversations, the
IntercomUnreadConversationCountDidChangeNotification
listener should fire with the updated count. -
Intercom.getUnreadConversationCount()
should return the correct number of unread conversations at the time of the call.
Actual Behavior:
-
Intercom.getUnreadConversationCount()
consistently returns0
(ornull
/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 analert(count)
inside the listener, but it never triggers.
Steps I've Taken & Debugging:
-
Polling: I've implemented a polling mechanism that calls
Intercom.getUnreadConversationCount()
every 30 seconds. The value remains0
. -
Event Listener: I've set up the
IntercomUnreadConversationCountDidChangeNotification
listener within auseEffect
hook, ensuring proper cleanup on unmount. -
Console Logs: I've added console logs around the Intercom calls but receive no errors or relevant output.
-
App State: I've tested this both with the app in the foreground and background (though for polling, I'd expect foreground to work).
-
Re-installation: I've tried deleting and reinstalling the app on my test device.
-
Force Quit: Force-quitting and reopening the app doesn't resolve the issue.
-
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!