fix(whatsapp.gblib): Fix PRIVACY_STORE_MESSAGES param.
This commit is contained in:
		
							parent
							
								
									b301b238ff
								
							
						
					
					
						commit
						99b5b8ba8b
					
				
					 4 changed files with 43 additions and 38 deletions
				
			
		| 
						 | 
					@ -1272,14 +1272,15 @@ export class GBConversationalService {
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const analytics = new AnalyticsService();
 | 
					    if (process.env.PRIVACY_STORE_MESSAGES === 'true') {
 | 
				
			||||||
    const conversation = null;
 | 
					      const analytics = new AnalyticsService();
 | 
				
			||||||
    if (!user.conversationId) {
 | 
					      const conversation = null;
 | 
				
			||||||
      const conversation = await analytics.createConversation(user);
 | 
					      if (!user.conversationId) {
 | 
				
			||||||
      user.conversationId = conversation.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')) {
 | 
					    if (!step && member && !isNaN(member.id) && !member.id.startsWith('1000')) {
 | 
				
			||||||
      const to = step.context.activity.group ? step.context.activity.group : member.id;
 | 
					      const to = step.context.activity.group ? step.context.activity.group : member.id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -444,10 +444,10 @@ export class GBMinService {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    GBServer.globals.server.all(`/${min.instance.botId}/whatsapp`, async (req, res) => {
 | 
					    GBServer.globals.server.all(`/${min.instance.botId}/whatsapp`, async (req, res) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      if (req.query['hub.mode'] === 'subscribe') {
 | 
					      if (req.query['hub.mode'] === 'subscribe') {
 | 
				
			||||||
        const val = req.query['hub.verify_token'];
 | 
					        const val = req.query['hub.verify_token'];
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
        if (val === process.env.META_CHALLENGE) {
 | 
					        if (val === process.env.META_CHALLENGE) {
 | 
				
			||||||
          res.send(req.query['hub.challenge']);
 | 
					          res.send(req.query['hub.challenge']);
 | 
				
			||||||
          res.status(200);
 | 
					          res.status(200);
 | 
				
			||||||
| 
						 | 
					@ -1034,12 +1034,12 @@ export class GBMinService {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          if (context.activity.from.id !== min.botId) {
 | 
					          if (context.activity.from.id !== min.botId) {
 | 
				
			||||||
            // Creates a new row in user table if it does not exists.
 | 
					            // 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);
 | 
					          await sec.updateConversationReferenceById(userId, conversationReference);
 | 
				
			||||||
| 
						 | 
					@ -1409,8 +1409,10 @@ export class GBMinService {
 | 
				
			||||||
    const userId = user.userId;
 | 
					    const userId = user.userId;
 | 
				
			||||||
    const params = user.params ? JSON.parse(user.params) : {};
 | 
					    const params = user.params ? JSON.parse(user.params) : {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    let message: GuaribasConversationMessage;
 | 
					    let message: GuaribasConversationMessage;
 | 
				
			||||||
    if (process.env.PRIVACY_STORE_MESSAGES === 'true') {
 | 
					    if (process.env.PRIVACY_STORE_MESSAGES === 'true') {
 | 
				
			||||||
 | 
					      
 | 
				
			||||||
      // Adds message to the analytics layer.
 | 
					      // Adds message to the analytics layer.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      const analytics = new AnalyticsService();
 | 
					      const analytics = new AnalyticsService();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -53,7 +53,7 @@ export class FeedbackDialog extends IGBDialog {
 | 
				
			||||||
   * @param bot The bot adapter.
 | 
					   * @param bot The bot adapter.
 | 
				
			||||||
   * @param min The minimal bot instance data.
 | 
					   * @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();
 | 
					    const service = new CSService();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    min.dialogs.add(
 | 
					    min.dialogs.add(
 | 
				
			||||||
| 
						 | 
					@ -99,11 +99,11 @@ export class FeedbackDialog extends IGBDialog {
 | 
				
			||||||
          } else {
 | 
					          } else {
 | 
				
			||||||
            await min.conversationalService.sendText(min, step, Messages[locale].please_wait_transfering);
 | 
					            await min.conversationalService.sendText(min, step, Messages[locale].please_wait_transfering);
 | 
				
			||||||
            const agentSystemId = await sec.assignHumanAgent(min, from);
 | 
					            const agentSystemId = await sec.assignHumanAgent(min, from);
 | 
				
			||||||
            
 | 
					
 | 
				
			||||||
            await min.userProfile.set(step.context, profile);
 | 
					            await min.userProfile.set(step.context, profile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (agentSystemId.indexOf('@') !== -1) {
 | 
					            if (agentSystemId.indexOf('@') !== -1) {
 | 
				
			||||||
              
 | 
					
 | 
				
			||||||
              // Agent is from Teams or Google Chat.
 | 
					              // Agent is from Teams or Google Chat.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
              const agent = await sec.getUserFromSystemId(agentSystemId);
 | 
					              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(userSystemId, min.instance.instanceId, null);
 | 
				
			||||||
            await sec.updateHumanAgent(manualUser.userSystemId, min.instance.instanceId, null);
 | 
					            await sec.updateHumanAgent(manualUser.userSystemId, min.instance.instanceId, null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            
 | 
					
 | 
				
			||||||
          } else if (user.agentMode === 'human') {
 | 
					          } else if (user.agentMode === 'human') {
 | 
				
			||||||
            const agent = await sec.getUserFromSystemId(user.agentSystemId);
 | 
					            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(user.userSystemId, min.instance.instanceId, null);
 | 
				
			||||||
            await sec.updateHumanAgent(agent.userSystemId, min.instance.instanceId, null);
 | 
					            await sec.updateHumanAgent(agent.userSystemId, min.instance.instanceId, null);
 | 
				
			||||||
            
 | 
					
 | 
				
			||||||
          } else {
 | 
					          } else {
 | 
				
			||||||
            if (user.userSystemId.charAt(2) === ':' || userSystemId.indexOf('@') > -1) {
 | 
					            if (user.userSystemId.charAt(2) === ':' || userSystemId.indexOf('@') > -1) {
 | 
				
			||||||
              // Agent is from Teams or Google Chat.
 | 
					              // Agent is from Teams or Google Chat.
 | 
				
			||||||
| 
						 | 
					@ -264,16 +264,19 @@ export class FeedbackDialog extends IGBDialog {
 | 
				
			||||||
        async step => {
 | 
					        async step => {
 | 
				
			||||||
          const fixedLocale = 'en-US';
 | 
					          const fixedLocale = 'en-US';
 | 
				
			||||||
          const user = await min.userProfile.get(step.context, {});
 | 
					          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 analytics = new AnalyticsService();
 | 
				
			||||||
          const rate = await analytics.updateConversationSuggestion(
 | 
					            let rate = await analytics.updateConversationSuggestion(
 | 
				
			||||||
            min.instance.instanceId,
 | 
					              min.instance.instanceId,
 | 
				
			||||||
            user.conversation.conversationId,
 | 
					              user.conversation.conversationId,
 | 
				
			||||||
            step.result,
 | 
					              step.result,
 | 
				
			||||||
            user.locale
 | 
					              user.locale
 | 
				
			||||||
          );
 | 
					            );
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          if (rate > 0.5) {
 | 
					          if (rate > 0.5) {
 | 
				
			||||||
            await min.conversationalService.sendText(min, step, Messages[fixedLocale].glad_you_liked);
 | 
					            await min.conversationalService.sendText(min, step, Messages[fixedLocale].glad_you_liked);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -39,7 +39,6 @@ import { GBMinInstance, IGBDialog } from 'botlib';
 | 
				
			||||||
import { BotAdapter } from 'botbuilder';
 | 
					import { BotAdapter } from 'botbuilder';
 | 
				
			||||||
import { WaterfallDialog } from 'botbuilder-dialogs';
 | 
					import { WaterfallDialog } from 'botbuilder-dialogs';
 | 
				
			||||||
import { AnalyticsService } from '../../analytics.gblib/services/AnalyticsService.js';
 | 
					import { AnalyticsService } from '../../analytics.gblib/services/AnalyticsService.js';
 | 
				
			||||||
import { GBConversationalService } from '../../core.gbapp/services/GBConversationalService.js';
 | 
					 | 
				
			||||||
import { CSService } from '../services/CSService.js';
 | 
					import { CSService } from '../services/CSService.js';
 | 
				
			||||||
import { Messages } from '../strings.js';
 | 
					import { Messages } from '../strings.js';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -53,7 +52,7 @@ export class QualityDialog extends IGBDialog {
 | 
				
			||||||
   * @param bot The bot adapter.
 | 
					   * @param bot The bot adapter.
 | 
				
			||||||
   * @param min The minimal bot instance data.
 | 
					   * @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();
 | 
					    const service = new CSService();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    min.dialogs.add(
 | 
					    min.dialogs.add(
 | 
				
			||||||
| 
						 | 
					@ -89,15 +88,15 @@ export class QualityDialog extends IGBDialog {
 | 
				
			||||||
            await service.insertQuestionAlternate(min.instance.instanceId, user.lastQuestion, user.lastQuestionId);
 | 
					            await service.insertQuestionAlternate(min.instance.instanceId, user.lastQuestion, user.lastQuestionId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Updates values to perform Bot Analytics.
 | 
					            // Updates values to perform Bot Analytics.
 | 
				
			||||||
 | 
					            if (process.env.PRIVACY_STORE_MESSAGES === 'true') {
 | 
				
			||||||
            const analytics = new AnalyticsService();
 | 
					              const analytics = new AnalyticsService();
 | 
				
			||||||
            analytics.updateConversationSuggestion(
 | 
					              analytics.updateConversationSuggestion(
 | 
				
			||||||
              min.instance.instanceId,
 | 
					                min.instance.instanceId,
 | 
				
			||||||
              user.conversation,
 | 
					                user.conversation,
 | 
				
			||||||
              step.result,
 | 
					                step.result,
 | 
				
			||||||
              user.locale
 | 
					                user.locale
 | 
				
			||||||
            );
 | 
					              );
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            // Goes to the ask loop.
 | 
					            // Goes to the ask loop.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return await step.replaceDialog('/ask', { emptyPrompt: true });
 | 
					            return await step.replaceDialog('/ask', { emptyPrompt: true });
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue