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

Include portalId and userId in the onReady payload #193

Merged
merged 11 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
11 changes: 7 additions & 4 deletions demos/demo-minimal-js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,21 @@ function enableButtons(ids) {
const cti = new CallingExtensions({
debugMode: true,
eventHandlers: {
onReady: data => {
onReady: ({ engagementId, portalId } = {}) => {
alonso-cadenas marked this conversation as resolved.
Show resolved Hide resolved
cti.initialized({
engagementId,
isLoggedIn: false,
sizeInfo,
engagementId: data.engagementId,
});
disableButtons([INITIALIZE]);
if (data.engagementId) {
if (engagementId) {
enableButtons([ANSWER_CALL, END_CALL]);
return;
state.engagementId = engagementId;
}
enableButtons([LOG_IN, SEND_ERROR, RESIZE_WIDGET]);
if (portalId) {
state.portalId = portalId;
}
},
onDialNumber: (data, rawEvent) => {
const { phoneNumber } = data;
Expand Down
8 changes: 5 additions & 3 deletions demos/demo-react-ts/src/hooks/useCti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,19 @@ export const useCti = (
debugMode: true,
eventHandlers: {
onReady: (data: { engagementId: number | undefined }) => {
const { engagementId } = data || {};
cti.initialized({
isLoggedIn: true,
sizeInfo: defaultSize,
engagementId: data.engagementId,
engagementId,
alonso-cadenas marked this conversation as resolved.
Show resolved Hide resolved
});
const incomingNumber =
window.localStorage.getItem(INCOMING_NUMBER_KEY);
const incomingContactName = window.localStorage.getItem(
INCOMING_CONTACT_NAME_KEY
);
if (data.engagementId && incomingNumber && incomingContactName) {
if (engagementId && incomingNumber && incomingContactName) {
setEngagementId(engagementId);
cti.incomingNumber = incomingNumber;
setIncomingContactName(incomingContactName);
initializeCallingStateForExistingCall(incomingNumber);
Expand Down Expand Up @@ -248,7 +250,7 @@ export const useCti = (
},
},
});
}, []);
}, [initializeCallingStateForExistingCall]);
return {
phoneNumber,
engagementId,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hubspot/calling-extensions-sdk",
"version": "0.4.1",
"version": "0.5.0-alpha.0",
"description": "A JavaScript SDK for integrating calling apps into HubSpot.",
"publishConfig": {
"access": "public"
Expand Down
8 changes: 4 additions & 4 deletions src/IFrameManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ class IFrameManager {
}
}

onReady(engagementId) {
onReady(data = {}) {
this.isReady = true;
this.onMessageHandler({
type: messageType.READY,
data: { engagementId },
data,
});
}

Expand Down Expand Up @@ -179,7 +179,7 @@ class IFrameManager {

onMessage(event) {
const { data, origin } = event;
const { type, engagementId } = event.data;
const { type, engagementId, portalId } = event.data;
if (type === messageType.SYNC) {
// The iFrame host can send this message multiple times, don't respond more than once
if (!this.isReady) {
Expand All @@ -196,7 +196,7 @@ class IFrameManager {
this.destinationHost = hostUrl || this.destinationHost;
this.logDebugMessage(prefix, debugMessageType.FROM_HUBSPOT, type, data);
this.sendMessage(message);
this.onReady(engagementId);
this.onReady({ engagementId, portalId });
}
return;
}
Expand Down
Loading