Skip to content

Commit

Permalink
fix(core.gbapp): SMS fix, Timezone on BASIC NOW, Order of welcome msg…
Browse files Browse the repository at this point in the history
…. fixed.
  • Loading branch information
rodrigorodriguez committed Nov 30, 2020
1 parent 482f465 commit 18b8bd9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 14 deletions.
13 changes: 9 additions & 4 deletions packages/core.gbapp/services/GBAPIService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,12 +468,17 @@ export class DialogClass {
return [year, month, day].join('/');
}
}

public async isAffirmative(step, text) {
return text.toLowerCase().match(Messages[step.context.activity.locale].affirmative_sentences);
}

public async getNow(step) {
var d = new Date();
return d.getHours() + ':' + d.getMinutes();
const nowUTC = new Date();
const now = new Date((typeof nowUTC === "string" ?
new Date(nowUTC) :
nowUTC).toLocaleString("en-US", {timeZone: process.env.DEFAULT_TIMEZONE}));

// TODO: Choose Fuse with country code or consent IP.
return now.getHours() + ':' + now.getMinutes();
}

public async sendFileTo(step, mobile, filename, caption) {
Expand Down
10 changes: 7 additions & 3 deletions packages/core.gbapp/services/GBConversationalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,10 @@ export class GBConversationalService {
});
// tslint:disable-next-line:no-unsafe-any
nexmo.message.sendSms(min.instance.smsServiceNumber, mobile, text, (err, data) => {
if (data.messages[0]['error-text']) {
GBLog.error(`BASIC: error sending SMS to ${mobile}: ${data.messages[0]['error-text']}`);
reject(data.messages[0]['error-text']);
const message = data.messages ? data.messages[0] : {};
if (err || message['error-text']) {
GBLog.error(`BASIC: error sending SMS to ${mobile}: ${message['error-text']}`);
reject(message['error-text']);
} else {
resolve(data);
}
Expand Down Expand Up @@ -467,6 +468,9 @@ export class GBConversationalService {
return false;
}

text = text.toLowerCase().replace('who\'s', 'who is');
text = text.toLowerCase().replace('what\'s', 'what is');

const model = new LuisRecognizer({
applicationId: min.instance.nlpAppId,
endpointKey: min.instance.nlpKey,
Expand Down
34 changes: 29 additions & 5 deletions packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,18 @@ export class GBMinService {
await sec.updateUserInstance(id, instance.instanceId);

await (activeMin as any).whatsAppDirectLine.resetConversationId(id);
await (activeMin as any).whatsAppDirectLine.sendToDevice(
id,
`Agora falando com ${activeMin.instance.title}...`
);

let startDialog = activeMin.core.getParam(activeMin.instance, 'Start Dialog', null);
GBLog.info(`Auto start dialog is now being called: ${startDialog}...`);

if (startDialog) {
req.body.messages[0].body = `${startDialog}`;
await (activeMin as any).whatsAppDirectLine.received(req, res);
}
else {
await (activeMin as any).whatsAppDirectLine.sendToDevice(
id,
`Agora falando com ${activeMin.instance.title}...`
);
res.end();
}
} else {
Expand Down Expand Up @@ -797,6 +797,14 @@ export class GBMinService {
});
}
text = await min.conversationalService.spellCheck(min, text);
if (keepText) {
const list = keepText.split(';');
let i = 0;
await CollectionUtil.asyncForEach(list, item => {
i++;
text = text.replace(`KEEPTEXT${i}`, item.trim());
});
}
// Detects user typed language and updates their locale profile if applies.

let locale = min.core.getParam<string>(
Expand Down Expand Up @@ -828,12 +836,28 @@ export class GBMinService {

// Translates the input text if is turned on instance params.

if (keepText) {
const list = keepText.split(';');
let i = 0;
await CollectionUtil.asyncForEach(list, item => {
i++;
text = text.replace(new RegExp(item.trim(), 'gi'), `KEEPTEXT${i}`);
});
}

let contentLocale = min.core.getParam<string>(
min.instance,
'Default Content Language',
GBConfigService.get('DEFAULT_CONTENT_LANGUAGE')
);
if (keepText) {
const list = keepText.split(';');
let i = 0;
await CollectionUtil.asyncForEach(list, item => {
i++;
text = text.replace(new RegExp(item.trim(), 'gi'), `KEEPTEXT${i}`);
});
}

text = await min.conversationalService.translate(min, text, contentLocale);
if (keepText) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core.gbapp/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const Messages = {
which_language: "Please, type the language name you would like to talk through.",
validation_enter_valid_email: "Please enter a valid e-mail." ,
language_chosen: "Very good, so let's go..." ,
affirmative_sentences: /^(sim|s|positivo|afirmativo|claro|evidente|sem dúvida|confirmo|confirmar|confirmado|uhum)/i,
affirmative_sentences: /^(sim|s|positivo|afirmativo|claro|evidente|sem dúvida|confirmo|confirmar|confirmado|uhum|si|y|yes|sure)/i,

},
'pt-BR': {
Expand All @@ -28,7 +28,7 @@ export const Messages = {
which_language: "Por favor, digite o idioma que você gostaria de usar para conversarmos.",
validation_enter_valid_email: "Por favor digite um email válido.",
language_chosen: "Muito bem, então vamos lá..." ,
affirmative_sentences: /^(sim|s|positivo|afirmativo|claro|evidente|sem dúvida|confirmo|confirmar|confirmado|uhum)/i,
affirmative_sentences: /^(sim|s|positivo|afirmativo|claro|evidente|sem dúvida|confirmo|confirmar|confirmado|uhum|si|y|yes|sure)/i,

}
};

0 comments on commit 18b8bd9

Please sign in to comment.