From 86991978990cfcb684d3b7f6a51ab3c10ad28ce2 Mon Sep 17 00:00:00 2001 From: Yen Truong Date: Wed, 18 Dec 2024 15:30:08 -0500 Subject: [PATCH 1/2] workaround to grab ticket id --- package-lock.json | 2 +- packages/chat-core-zendesk/package.json | 2 +- .../src/infra/ChatCoreZendeskImpl.ts | 37 ++++++++++++------- .../tests/ChatCoreZendesk.test.ts | 29 +++++++++++++++ test-sites/test-browser-esm/package-lock.json | 2 +- 5 files changed, 55 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7db38b5..7dd5ddb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9566,7 +9566,7 @@ }, "packages/chat-core-zendesk": { "name": "@yext/chat-core-zendesk", - "version": "0.3.1", + "version": "0.4.0", "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 478ce37..6eb5006 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.3.1", + "version": "0.4.0", "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 d700471..92f938f 100644 --- a/packages/chat-core-zendesk/src/infra/ChatCoreZendeskImpl.ts +++ b/packages/chat-core-zendesk/src/infra/ChatCoreZendeskImpl.ts @@ -157,6 +157,21 @@ export class ChatCoreZendeskImpl implements ChatCoreZendesk { } this.conversationId = convo.id; Smooch.loadConversation(convo.id); + + // This is a temporary solution until Zendesk have a more robust way of fetching the ticket id. + // A Zendesk trigger is setup to make a Sunco API call, using this conversation ID placed inside + // a Zendesk custom field, to append the corresponding ticket id into the Sunco conversation's + // metadata. The bot then pull from metadata to inform the user of the ticket id when the messaging + // session ends. + const convoIdTicketField = Object.keys(ticketFields).find((key) => { + return ticketFields[key] === "SUNCO_CONVERSATION_ID_PLACEHOLDER"; + }); + if (convoIdTicketField) { + await Smooch.updateConversation(convo.id, { + metadata: { [convoIdTicketField]: convo.id }, + }); + } + Smooch.sendMessage( `SUMMARY: ${ messageRsp.notes.conversationSummary ?? @@ -179,29 +194,23 @@ export class ChatCoreZendeskImpl implements ChatCoreZendesk { if (data.conversation.id !== this.conversationId) { return; } - if (message.type !== "text" || message.role !== "business") { + if ( + message.type !== "text" || + message.role !== "business" || + // @ts-ignore - metadata is not in the Smooch types but it's in the actual data + message["metadata"]?.type === "csat" + ) { return; } - let msg: string = message.text; - - // If the message is of type CSAT, indicating the agent has resolved the ticket, then omit this message. - // Instead, send a message to inform user and reset the session - // @ts-ignore - metadata is not in the Smooch types but it's in the actual data - if (message["metadata"]?.type === "csat") { - this.resetSession(); - this.eventListeners["close"]?.forEach((cb) => cb(data)); - msg = - "The agent has resolved the ticket. Further assistance will now be provided by the bot."; - } - // If the message is from a bot, indicating the agent has deleted the ticket, then reset the session + // If the message is from a bot, indicating the agent has ended the messaging session, then reset the session // @ts-ignore - subroles is not in the Smooch types but it's in the actual data if (message["subroles"]?.includes("AI")) { this.resetSession(); this.eventListeners["close"]?.forEach((cb) => cb(data)); } - this.eventListeners["message"]?.forEach((cb) => cb(msg)); + this.eventListeners["message"]?.forEach((cb) => cb(message.text)); this.eventListeners["typing"]?.forEach((cb) => cb(false)); } ); diff --git a/packages/chat-core-zendesk/tests/ChatCoreZendesk.test.ts b/packages/chat-core-zendesk/tests/ChatCoreZendesk.test.ts index d5229c5..b30ac1b 100644 --- a/packages/chat-core-zendesk/tests/ChatCoreZendesk.test.ts +++ b/packages/chat-core-zendesk/tests/ChatCoreZendesk.test.ts @@ -28,6 +28,7 @@ jest.mock("smooch", () => ({ render: jest.fn(), init: jest.fn(), createConversation: jest.fn(), + updateConversation: jest.fn(), loadConversation: jest.fn(), sendMessage: jest.fn(), on: jest.fn(), @@ -300,3 +301,31 @@ it("sets ticket tags defined in config on handoff", async () => { }, }); }); + +it("set conversation id to custom field on handoff", async () => { + const createConversationSpy = jest.spyOn(SmoochLib, "createConversation"); + const updateConversationSpy = jest.spyOn(SmoochLib, "updateConversation"); + const chatCoreZendesk = provideChatCoreZendesk(mockConfig); + + await chatCoreZendesk.init({ + ...mockMessageResponse(), + integrationDetails: { + zendeskHandoff: { + ticketFields: '{"123456": "SUNCO_CONVERSATION_ID_PLACEHOLDER"}', + }, + }, + }); + expect(createConversationSpy).toBeCalledWith({ + metadata: { + "zen:ticket:tags": "yext-chat-agent-handoff", + YEXT_CHAT_SDK: true, + "zen:ticket_field:123456": "SUNCO_CONVERSATION_ID_PLACEHOLDER", + }, + }); + + expect(updateConversationSpy).toBeCalledWith(mockConversationId, { + metadata: { + "zen:ticket_field:123456": mockConversationId, + }, + }); +}); diff --git a/test-sites/test-browser-esm/package-lock.json b/test-sites/test-browser-esm/package-lock.json index abfd914..c086a4e 100644 --- a/test-sites/test-browser-esm/package-lock.json +++ b/test-sites/test-browser-esm/package-lock.json @@ -107,7 +107,7 @@ }, "../../packages/chat-core-zendesk": { "name": "@yext/chat-core-zendesk", - "version": "0.3.1", + "version": "0.4.0", "license": "BSD-3-Clause", "dependencies": { "smooch": "5.6.0" From 1ca3307decb08786f852d9dd08a26546730de399 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 18 Dec 2024 20:48:53 +0000 Subject: [PATCH 2/2] Automated update to repo's documentation and third party notices from github action --- packages/chat-core-aws-connect/THIRD-PARTY-NOTICES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/chat-core-aws-connect/THIRD-PARTY-NOTICES b/packages/chat-core-aws-connect/THIRD-PARTY-NOTICES index 58b8224..1e61bfc 100644 --- a/packages/chat-core-aws-connect/THIRD-PARTY-NOTICES +++ b/packages/chat-core-aws-connect/THIRD-PARTY-NOTICES @@ -194,7 +194,7 @@ The following NPM packages may be included in this product: - @types/istanbul-lib-report@3.0.3 - @types/istanbul-reports@3.0.4 - @types/jsdom@20.0.1 - - @types/node@22.10.1 + - @types/node@22.10.2 - @types/stack-utils@2.0.3 - @types/tough-cookie@4.0.5 - @types/yargs-parser@21.0.3