Skip to content

Commit

Permalink
chat-core-zendesk: fetch new user's first conversation ID #48
Browse files Browse the repository at this point in the history
the returned conversation ID when invoking `Smooch.createConversation` for a new user is `TEMPORARY_CONVERSATION`. In order the the rest of the integration logic to work, we need the actual conversation ID. this PR updates it to re-fetch using `Smooch.getDisplayedConversation` to get the actual id for the session. Subsequent conversation creation do return the proper ID so this additional logic is not needed there

J=CLIP-1516
TEST=manual

clear all cookies and values in local/session storage to start as a new user, see that it no longer throws an error on the first conversation.
  • Loading branch information
yen-tt authored Sep 12, 2024
1 parent 67a78da commit 6abe20e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 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.0",
"version": "0.1.1",
"description": "Typescript Networking Library for the Yext Chat API Integration with Zendesk",
"main": "./dist/commonjs/index.js",
"module": "./dist/esm/index.mjs",
Expand Down
12 changes: 11 additions & 1 deletion packages/chat-core-zendesk/src/infra/ChatCoreZendeskImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,23 @@ export class ChatCoreZendeskImpl {
* with the conversation summary as the initial message.
*/
private async setupSession(messageRsp: MessageResponse) {
const convo: Conversation = await Smooch.createConversation({
let convo: Conversation = await Smooch.createConversation({
metadata: {
"zen:ticket:tags": "yext-chat",
// this indicates to the internal zendesk bot webhook that the conversation is from the Chat SDK
[MetadataChatSDKKey]: true,
},
});

// On first conversation creation of a new user, the id is TEMPORARY_CONVERSATION.
// We need to re-fetch the current conversation to get the actual id.
if (convo.id === 'TEMPORARY_CONVERSATION') {
const currentConversation = Smooch.getDisplayedConversation();
if (!currentConversation) {
throw new Error("No conversation found");
}
convo = currentConversation;
}
this.conversationId = convo.id;
Smooch.loadConversation(convo.id);
Smooch.sendMessage(
Expand Down
8 changes: 4 additions & 4 deletions 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 6abe20e

Please sign in to comment.