Skip to content

Commit

Permalink
fix: do not send timeout event if waiting for memori response
Browse files Browse the repository at this point in the history
  • Loading branch information
nzambello committed Jul 31, 2023
1 parent d6ddaa0 commit c6ad751
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/components/MemoriWidget/MemoriWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,15 @@ const MemoriWidget = ({
undefined
);

let referral;
try {
referral = (() => {
return window.location.href;
})();
} catch (err) {
console.error(err);
}

fetchSession({
memoriID: memori.engineMemoriID ?? '',
password: secret || memoriPwd || memori.secretToken,
Expand All @@ -885,6 +894,11 @@ const MemoriWidget = ({
initialContextVars,
initialQuestion,
birthDate: birthDate || storageBirthDate || undefined,
additionalInfo: {
...(additionalInfo || {}),
language: getCultureCodeByLanguage(userLang),
referral: referral,
},
});
} else if (!!currentState) {
return {
Expand Down Expand Up @@ -947,6 +961,7 @@ const MemoriWidget = ({
!speechSynthesizer &&
!isPlayingAudio &&
!userMessage.length &&
!memoriTyping &&
!listening
)
setInteractionTimeout();
Expand All @@ -956,6 +971,7 @@ const MemoriWidget = ({
!!speechSynthesizer ||
isPlayingAudio ||
!!userMessage.length ||
memoriTyping ||
listening
) {
resetInteractionTimeout();
Expand Down Expand Up @@ -1016,16 +1032,13 @@ const MemoriWidget = ({
}
}

if (memori.enableCompletions) {
timeout = timeout + 60;
}

let uiTimeout = setTimeout(handleTimeout, timeout * 1000);
setUserInteractionTimeout(uiTimeout);
timeoutRef.current = uiTimeout;
};
useEffect(() => {
if (!!userMessage.length || isPlayingAudio) clearInteractionTimeout();
if (!!userMessage.length || isPlayingAudio || memoriTyping)
clearInteractionTimeout();
if (sessionId && !!!userMessage.length) resetInteractionTimeout();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
Expand All @@ -1036,6 +1049,7 @@ const MemoriWidget = ({
sessionId,
history,
userMessage,
memoriTyping,
]);
useEffect(() => {
return () => {
Expand Down

0 comments on commit c6ad751

Please sign in to comment.