From a98688e11d60c32be2f7a56731ca280e02bce1ac Mon Sep 17 00:00:00 2001 From: Esme Ling Date: Wed, 30 Oct 2024 14:43:44 -0700 Subject: [PATCH 1/3] Handle UPDATE_ASSOCIATIONS_FAILED message --- demos/demo-react-ts/src/hooks/useCti.ts | 9 ++++++--- src/Constants.js | 2 ++ src/typedefs.js | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/demos/demo-react-ts/src/hooks/useCti.ts b/demos/demo-react-ts/src/hooks/useCti.ts index 4e5f678..28b4eb5 100644 --- a/demos/demo-react-ts/src/hooks/useCti.ts +++ b/demos/demo-react-ts/src/hooks/useCti.ts @@ -158,7 +158,7 @@ class CallingExtensionsWrapper implements CallingExtensionsContract { } export const useCti = ( - initializeCallingStateForExistingCall: (incomingNumber: string) => void, + initializeCallingStateForExistingCall: (incomingNumber: string) => void ) => { const [phoneNumber, setPhoneNumber] = useState(""); const [engagementId, setEngagementId] = useState(null); @@ -187,7 +187,7 @@ export const useCti = ( const incomingNumber = window.localStorage.getItem(INCOMING_NUMBER_KEY); const incomingContactName = window.localStorage.getItem( - INCOMING_CONTACT_NAME_KEY, + INCOMING_CONTACT_NAME_KEY ); if (engagementId && incomingNumber && incomingContactName) { setEngagementId(engagementId); @@ -244,7 +244,7 @@ export const useCti = ( // save info in localstorage so that it can retrieved on redirect window.localStorage.setItem( INCOMING_NUMBER_KEY, - cti.incomingNumber, + cti.incomingNumber ); window.localStorage.setItem(INCOMING_CONTACT_NAME_KEY, name); cti.navigateToRecord({ @@ -287,6 +287,9 @@ export const useCti = ( onSetWidgetUrlFailed: (data: any, _rawEvent: any) => { /** HubSpot was unable to change the widget iframe src URL. */ }, + onUpdateAssociationsFailed: (data: any, _rawEvent: any) => { + /** HubSpot was unable to update associations for the desired record page. */ + }, }, }); }, []); diff --git a/src/Constants.js b/src/Constants.js index 50aed9b..14b3aac 100644 --- a/src/Constants.js +++ b/src/Constants.js @@ -38,6 +38,7 @@ const hostToThirdPartyEvents = { INITIATE_CALL_ID_FAILED: "INITIATE_CALL_ID_FAILED", INITIATE_CALL_ID_SUCCEEDED: "INITIATE_CALL_ID_SUCCEEDED", NAVIGATE_TO_RECORD_FAILED: "NAVIGATE_TO_RECORD_FAILED", + UPDATE_ASSOCIATIONS_FAILED: "UPDATE_ASSOCIATIONS_FAILED", PUBLISH_TO_CHANNEL_FAILED: "PUBLISH_TO_CHANNEL_FAILED", PUBLISH_TO_CHANNEL_SUCCEEDED: "PUBLISH_TO_CHANNEL_SUCCEEDED", SET_WIDGET_URL_FAILED: "SET_WIDGET_URL_FAILED", @@ -74,6 +75,7 @@ export const messageHandlerNames = { [messageType.INITIATE_CALL_ID_FAILED]: "onInitiateCallIdFailed", [messageType.INITIATE_CALL_ID_SUCCEEDED]: "onInitiateCallIdSucceeded", [messageType.NAVIGATE_TO_RECORD_FAILED]: "onNavigateToRecordFailed", + [messageType.UPDATE_ASSOCIATIONS_FAILED]: "onUpdateAssociationsFailed", [messageType.PUBLISH_TO_CHANNEL_FAILED]: "onPublishToChannelFailed", [messageType.PUBLISH_TO_CHANNEL_SUCCEEDED]: "onPublishToChannelSucceeded", [messageType.READY]: "onReady", diff --git a/src/typedefs.js b/src/typedefs.js index 388d0a5..2e609f9 100644 --- a/src/typedefs.js +++ b/src/typedefs.js @@ -16,6 +16,7 @@ * @property {function} onInitiateCallIdFailed - Called when initiating a call ID fails. * @property {function} onInitiateCallIdSucceeded - Called when initiating a call ID succeeds. * @property {function} onNavigateToRecordFailed - Called when navigating to a record fails. + * @property {function} onUpdateAssociationsFailed - Called when updating associations for a record fails. * @property {function} onPublishToChannelFailed - Called when publishing to a channel fails. * @property {function} onPublishToChannelSucceeded - Called when publishing to a channel succeeds. * @property {function} onReady - Called when HubSpot is ready to receive messages. From baaa8ba173faccf703f4fa76ca316eea102d20f1 Mon Sep 17 00:00:00 2001 From: Esme Ling Date: Thu, 31 Oct 2024 20:34:57 -0700 Subject: [PATCH 2/3] Catch all failed events --- src/CallingExtensions.js | 9 ++++++++- src/Constants.js | 2 ++ src/typedefs.js | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/CallingExtensions.js b/src/CallingExtensions.js index c314ecc..ec74549 100644 --- a/src/CallingExtensions.js +++ b/src/CallingExtensions.js @@ -213,11 +213,18 @@ class CallingExtensions { const { eventHandlers } = this.options; let handler; - if (type in messageHandlerNames) { + + const isFailedEvent = String(type).endsWith("_FAILED"); + + if (type in messageHandlerNames || isFailedEvent) { const name = messageHandlerNames[type]; if (name in eventHandlers) { handler = eventHandlers[name]; } + + if (isFailedEvent) { + handler = eventHandlers[messageType.FAILED]; + } } else { // Send back a message indicating an unknown event is received this.sendMessage({ diff --git a/src/Constants.js b/src/Constants.js index 14b3aac..aad2b53 100644 --- a/src/Constants.js +++ b/src/Constants.js @@ -59,6 +59,7 @@ export const messageType = { SYNC_ACK: "SYNC_ACK", SYNC: "SYNC", UNLOADING: "UNLOADING", + FAILED: "FAILED", }; /** @@ -84,6 +85,7 @@ export const messageHandlerNames = { [messageType.UPDATE_ENGAGEMENT_FAILED]: "onUpdateEngagementFailed", [messageType.UPDATE_ENGAGEMENT_SUCCEEDED]: "onUpdateEngagementSucceeded", [messageType.VISIBILITY_CHANGED]: "onVisibilityChanged", + [messageType.FAILED]: "onFailed", }; export const errorType = { diff --git a/src/typedefs.js b/src/typedefs.js index 2e609f9..7febbcd 100644 --- a/src/typedefs.js +++ b/src/typedefs.js @@ -25,6 +25,7 @@ * @property {function} onUpdateEngagementFailed - Called when updating an engagement fails. * @property {function} onUpdateEngagementSucceeded - Called when updating an engagement succeeds. * @property {function} onVisibilityChanged - Called when the call widget's visibility changes. + * @property {function} onFailed - Called when any of the failed events occurs. * @property {function} [defaultEventHandler] - Default event handler to handle unhandled events. */ From db9cce9544e500d5c4feb99f52c5eead37d537f4 Mon Sep 17 00:00:00 2001 From: Esme Ling Date: Thu, 31 Oct 2024 20:37:24 -0700 Subject: [PATCH 3/3] Add onFailed --- demos/demo-react-ts/src/hooks/useCti.ts | 3 +++ src/CallingExtensions.js | 15 ++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/demos/demo-react-ts/src/hooks/useCti.ts b/demos/demo-react-ts/src/hooks/useCti.ts index 28b4eb5..08a38e0 100644 --- a/demos/demo-react-ts/src/hooks/useCti.ts +++ b/demos/demo-react-ts/src/hooks/useCti.ts @@ -290,6 +290,9 @@ export const useCti = ( onUpdateAssociationsFailed: (data: any, _rawEvent: any) => { /** HubSpot was unable to update associations for the desired record page. */ }, + onFailed: (data: any, _rawEvent: any) => { + /** All failed events from HubSpot */ + }, }, }); }, []); diff --git a/src/CallingExtensions.js b/src/CallingExtensions.js index ec74549..65b1042 100644 --- a/src/CallingExtensions.js +++ b/src/CallingExtensions.js @@ -214,17 +214,11 @@ class CallingExtensions { let handler; - const isFailedEvent = String(type).endsWith("_FAILED"); - - if (type in messageHandlerNames || isFailedEvent) { + if (type in messageHandlerNames) { const name = messageHandlerNames[type]; if (name in eventHandlers) { handler = eventHandlers[name]; } - - if (isFailedEvent) { - handler = eventHandlers[messageType.FAILED]; - } } else { // Send back a message indicating an unknown event is received this.sendMessage({ @@ -238,6 +232,13 @@ class CallingExtensions { }); } + const isFailedEvent = String(type).endsWith("_FAILED"); + + if (isFailedEvent) { + const failedHandler = eventHandlers[messageType.FAILED]; + failedHandler(data, event); + } + handler = handler || eventHandlers.defaultEventHandler; if (handler) { handler(data, event);