From 99b5b8ba8bb9d6fb0e6bdbd2fad2c4cc3312799a Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Sat, 11 May 2024 17:32:45 -0300 Subject: [PATCH] fix(whatsapp.gblib): Fix PRIVACY_STORE_MESSAGES param. --- .../services/GBConversationalService.ts | 15 +++++----- packages/core.gbapp/services/GBMinService.ts | 16 +++++----- .../dialogs/FeedbackDialog.ts | 29 ++++++++++--------- .../dialogs/QualityDialog.ts | 21 +++++++------- 4 files changed, 43 insertions(+), 38 deletions(-) diff --git a/packages/core.gbapp/services/GBConversationalService.ts b/packages/core.gbapp/services/GBConversationalService.ts index 6a716cde..d838a5fb 100644 --- a/packages/core.gbapp/services/GBConversationalService.ts +++ b/packages/core.gbapp/services/GBConversationalService.ts @@ -1272,14 +1272,15 @@ export class GBConversationalService { }); } - const analytics = new AnalyticsService(); - const conversation = null; - if (!user.conversationId) { - const conversation = await analytics.createConversation(user); - user.conversationId = conversation.conversationId; + if (process.env.PRIVACY_STORE_MESSAGES === 'true') { + const analytics = new AnalyticsService(); + const conversation = null; + if (!user.conversationId) { + const conversation = await analytics.createConversation(user); + user.conversationId = conversation.conversationId; + } + analytics.createMessage(min.instance.instanceId, conversation, null, text); } - analytics.createMessage(min.instance.instanceId, conversation, null, text); - if (!step && member && !isNaN(member.id) && !member.id.startsWith('1000')) { const to = step.context.activity.group ? step.context.activity.group : member.id; diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 8d91dc23..4a51f3f2 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -444,10 +444,10 @@ export class GBMinService { GBServer.globals.server.all(`/${min.instance.botId}/whatsapp`, async (req, res) => { - + if (req.query['hub.mode'] === 'subscribe') { const val = req.query['hub.verify_token']; - + if (val === process.env.META_CHALLENGE) { res.send(req.query['hub.challenge']); res.status(200); @@ -1034,12 +1034,12 @@ export class GBMinService { if (context.activity.from.id !== min.botId) { // Creates a new row in user table if it does not exists. + if (process.env.PRIVACY_STORE_MESSAGES === 'true') { + // Stores conversation associated to the user to group each message. - // Stores conversation associated to the user to group each message. - - const analytics = new AnalyticsService(); - await analytics.createConversation(user); - + const analytics = new AnalyticsService(); + await analytics.createConversation(user); + } } await sec.updateConversationReferenceById(userId, conversationReference); @@ -1409,8 +1409,10 @@ export class GBMinService { const userId = user.userId; const params = user.params ? JSON.parse(user.params) : {}; + let message: GuaribasConversationMessage; if (process.env.PRIVACY_STORE_MESSAGES === 'true') { + // Adds message to the analytics layer. const analytics = new AnalyticsService(); diff --git a/packages/customer-satisfaction.gbapp/dialogs/FeedbackDialog.ts b/packages/customer-satisfaction.gbapp/dialogs/FeedbackDialog.ts index f8282ef9..4df8ca44 100644 --- a/packages/customer-satisfaction.gbapp/dialogs/FeedbackDialog.ts +++ b/packages/customer-satisfaction.gbapp/dialogs/FeedbackDialog.ts @@ -53,7 +53,7 @@ export class FeedbackDialog extends IGBDialog { * @param bot The bot adapter. * @param min The minimal bot instance data. */ - public static setup (bot: BotAdapter, min: GBMinInstance) { + public static setup(bot: BotAdapter, min: GBMinInstance) { const service = new CSService(); min.dialogs.add( @@ -99,11 +99,11 @@ export class FeedbackDialog extends IGBDialog { } else { await min.conversationalService.sendText(min, step, Messages[locale].please_wait_transfering); const agentSystemId = await sec.assignHumanAgent(min, from); - + await min.userProfile.set(step.context, profile); if (agentSystemId.indexOf('@') !== -1) { - + // Agent is from Teams or Google Chat. const agent = await sec.getUserFromSystemId(agentSystemId); @@ -169,7 +169,7 @@ export class FeedbackDialog extends IGBDialog { await sec.updateHumanAgent(userSystemId, min.instance.instanceId, null); await sec.updateHumanAgent(manualUser.userSystemId, min.instance.instanceId, null); - + } else if (user.agentMode === 'human') { const agent = await sec.getUserFromSystemId(user.agentSystemId); @@ -198,7 +198,7 @@ export class FeedbackDialog extends IGBDialog { await sec.updateHumanAgent(user.userSystemId, min.instance.instanceId, null); await sec.updateHumanAgent(agent.userSystemId, min.instance.instanceId, null); - + } else { if (user.userSystemId.charAt(2) === ':' || userSystemId.indexOf('@') > -1) { // Agent is from Teams or Google Chat. @@ -264,16 +264,19 @@ export class FeedbackDialog extends IGBDialog { async step => { const fixedLocale = 'en-US'; const user = await min.userProfile.get(step.context, {}); + let rate = 1; - // Updates values to perform Bot Analytics. + if (process.env.PRIVACY_STORE_MESSAGES === 'true') { + // Updates values to perform Bot Analytics. - const analytics = new AnalyticsService(); - const rate = await analytics.updateConversationSuggestion( - min.instance.instanceId, - user.conversation.conversationId, - step.result, - user.locale - ); + const analytics = new AnalyticsService(); + let rate = await analytics.updateConversationSuggestion( + min.instance.instanceId, + user.conversation.conversationId, + step.result, + user.locale + ); + } if (rate > 0.5) { await min.conversationalService.sendText(min, step, Messages[fixedLocale].glad_you_liked); diff --git a/packages/customer-satisfaction.gbapp/dialogs/QualityDialog.ts b/packages/customer-satisfaction.gbapp/dialogs/QualityDialog.ts index 3b56e822..e4a06b0e 100644 --- a/packages/customer-satisfaction.gbapp/dialogs/QualityDialog.ts +++ b/packages/customer-satisfaction.gbapp/dialogs/QualityDialog.ts @@ -39,7 +39,6 @@ import { GBMinInstance, IGBDialog } from 'botlib'; import { BotAdapter } from 'botbuilder'; import { WaterfallDialog } from 'botbuilder-dialogs'; import { AnalyticsService } from '../../analytics.gblib/services/AnalyticsService.js'; -import { GBConversationalService } from '../../core.gbapp/services/GBConversationalService.js'; import { CSService } from '../services/CSService.js'; import { Messages } from '../strings.js'; @@ -53,7 +52,7 @@ export class QualityDialog extends IGBDialog { * @param bot The bot adapter. * @param min The minimal bot instance data. */ - public static setup (bot: BotAdapter, min: GBMinInstance) { + public static setup(bot: BotAdapter, min: GBMinInstance) { const service = new CSService(); min.dialogs.add( @@ -89,15 +88,15 @@ export class QualityDialog extends IGBDialog { await service.insertQuestionAlternate(min.instance.instanceId, user.lastQuestion, user.lastQuestionId); // Updates values to perform Bot Analytics. - - const analytics = new AnalyticsService(); - analytics.updateConversationSuggestion( - min.instance.instanceId, - user.conversation, - step.result, - user.locale - ); - + if (process.env.PRIVACY_STORE_MESSAGES === 'true') { + const analytics = new AnalyticsService(); + analytics.updateConversationSuggestion( + min.instance.instanceId, + user.conversation, + step.result, + user.locale + ); + } // Goes to the ask loop. return await step.replaceDialog('/ask', { emptyPrompt: true });