From 6abe20eaec458194ff60abe0735b79bced3195a1 Mon Sep 17 00:00:00 2001 From: Yen Truong <36055303+yen-tt@users.noreply.github.com> Date: Thu, 12 Sep 2024 11:26:55 -0400 Subject: [PATCH] chat-core-zendesk: fetch new user's first conversation ID #48 the returned conversation ID when invoking `Smooch.createConversation` for a new user is `TEMPORARY_CONVERSATION`. In order the the rest of the integration logic to work, we need the actual conversation ID. this PR updates it to re-fetch using `Smooch.getDisplayedConversation` to get the actual id for the session. Subsequent conversation creation do return the proper ID so this additional logic is not needed there J=CLIP-1516 TEST=manual clear all cookies and values in local/session storage to start as a new user, see that it no longer throws an error on the first conversation. --- package-lock.json | 2 +- packages/chat-core-zendesk/package.json | 2 +- .../src/infra/ChatCoreZendeskImpl.ts | 12 +++++++++++- test-sites/test-browser-esm/package-lock.json | 8 ++++---- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6e25545..3436274 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9560,7 +9560,7 @@ }, "packages/chat-core-zendesk": { "name": "@yext/chat-core-zendesk", - "version": "0.1.0", + "version": "0.1.1", "license": "BSD-3-Clause", "dependencies": { "smooch": "5.6.0" diff --git a/packages/chat-core-zendesk/package.json b/packages/chat-core-zendesk/package.json index a0c1987..dab2d09 100644 --- a/packages/chat-core-zendesk/package.json +++ b/packages/chat-core-zendesk/package.json @@ -1,6 +1,6 @@ { "name": "@yext/chat-core-zendesk", - "version": "0.1.0", + "version": "0.1.1", "description": "Typescript Networking Library for the Yext Chat API Integration with Zendesk", "main": "./dist/commonjs/index.js", "module": "./dist/esm/index.mjs", diff --git a/packages/chat-core-zendesk/src/infra/ChatCoreZendeskImpl.ts b/packages/chat-core-zendesk/src/infra/ChatCoreZendeskImpl.ts index 0bf3c9a..c1cce23 100644 --- a/packages/chat-core-zendesk/src/infra/ChatCoreZendeskImpl.ts +++ b/packages/chat-core-zendesk/src/infra/ChatCoreZendeskImpl.ts @@ -88,13 +88,23 @@ export class ChatCoreZendeskImpl { * with the conversation summary as the initial message. */ private async setupSession(messageRsp: MessageResponse) { - const convo: Conversation = await Smooch.createConversation({ + let convo: Conversation = await Smooch.createConversation({ metadata: { "zen:ticket:tags": "yext-chat", // this indicates to the internal zendesk bot webhook that the conversation is from the Chat SDK [MetadataChatSDKKey]: true, }, }); + + // On first conversation creation of a new user, the id is TEMPORARY_CONVERSATION. + // We need to re-fetch the current conversation to get the actual id. + if (convo.id === 'TEMPORARY_CONVERSATION') { + const currentConversation = Smooch.getDisplayedConversation(); + if (!currentConversation) { + throw new Error("No conversation found"); + } + convo = currentConversation; + } this.conversationId = convo.id; Smooch.loadConversation(convo.id); Smooch.sendMessage( diff --git a/test-sites/test-browser-esm/package-lock.json b/test-sites/test-browser-esm/package-lock.json index 97c86fe..0ebf5c4 100644 --- a/test-sites/test-browser-esm/package-lock.json +++ b/test-sites/test-browser-esm/package-lock.json @@ -88,7 +88,7 @@ "@microsoft/api-extractor": "^7.34.8", "@types/jest": "^29.5.1", "@types/node-fetch": "^2.6.4", - "@yext/chat-core": "^0.8.2", + "@yext/chat-core": "^0.9.1", "@yext/eslint-config": "^1.0.0", "babel-jest": "^29.5.0", "dotenv": "^16.4.5", @@ -102,7 +102,7 @@ "typescript": "^5.0.4" }, "peerDependencies": { - "@yext/chat-core": "^0.8.2" + "@yext/chat-core": "^0.9.1" } }, "../../packages/chat-core-zendesk": { @@ -119,7 +119,7 @@ "@microsoft/api-extractor": "^7.34.8", "@types/jest": "^29.5.1", "@types/smooch": "^5.3.7", - "@yext/chat-core": "^0.8.2", + "@yext/chat-core": "^0.9.1", "@yext/eslint-config": "^1.0.0", "babel-jest": "^29.5.0", "eslint": "^8.39.0", @@ -132,7 +132,7 @@ "typescript": "^5.0.4" }, "peerDependencies": { - "@yext/chat-core": "^0.8.2" + "@yext/chat-core": "^0.9.1" } }, "node_modules/@jridgewell/sourcemap-codec": {