From cd5d204411a6769104ae43fc1d47f2752c5bdf19 Mon Sep 17 00:00:00 2001 From: AlexanderKanakis Date: Tue, 15 Feb 2022 18:03:08 +0200 Subject: [PATCH] retain response for chat escalation --- app.json | 2 +- handlers/InitiateSalesforceSessionHandler.ts | 2 +- .../CheckChatStatusHelper.ts | 12 ++++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app.json b/app.json index 7c5c3ee..1c0d4f5 100644 --- a/app.json +++ b/app.json @@ -20,5 +20,5 @@ "IRoomUserTyping", "IUIKitLivechatInteractionHandler" ], - "commitHash": "947b904c7e5fe7512fb0d7df174a2ffc0ee02397" + "commitHash": "38d13ed51a2ff816eebfd019dab387f9ab97e6f7" } \ No newline at end of file diff --git a/handlers/InitiateSalesforceSessionHandler.ts b/handlers/InitiateSalesforceSessionHandler.ts index 2e61cee..7a1c8f3 100644 --- a/handlers/InitiateSalesforceSessionHandler.ts +++ b/handlers/InitiateSalesforceSessionHandler.ts @@ -226,7 +226,7 @@ export class InitiateSalesforceSession { technicalDifficultyMessage, assoc, ); - await checkChatStatusDirect.checkCurrentChatStatus(); + await checkChatStatusDirect.checkCurrentChatStatus(pullMessagesres); } }) .catch(async (error) => { diff --git a/helperFunctions/subscribeHelpers/InitiateSalesforceSessionHelpers/CheckChatStatusHelper.ts b/helperFunctions/subscribeHelpers/InitiateSalesforceSessionHelpers/CheckChatStatusHelper.ts index c2eb5a3..b19d019 100644 --- a/helperFunctions/subscribeHelpers/InitiateSalesforceSessionHelpers/CheckChatStatusHelper.ts +++ b/helperFunctions/subscribeHelpers/InitiateSalesforceSessionHelpers/CheckChatStatusHelper.ts @@ -31,7 +31,7 @@ export class CheckChatStatus { private assoc: RocketChatAssociationRecord, ) { } - public async checkCurrentChatStatus() { + public async checkCurrentChatStatus(res: any = {}) { const checkAgentStatusDirectCallback = new CheckAgentStatusCallback( this.app, this.http, @@ -43,6 +43,9 @@ export class CheckChatStatus { ); pullMessages(this.http, this.salesforceChatApiEndpoint, this.affinityToken, this.key) .then(async (response) => { + if ((Object.keys(res).length === 0 || res !== 'undefined') && response.content === '{}') { + response = res; + } if (response.statusCode === 403) { console.error('pullMessages: Chat session is expired.', getError(response)); console.log(ErrorLogs.LIVEAGENT_SESSION_EXPIRED); @@ -83,7 +86,12 @@ export class CheckChatStatus { const chasitorIdleTimeout = chatEstablishedMessage.chasitorIdleTimeout || false; const sneakPeekEnabled = chatEstablishedMessage.sneakPeekEnabled; const { id, persisantAffinity, persistantKey } = await retrievePersistentTokens(this.read, this.assoc); - const salesforceAgentName = chatEstablishedMessage.name; + let salesforceAgentName; + for (const msg of messageArray) { + if (msg.message.name) { + salesforceAgentName = msg.message.name; + } + } await this.persistence.updateByAssociation(this.assoc, { id, affinityToken: persisantAffinity, key: persistantKey, chasitorIdleTimeout, sneakPeekEnabled, salesforceAgentName }, true);