Skip to content

Commit

Permalink
handle resolved ticket event
Browse files Browse the repository at this point in the history
  • Loading branch information
Yen Truong committed Sep 12, 2024
1 parent 6abe20e commit ab2aeb0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/chat-core-zendesk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yext/chat-core-zendesk",
"version": "0.1.1",
"version": "0.1.2",
"description": "Typescript Networking Library for the Yext Chat API Integration with Zendesk",
"main": "./dist/commonjs/index.js",
"module": "./dist/esm/index.mjs",
Expand Down
26 changes: 17 additions & 9 deletions packages/chat-core-zendesk/src/infra/ChatCoreZendeskImpl.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { MessageRequest, MessageResponse } from "@yext/chat-core";

/**
Expand Down Expand Up @@ -118,21 +119,28 @@ export class ChatCoreZendeskImpl {
Smooch.on(
"message:received",
(message: Message, data: ConversationData) => {
if (message.type !== "text") {
if (message.type !== "text" || message.role !== "business") {
return;
}
// If the message is from a bot, indicating the agent has left or closed the ticket, then reset the session
if (
message.role === "business" &&
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - subroles is not in the Smooch types but it's in the actual data
message["subroles"]?.includes("AI")
) {
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.";
}

this.eventListeners["message"]?.forEach((cb) => cb(message.text));
// If the message is from a bot, indicating the agent has deleted the ticket, 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["typing"]?.forEach((cb) => cb(false));
}
);
Expand Down
2 changes: 1 addition & 1 deletion packages/chat-core-zendesk/tests/ChatCoreZendesk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ it("triggers message event callbacks", async () => {
const onMessageFn = onCbSpy.mock.calls[0][1] as any;
// simulate a message event
onMessageFn(
{ text, type: "text" },
{ text, type: "text", role: "business" },
{ conversation: { id: mockConversationId } }
);
expect(dummyFn).toBeCalledWith(text);
Expand Down
2 changes: 1 addition & 1 deletion test-sites/test-browser-esm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ab2aeb0

Please sign in to comment.