Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
popestr committed Sep 25, 2024
1 parent 9f2a385 commit 62689ff
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/chat-core-aws-connect/THIRD-PARTY-NOTICES
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,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.6.1
- @types/node@22.7.1
- @types/stack-utils@2.0.3
- @types/tough-cookie@4.0.5
- @types/yargs-parser@21.0.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Provide the current conversation ID for the chat session.
**Signature:**

```typescript
getSession(): void;
getSession(): string | undefined;
```
**Returns:**

void
string \| undefined

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Initialize the Amazon Connect chat session using the credentials from the Chat A
**Signature:**

```typescript
init(messageResponse: MessageResponse): Promise<void>;
init(messageResponse: MessageResponse): Promise<ChatCoreZendeskSessionCredentials>;
```

## Parameters
Expand All @@ -20,5 +20,5 @@ init(messageResponse: MessageResponse): Promise<void>;

**Returns:**

Promise&lt;void&gt;
Promise&lt;ChatCoreZendeskSessionCredentials&gt;

Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Reinitialize the session using existing session data.
**Signature:**

```typescript
reinitializeSession(credentials: string): Promise<void>;
reinitializeSession(credentials: ChatCoreZendeskSessionCredentials): Promise<void>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| credentials | string | The credentials to use to reinitialize the session. |
| credentials | ChatCoreZendeskSessionCredentials | The credentials to use to reinitialize the session. |

**Returns:**

Expand Down
7 changes: 4 additions & 3 deletions packages/chat-core-zendesk/etc/chat-core-zendesk.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import { MessageResponse } from '@yext/chat-core';
// @public
export interface ChatCoreZendesk {
emit<T extends keyof EventMap>(eventName: T, data: EventMap[T]): void;
getSession(): void;
init(messageResponse: MessageResponse): Promise<void>;
getSession(): string | undefined;
// Warning: (ae-forgotten-export) The symbol "ChatCoreZendeskSessionCredentials" needs to be exported by the entry point index.d.ts
init(messageResponse: MessageResponse): Promise<ChatCoreZendeskSessionCredentials>;
// Warning: (ae-forgotten-export) The symbol "EventMap" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "EventCallback" needs to be exported by the entry point index.d.ts
on<T extends keyof EventMap>(eventName: T, cb: EventCallback<T>): void;
processMessage(request: MessageRequest): Promise<void>;
reinitializeSession(credentials: string): Promise<void>;
reinitializeSession(credentials: ChatCoreZendeskSessionCredentials): Promise<void>;
resetSession(): void;
}

Expand Down
23 changes: 15 additions & 8 deletions packages/chat-core-zendesk/src/infra/ChatCoreZendeskImpl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { MessageRequest, MessageResponse } from "@yext/chat-core";
import { ChatCoreZendesk } from "../models";

/**
* Issue 1: Smooch Version
Expand Down Expand Up @@ -32,6 +33,7 @@ const Smooch = (SmoochLib.default || SmoochLib) as typeof SmoochLib;

import { ChatCoreZendeskConfig } from "../models/ChatCoreZendeskConfig";
import { EventCallback, EventMap } from "../models/EventCallback";
import { ChatCoreZendeskSessionCredentials } from "../models/ChatCoreZendeskSessionCredentials";

const MetadataChatSDKKey = "YEXT_CHAT_SDK";

Expand All @@ -43,7 +45,7 @@ const MetadataChatSDKKey = "YEXT_CHAT_SDK";
*
* @internal
*/
export class ChatCoreZendeskImpl {
export class ChatCoreZendeskImpl implements ChatCoreZendesk {
private eventListeners: { [T in keyof EventMap]?: EventCallback<T>[] } = {};
private conversationId: string | undefined;
private integrationId: string;
Expand All @@ -63,9 +65,9 @@ export class ChatCoreZendeskImpl {
* mode on the first invocation. Subsequent calls to this method will create a
* new conversation session.
*/
async init(messageRsp: MessageResponse): Promise<string> {
async init(messageRsp: MessageResponse): Promise<ChatCoreZendeskSessionCredentials> {
await this.initializeZendeskSdk();
return await this.createZendeskConversation(messageRsp);
return this.createZendeskConversation(messageRsp);
}

private async initializeZendeskSdk(): Promise<void> {
Expand Down Expand Up @@ -97,7 +99,7 @@ export class ChatCoreZendeskImpl {
*/
private async createZendeskConversation(
messageRsp: MessageResponse
): Promise<string> {
): Promise<ChatCoreZendeskSessionCredentials> {
const ticketFields: Record<string, unknown> = {};
try {
if (messageRsp.integrationDetails?.zendeskHandoff?.ticketFields) {
Expand Down Expand Up @@ -139,7 +141,10 @@ export class ChatCoreZendeskImpl {
}`,
this.conversationId
);
return this.conversationId;

return {
conversationId: convo.id,
};
}

private setupEventListeners() {
Expand Down Expand Up @@ -215,12 +220,14 @@ export class ChatCoreZendeskImpl {
}

resetSession(): void {
// @ts-ignore - off() is not in the Smooch types, but does exist
Smooch.off();
this.conversationId = undefined;
}

async reinitializeSession(conversationId: string): Promise<void> {
this.conversationId = conversationId;
async reinitializeSession(credentials: ChatCoreZendeskSessionCredentials): Promise<void> {
this.conversationId = credentials.conversationId;
await this.initializeZendeskSdk();
await Smooch.loadConversation(conversationId);
await Smooch.loadConversation(credentials.conversationId);
}
}
7 changes: 4 additions & 3 deletions packages/chat-core-zendesk/src/models/ChatCoreZendesk.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MessageRequest, MessageResponse } from "@yext/chat-core";
import { EventCallback, EventMap } from "./EventCallback";
import { ChatCoreZendeskSessionCredentials } from "./ChatCoreZendeskSessionCredentials";

/**
* Provides methods for interacting with Chat's Zendesk integration.
Expand All @@ -12,7 +13,7 @@ export interface ChatCoreZendesk {
*
* @param messageResponse - The response returned from a successful call to the Chat API.
*/
init(messageResponse: MessageResponse): Promise<void>;
init(messageResponse: MessageResponse): Promise<ChatCoreZendeskSessionCredentials>;

/**
* Register a callback for an event triggered within the Zendesk chat session.
Expand Down Expand Up @@ -46,7 +47,7 @@ export interface ChatCoreZendesk {
/**
* Provide the current conversation ID for the chat session.
*/
getSession(): void;
getSession(): string | undefined;

/**
* Reset the chat session by clearing the current conversation ID.
Expand All @@ -58,5 +59,5 @@ export interface ChatCoreZendesk {
*
* @param credentials - The credentials to use to reinitialize the session.
*/
reinitializeSession(credentials: string): Promise<void>;
reinitializeSession(credentials: ChatCoreZendeskSessionCredentials): Promise<void>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Credentials for the Zendesk session created by the {@link ChatCoreZendesk}.
* Used for reinitializing the session across page reloads.
*
* @public
*/
export interface ChatCoreZendeskSessionCredentials {
/**
* The conversation ID for the current chat session.
*/
conversationId: string;
}

0 comments on commit 62689ff

Please sign in to comment.