Skip to content

Commit

Permalink
fix(whatsapp.gblib): Fix of missing mobile number.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Jun 5, 2020
1 parent 1d316ef commit 6306274
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
19 changes: 10 additions & 9 deletions packages/core.gbapp/services/GBConversationalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ export class GBConversationalService {

if (step !== null) {
if (!isNaN(step.context.activity.from.id as any)) {
GBLog.info(`Sending file ${url} to ${step.context.activity.from.id}...`)
mobile = step.context.activity.from.id;
GBLog.info(`Sending file ${url} to ${mobile}...`)
const filename = url.substring(url.lastIndexOf('/') + 1);
await min.whatsAppDirectLine.sendFileToDevice(mobile, url, filename, caption);
}
Expand Down Expand Up @@ -348,7 +349,7 @@ export class GBConversationalService {
await step.context.sendActivity(currentText);
}
else {
this.sendToMobile(min, mobile, currentText);
await this.sendToMobile(min, mobile, currentText);
}
await sleep(3000);
currentText = '';
Expand All @@ -371,7 +372,7 @@ export class GBConversationalService {
await step.context.sendActivity(currentText);
}
else {
this.sendToMobile(min, mobile, currentText);
await this.sendToMobile(min, mobile, currentText);
}
await sleep(3000);
}
Expand Down Expand Up @@ -404,9 +405,9 @@ export class GBConversationalService {
await step.context.sendActivity(currentText);
}
else {
this.sendToMobile(min, mobile, currentText);
await this.sendToMobile(min, mobile, currentText);
}
await sleep(3000);
await sleep(2900);
}
currentText = '';
state = State.InImageCaption;
Expand Down Expand Up @@ -435,7 +436,7 @@ export class GBConversationalService {
let url = urlJoin(GBServer.globals.publicAddress, currentImage);
await this.sendFile(min, step, mobile, url, currentCaption);
currentCaption = '';
await sleep(5000);
await sleep(4500);
currentImage = '';
}
else {
Expand All @@ -451,7 +452,7 @@ export class GBConversationalService {

}
else {
this.sendToMobile(min, mobile, currentText);
await this.sendToMobile(min, mobile, currentText);
}
}
}
Expand Down Expand Up @@ -590,7 +591,7 @@ export class GBConversationalService {
const user = await sec.ensureUser(min.instance.instanceId, member.id,
member.name, "", "web", member.name);
if (text !== null) {
text = await min.conversationalService.translate(min,
text = await min.conversationalService.translate(min,
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
text,
Expand All @@ -606,7 +607,7 @@ export class GBConversationalService {
const user = await min.userProfile.get(step.context, {});
if (user) {
const minBoot = GBServer.globals.minBoot as any;
text = await min.conversationalService.translate(min,
text = await min.conversationalService.translate(min,
min.instance.translatorKey ? min.instance.translatorKey : minBoot.instance.translatorKey,
min.instance.translatorEndpoint ? min.instance.translatorEndpoint : minBoot.instance.translatorEndpoint,
text,
Expand Down
22 changes: 14 additions & 8 deletions packages/kb.gbapp/services/KBService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ export class KBService implements IGBKBService {

public async sendAnswer(min: GBMinInstance, channel: string, step: GBDialogStep, answer: GuaribasAnswer) {
if (answer.content.endsWith('.mp4')) {
await this.playVideo(min, min.conversationalService, step, answer);
await this.playVideo(min, min.conversationalService, step, answer, channel);
}
else if (answer.format === '.md') {

Expand Down Expand Up @@ -433,21 +433,22 @@ export class KBService implements IGBKBService {
// MSFT Translator breaks markdown, so we need to fix it:

text = text.replace('! [', '![').replace('] (', '](');
text = text.replace(`[[embed url=`, process.env.BOT_URL + '/').replace(']]', ''); // TODO: Improve it.

const html = marked(text);
let html = text.replace(`[[embed url=`, process.env.BOT_URL + '/').replace(']]', ''); // TODO: Improve it.

// According to the channel, formats the output optimized to it.

if (channel === 'webchat' &&
GBConfigService.get('DISABLE_WEB') !== 'true') {
html = marked(text);
await this.sendMarkdownToWeb(min, step, conversationalService, html, answer);
}
else if (channel === 'whatsapp') {

await conversationalService.sendMarkdownToMobile(min, step, user.userSystemId, text);
}
else {
html = marked(text);
await min.conversationalService.sendText(min, step, html);
}
}
Expand Down Expand Up @@ -481,11 +482,16 @@ export class KBService implements IGBKBService {
}


private async playVideo(min, conversationalService: IGBConversationalService, step: GBDialogStep, answer: GuaribasAnswer) {
await conversationalService.sendEvent(min, step, 'play', {
playerType: 'video',
data: answer.content
});
private async playVideo(min, conversationalService: IGBConversationalService,
step: GBDialogStep, answer: GuaribasAnswer, channel: string) {
if (channel === "whatsapp") {
await min.conversationalService.sendFile(min, step, null, answer.content, "");
} else {
await conversationalService.sendEvent(min, step, 'play', {
playerType: 'video',
data: answer.content
});
}
}

public async importKbPackage(
Expand Down
2 changes: 1 addition & 1 deletion packages/whatsapp.gblib/services/WhatsappDirectLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ export class WhatsappDirectLine extends GBService {

}

public async sendToDevice(to, msg) {
public async sendToDevice(to: string, msg: string) {

const cmd = '/audio ';
if (msg.startsWith(cmd)) {
Expand Down

0 comments on commit 6306274

Please sign in to comment.