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

chat-core-zendesk: support setting tags in constructor config #52

Merged
merged 2 commits into from
Sep 23, 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
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ 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 ?? [])];
yen-tt marked this conversation as resolved.
Show resolved Hide resolved
this.tags = [...new Set(this.tags)];
}

/**
Expand Down Expand Up @@ -106,7 +109,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
Loading