Skip to content

Commit

Permalink
Help Center: Add error reporting when ZD conversation is not found (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
alshakero authored Jan 20, 2025
1 parent c7fe629 commit 714e91c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/odie-client/src/data/use-get-zendesk-conversation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback } from 'react';
import Smooch from 'smooch';
import { useOdieAssistantContext } from '../context';
import { zendeskMessageConverter } from '../utils';
import { useGetUnreadConversations } from './use-get-unread-conversations';
import type { ZendeskMessage } from '../types';
Expand All @@ -22,6 +23,7 @@ const parseResponse = ( conversation: Conversation ) => {
*/
export const useGetZendeskConversation = () => {
const getUnreadNotifications = useGetUnreadConversations();
const { trackEvent } = useOdieAssistantContext();

return useCallback(
( {
Expand All @@ -35,7 +37,9 @@ export const useGetZendeskConversation = () => {
return null;
}

const conversation = Smooch.getConversations().find( ( conversation ) => {
const conversations = Smooch.getConversations();

const conversation = conversations.find( ( conversation ) => {
if ( conversationId ) {
return conversation.id === conversationId;
}
Expand All @@ -44,6 +48,14 @@ export const useGetZendeskConversation = () => {
} );

if ( ! conversation ) {
// Conversation id was passed but the conversion was not found. Something went wrong.
if ( conversationId ) {
trackEvent( 'zendesk_conversation_not_found', {
conversationId,
chatId,
conversationsCount: conversations?.length ?? null,
} );
}
return null;
}

Expand All @@ -56,6 +68,6 @@ export const useGetZendeskConversation = () => {
} )
.catch( () => parseResponse( conversation ) );
},
[ getUnreadNotifications ]
[ getUnreadNotifications, trackEvent ]
);
};

0 comments on commit 714e91c

Please sign in to comment.