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 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
18 changes: 13 additions & 5 deletions demos/demo-minimal-js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { messageType, callEndStatus } from "../../src/Constants";

export const state = {
engagementId: 0,
toNumber: "+1234",
fromNumber: "+123456",
userAvailable: false,
incomingContactName: "",
toNumber: "+1234",
userAvailable: false,
userId: 0,
};

const sizeInfo = {
Expand Down Expand Up @@ -46,18 +47,25 @@ function enableButtons(ids) {
const cti = new CallingExtensions({
debugMode: true,
eventHandlers: {
onReady: data => {
onReady: ({ engagementId, portalId, userId } = {}) => {
cti.initialized({
engagementId,
isLoggedIn: false,
sizeInfo,
engagementId: data.engagementId,
});
disableButtons([INITIALIZE]);
if (data.engagementId) {
if (engagementId) {
enableButtons([ANSWER_CALL, END_CALL]);
state.engagementId = engagementId;
return;
}
enableButtons([LOG_IN, SEND_ERROR, RESIZE_WIDGET]);
if (portalId) {
state.portalId = portalId;
}
if (userId) {
state.userId = userId;
}
},
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.

4 changes: 2 additions & 2 deletions 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",
"description": "A JavaScript SDK for integrating calling apps into HubSpot.",
"publishConfig": {
"access": "public"
Expand All @@ -10,7 +10,7 @@
"build:test": "npm run build && npm run test",
"cover": "open coverage/lcov-report/index.html",
"eslint": "eslint src --ext .js",
"eslint:fix": "eslint src .js --fix",
"eslint:fix": "eslint src --ext .js --fix",
"preversion": "npm run build:test",
"postversion": "git push --follow-tags",
"publish:alpha:current": "npm publish --access public --tag alpha",
Expand Down
14 changes: 9 additions & 5 deletions src/IFrameManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ class IFrameManager {
}

static createIFrame(iFrameOptions, onLoadCallback) {
const { src, width, height, hostElementSelector } = iFrameOptions;
const {
src, width, height, hostElementSelector,
} = iFrameOptions;

if (!src || !width || !height || !hostElementSelector) {
throw new Error(
Expand Down Expand Up @@ -118,11 +120,11 @@ class IFrameManager {
}
}

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

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

onMessage(event) {
const { data, origin } = event;
const { type, engagementId } = event.data;
const {
type, engagementId, portalId, userId,
} = 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 +200,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, userId });
}
return;
}
Expand Down
Loading