From 38d26fdd0c61f413c1e9bc6a29bb480cb93f625f Mon Sep 17 00:00:00 2001 From: Ryan Pope Date: Thu, 19 Sep 2024 15:26:37 -0400 Subject: [PATCH 1/2] chat-core-zendesk: support setting tags in constructor config Adds the ticketTags field to the constructor config, so that arbitrary tags can be applied to conversations created by the SDK. TEST=manual,auto Ran SDK locally, saw created ZD conversation have the testing tag applied. Wrote a unit test asserting that tags are set correctly, saw it pass. --- .../chat-core-zendesk.chatcorezendeskconfig.md | 1 + ...-zendesk.chatcorezendeskconfig.tickettags.md | 13 +++++++++++++ .../etc/chat-core-zendesk.api.md | 1 + .../src/infra/ChatCoreZendeskImpl.ts | 4 +++- .../src/models/ChatCoreZendeskConfig.ts | 4 ++++ .../tests/ChatCoreZendesk.test.ts | 17 +++++++++++++++++ test-sites/test-browser-esm/src/script.js | 1 + 7 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 packages/chat-core-zendesk/docs/chat-core-zendesk.chatcorezendeskconfig.tickettags.md diff --git a/packages/chat-core-zendesk/docs/chat-core-zendesk.chatcorezendeskconfig.md b/packages/chat-core-zendesk/docs/chat-core-zendesk.chatcorezendeskconfig.md index d96434a..d48513b 100644 --- a/packages/chat-core-zendesk/docs/chat-core-zendesk.chatcorezendeskconfig.md +++ b/packages/chat-core-zendesk/docs/chat-core-zendesk.chatcorezendeskconfig.md @@ -17,4 +17,5 @@ export interface ChatCoreZendeskConfig | Property | Modifiers | Type | Description | | --- | --- | --- | --- | | [integrationId](./chat-core-zendesk.chatcorezendeskconfig.integrationid.md) | | string | The web widget integration ID for the Zendesk chat. | +| [ticketTags?](./chat-core-zendesk.chatcorezendeskconfig.tickettags.md) | | string\[\] | _(Optional)_ Tags to apply when handoff to Zendesk is initiated. | diff --git a/packages/chat-core-zendesk/docs/chat-core-zendesk.chatcorezendeskconfig.tickettags.md b/packages/chat-core-zendesk/docs/chat-core-zendesk.chatcorezendeskconfig.tickettags.md new file mode 100644 index 0000000..c15cba2 --- /dev/null +++ b/packages/chat-core-zendesk/docs/chat-core-zendesk.chatcorezendeskconfig.tickettags.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@yext/chat-core-zendesk](./chat-core-zendesk.md) > [ChatCoreZendeskConfig](./chat-core-zendesk.chatcorezendeskconfig.md) > [ticketTags](./chat-core-zendesk.chatcorezendeskconfig.tickettags.md) + +## ChatCoreZendeskConfig.ticketTags property + +Tags to apply when handoff to Zendesk is initiated. + +**Signature:** + +```typescript +ticketTags?: string[]; +``` diff --git a/packages/chat-core-zendesk/etc/chat-core-zendesk.api.md b/packages/chat-core-zendesk/etc/chat-core-zendesk.api.md index 18a1926..c476ef7 100644 --- a/packages/chat-core-zendesk/etc/chat-core-zendesk.api.md +++ b/packages/chat-core-zendesk/etc/chat-core-zendesk.api.md @@ -24,6 +24,7 @@ export interface ChatCoreZendesk { // @public export interface ChatCoreZendeskConfig { integrationId: string; + ticketTags?: string[]; } // Warning: (ae-forgotten-export) The symbol "ChatCoreZendeskImpl" needs to be exported by the entry point index.d.ts diff --git a/packages/chat-core-zendesk/src/infra/ChatCoreZendeskImpl.ts b/packages/chat-core-zendesk/src/infra/ChatCoreZendeskImpl.ts index eba51d9..c27bf7f 100644 --- a/packages/chat-core-zendesk/src/infra/ChatCoreZendeskImpl.ts +++ b/packages/chat-core-zendesk/src/infra/ChatCoreZendeskImpl.ts @@ -47,12 +47,14 @@ export class ChatCoreZendeskImpl { private eventListeners: { [T in keyof EventMap]?: EventCallback[] } = {}; private conversationId: string | undefined; private integrationId: string; + private tags: string[] = ["yext-chat-agent-handoff"]; constructor(config: ChatCoreZendeskConfig) { if (window === undefined) { throw new Error("This package can only be used in the browser."); } this.integrationId = config.integrationId; + this.tags = [...this.tags, ...(config.ticketTags ?? [])]; } /** @@ -106,7 +108,7 @@ export class ChatCoreZendeskImpl { let convo: Conversation = await Smooch.createConversation({ metadata: { ...ticketFields, - "zen:ticket:tags": "yext-chat-agent-handoff", + "zen:ticket:tags": this.tags.join(", "), // this indicates to the internal zendesk bot webhook that the conversation is from the Chat SDK [MetadataChatSDKKey]: true, }, diff --git a/packages/chat-core-zendesk/src/models/ChatCoreZendeskConfig.ts b/packages/chat-core-zendesk/src/models/ChatCoreZendeskConfig.ts index ff88884..805d1ce 100644 --- a/packages/chat-core-zendesk/src/models/ChatCoreZendeskConfig.ts +++ b/packages/chat-core-zendesk/src/models/ChatCoreZendeskConfig.ts @@ -8,4 +8,8 @@ export interface ChatCoreZendeskConfig { * The web widget integration ID for the Zendesk chat. */ integrationId: string; + /** + * Tags to apply when handoff to Zendesk is initiated. + */ + ticketTags?: string[]; } diff --git a/packages/chat-core-zendesk/tests/ChatCoreZendesk.test.ts b/packages/chat-core-zendesk/tests/ChatCoreZendesk.test.ts index 335b1cf..71e2df9 100644 --- a/packages/chat-core-zendesk/tests/ChatCoreZendesk.test.ts +++ b/packages/chat-core-zendesk/tests/ChatCoreZendesk.test.ts @@ -238,3 +238,20 @@ it("sets ticket fields on handoff", async () => { }, }); }); + +it("sets ticket tags defined in config on handoff", async () => { + const createConversationSpy = jest.spyOn(SmoochLib, "createConversation"); + const chatCoreZendesk = provideChatCoreZendesk({ + ...mockConfig, + ticketTags: ["tag1", "tag2"], + }); + await chatCoreZendesk.init(mockMessageResponse()); + expect(createConversationSpy).toBeCalledWith({ + metadata: { + "zen:ticket_field:field1": "value1", + "zen:ticket_field:field2": "value2", + "zen:ticket:tags": "yext-chat-agent-handoff, tag1, tag2", + YEXT_CHAT_SDK: true, + }, + }); +}); diff --git a/test-sites/test-browser-esm/src/script.js b/test-sites/test-browser-esm/src/script.js index 8392249..ba8a042 100644 --- a/test-sites/test-browser-esm/src/script.js +++ b/test-sites/test-browser-esm/src/script.js @@ -63,6 +63,7 @@ window.getNextMessage = async () => { currentResponder = "ZENDESK"; agentCore = provideChatCoreZendesk({ integrationId: process.env.TEST_ZENDESK_INTEGRATION_ID, + ticketTags: ["testingTag"], }); handleHandoff(data); } From 33f21bac8d2fbcd0f6161ee0c88a3ade009a6845 Mon Sep 17 00:00:00 2001 From: Ryan Pope Date: Mon, 23 Sep 2024 14:03:15 -0400 Subject: [PATCH 2/2] dedupe tags --- packages/chat-core-zendesk/src/infra/ChatCoreZendeskImpl.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/chat-core-zendesk/src/infra/ChatCoreZendeskImpl.ts b/packages/chat-core-zendesk/src/infra/ChatCoreZendeskImpl.ts index c27bf7f..9a52750 100644 --- a/packages/chat-core-zendesk/src/infra/ChatCoreZendeskImpl.ts +++ b/packages/chat-core-zendesk/src/infra/ChatCoreZendeskImpl.ts @@ -55,6 +55,7 @@ export class ChatCoreZendeskImpl { } this.integrationId = config.integrationId; this.tags = [...this.tags, ...(config.ticketTags ?? [])]; + this.tags = [...new Set(this.tags)]; } /**