Skip to content

Commit

Permalink
chat-core-zendesk: support setting tags in constructor config
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
popestr committed Sep 19, 2024
1 parent 4f213b0 commit 38d26fd
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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. |

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@yext/chat-core-zendesk](./chat-core-zendesk.md) &gt; [ChatCoreZendeskConfig](./chat-core-zendesk.chatcorezendeskconfig.md) &gt; [ticketTags](./chat-core-zendesk.chatcorezendeskconfig.tickettags.md)

## ChatCoreZendeskConfig.ticketTags property

Tags to apply when handoff to Zendesk is initiated.

**Signature:**

```typescript
ticketTags?: string[];
```
1 change: 1 addition & 0 deletions packages/chat-core-zendesk/etc/chat-core-zendesk.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion packages/chat-core-zendesk/src/infra/ChatCoreZendeskImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ export class ChatCoreZendeskImpl {
private eventListeners: { [T in keyof EventMap]?: EventCallback<T>[] } = {};
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 ?? [])];
}

/**
Expand Down Expand Up @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}
17 changes: 17 additions & 0 deletions packages/chat-core-zendesk/tests/ChatCoreZendesk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});
});
1 change: 1 addition & 0 deletions test-sites/test-browser-esm/src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ window.getNextMessage = async () => {
currentResponder = "ZENDESK";
agentCore = provideChatCoreZendesk({
integrationId: process.env.TEST_ZENDESK_INTEGRATION_ID,
ticketTags: ["testingTag"],
});
handleHandoff(data);
}
Expand Down

0 comments on commit 38d26fd

Please sign in to comment.