Hello Team,
Freshchat.addEventListener event is calling multiple times.
Below is the code snippet :
useEffect(() => {
Freshchat.addEventListener(Freshchat.EVENT_USER_RESTORE_ID_GENERATED, () => {
Freshchat.getUser((user) => {
const restoreId = user.restoreId;
const externalId = user.externalId;
try {
**callUpdateFCPRofile(externalId, restoreId);**
} catch (e) {
//
}
Freshchat.identifyUser(externalId, restoreId, (error) => {
CommonBugFender('freshchat_event_identifyUser', error, BUSINESS_VERTICAL.NH);
});
});
});
}, [currentPatient?.mobileNumber]);
Here callUpdateFCPRofile(externalId, restoreId); method is calling multiple times due to which API is hitting multiple times. I checked with putting log observed that Freshchat.addEventListener is triggering multiple times when a new user initiating the chat (sending the first message).
Why it is triggering multiple times? it supposed to be triggered only one time.