Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle UPDATE_ASSOCIATIONS_FAILED message #240

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions demos/demo-react-ts/src/hooks/useCti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number | null>(null);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -287,6 +287,12 @@ 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. */
},
onFailed: (data: any, _rawEvent: any) => {
/** All failed events from HubSpot */
},
},
});
}, []);
Expand Down
8 changes: 8 additions & 0 deletions src/CallingExtensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class CallingExtensions {
const { eventHandlers } = this.options;

let handler;

if (type in messageHandlerNames) {
const name = messageHandlerNames[type];
if (name in eventHandlers) {
Expand All @@ -231,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);
Expand Down
4 changes: 4 additions & 0 deletions src/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -58,6 +59,7 @@ export const messageType = {
SYNC_ACK: "SYNC_ACK",
SYNC: "SYNC",
UNLOADING: "UNLOADING",
FAILED: "FAILED",
};

/**
Expand All @@ -74,6 +76,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",
Expand All @@ -82,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 = {
Expand Down
2 changes: 2 additions & 0 deletions src/typedefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -24,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.
*/

Expand Down
Loading