Skip to content

Commit

Permalink
fix(whatsapp.gblib): Fix PRIVACY_STORE_MESSAGES param.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed May 11, 2024
1 parent b301b23 commit 99b5b8b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 38 deletions.
15 changes: 8 additions & 7 deletions packages/core.gbapp/services/GBConversationalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 9 additions & 7 deletions packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
29 changes: 16 additions & 13 deletions packages/customer-satisfaction.gbapp/dialogs/FeedbackDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
21 changes: 10 additions & 11 deletions packages/customer-satisfaction.gbapp/dialogs/QualityDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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(
Expand Down Expand Up @@ -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 });
Expand Down

0 comments on commit 99b5b8b

Please sign in to comment.