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

Send SDK message to HubSpot if usesCallingWindow=false #266

Merged
merged 4 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 4 additions & 2 deletions demos/demo-react-ts/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ function App() {
cti.broadcastChannel.onmessage = ({
data,
}: MessageEvent<{ type: string; payload?: any }>) => {
// Send SDK message to HubSpot in the calling window
if (cti.isFromWindow) {
// Send SDK message to HubSpot in the calling window or if usesCallingWindow is false
if (
cti.usesCallingWindow ? cti.isFromWindow : cti.isFromRemoteWithoutWindow
) {
// TODO: Refactor to use eventHandler to invoke the appropriate function
// const eventHandler = broadcastEventHandlers[data.type];
// cti.contract[eventHandler](data.payload);
Expand Down
18 changes: 18 additions & 0 deletions demos/demo-react-ts/src/components/screens/LoginScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ function LoginScreen({ cti, handleNextScreen }: ScreenProps) {
target: { value },
}: ChangeEvent<HTMLInputElement>) => setPassword(value);

const handleOpenWindow = () => {
const hostUrl = "https://app.hubspotqa.com/";
esme marked this conversation as resolved.
Show resolved Hide resolved
const url = `${hostUrl}/calling-integration-popup-ui/${cti.portalId}?usesCallingWindow=false`;
window.open(url, "_blank");
};

return (
<Wrapper style={{ color: PANTERA }}>
<form>
Expand Down Expand Up @@ -67,6 +73,18 @@ function LoginScreen({ cti, handleNextScreen }: ScreenProps) {
Sign in with SSO
</LinkButton>
</Row>
<br />
{!cti.usesCallingWindow && (
<Row>
<LinkButton
use="transparent-on-primary"
onClick={handleOpenWindow}
type="button"
>
Open calling window
</LinkButton>
</Row>
)}
</form>
</Wrapper>
);
Expand Down
13 changes: 12 additions & 1 deletion demos/demo-react-ts/src/hooks/useCti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class CallingExtensionsWrapper implements CallingExtensionsContract {

private _usesCallingWindow = true;

portalId = 0;

broadcastChannel: BroadcastChannel = new BroadcastChannel(
"calling-extensions-demo-react-ts"
);
Expand Down Expand Up @@ -100,14 +102,18 @@ class CallingExtensionsWrapper implements CallingExtensionsContract {
this._usesCallingWindow = usesCallingWindow;
}

get isFromRemoteWithoutWindow() {
return !this._usesCallingWindow && this._iframeLocation === "remote";
}

/** Do not send messages to HubSpot in the remote */
get isFromRemote() {
return this._usesCallingWindow && this._iframeLocation === "remote";
}

/** Send messages to HubSpot in the calling window */
get isFromWindow() {
return this._usesCallingWindow && this._iframeLocation === "window";
return this._iframeLocation === "window";
}

/** Broadcast message from remote or window */
Expand Down Expand Up @@ -135,6 +141,10 @@ class CallingExtensionsWrapper implements CallingExtensionsContract {
this._usesCallingWindow = userData.usesCallingWindow;
}

if (userData.portalId) {
this.portalId = userData.portalId;
}

return this._cti.initialized(userData);
}

Expand Down Expand Up @@ -348,6 +358,7 @@ export const useCti = (setDialNumber: (phoneNumber: string) => void) => {
},
iframeLocation: data.iframeLocation,
usesCallingWindow: data.usesCallingWindow,
portalId: data.portalId,
} as OnInitialized);
},
onDialNumber: (data: any, _rawEvent: any) => {
Expand Down
Loading