fix(whatsapp.gblib): Send file now working again.
This commit is contained in:
parent
821842c317
commit
3abe85ca30
3 changed files with 22 additions and 13 deletions
|
@ -88,7 +88,7 @@ export class AdminDialog extends IGBDialog {
|
||||||
const locale = step.context.activity.locale;
|
const locale = step.context.activity.locale;
|
||||||
const sensitive = step.result;
|
const sensitive = step.result;
|
||||||
|
|
||||||
if (sensitive === process.env.ADMIN_PASS ) { // TODO: Per bot: min.instance.adminPass
|
if (sensitive === process.env.ADMIN_PASS) { // TODO: Per bot: min.instance.adminPass
|
||||||
await min.conversationalService.sendText(min, step, Messages[locale].welcome);
|
await min.conversationalService.sendText(min, step, Messages[locale].welcome);
|
||||||
|
|
||||||
return await step.endDialog(true);
|
return await step.endDialog(true);
|
||||||
|
@ -208,7 +208,7 @@ export class AdminDialog extends IGBDialog {
|
||||||
await step.beginDialog('/admin-auth');
|
await step.beginDialog('/admin-auth');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
step.next(true);
|
await step.next(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -89,16 +89,13 @@ export class GBConversationalService {
|
||||||
public getCurrentLanguage(step: GBDialogStep) {
|
public getCurrentLanguage(step: GBDialogStep) {
|
||||||
return step.context.activity.locale;
|
return step.context.activity.locale;
|
||||||
}
|
}
|
||||||
private static getChannel(step): string {
|
|
||||||
return !isNaN(step.context.activity.from.id) ? 'whatsapp' : step.context.activity.channelId;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public async sendFile(min: GBMinInstance, step: GBDialogStep, mobile: string, url: string, caption: string): Promise<any> {
|
public async sendFile(min: GBMinInstance, step: GBDialogStep, mobile: string, url: string, caption: string): Promise<any> {
|
||||||
|
|
||||||
if (step !== null) {
|
if (step !== null) {
|
||||||
mobile = step.context.activity.from.id;
|
if (!isNaN(step.context.activity.from.id as any)) {
|
||||||
if (GBConversationalService.getChannel(step) === 'whatsapp') {
|
|
||||||
GBLog.info(`Sending file ${url} to ${step.context.activity.from.id}...`)
|
GBLog.info(`Sending file ${url} to ${step.context.activity.from.id}...`)
|
||||||
const filename = url.substring(url.lastIndexOf('/') + 1);
|
const filename = url.substring(url.lastIndexOf('/') + 1);
|
||||||
await min.whatsAppDirectLine.sendFileToDevice(mobile, url, filename, caption);
|
await min.whatsAppDirectLine.sendFileToDevice(mobile, url, filename, caption);
|
||||||
|
@ -108,6 +105,12 @@ export class GBConversationalService {
|
||||||
await min.conversationalService.sendText(min, step, url);
|
await min.conversationalService.sendText(min, step, url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GBLog.info(`Sending file ${url} to ${mobile}...`)
|
||||||
|
const filename = url.substring(url.lastIndexOf('/') + 1);
|
||||||
|
await min.whatsAppDirectLine.sendFileToDevice(mobile, url, filename, caption);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendAudio(min: GBMinInstance, step: GBDialogStep, url: string): Promise<any> {
|
public async sendAudio(min: GBMinInstance, step: GBDialogStep, url: string): Promise<any> {
|
||||||
|
@ -600,7 +603,13 @@ export class GBConversationalService {
|
||||||
user.locale ? user.locale : 'pt'
|
user.locale ? user.locale : 'pt'
|
||||||
);
|
);
|
||||||
|
|
||||||
await step.context.sendActivity(text);
|
if (!isNaN(member.id)) {
|
||||||
|
await min.whatsAppDirectLine.sendToDevice(member.id, text);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await step.context.sendActivity(text);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -369,7 +369,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
try {
|
try {
|
||||||
// tslint:disable-next-line: await-promise
|
// tslint:disable-next-line: await-promise
|
||||||
const result = await request.post(options);
|
const result = await request.post(options);
|
||||||
GBLog.info(result);
|
GBLog.info( `File ${url} sent to ${to}: ${result}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
GBLog.error(`Error sending file to Whatsapp provider ${error.message}`);
|
GBLog.error(`Error sending file to Whatsapp provider ${error.message}`);
|
||||||
}
|
}
|
||||||
|
@ -392,7 +392,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
try {
|
try {
|
||||||
// tslint:disable-next-line: await-promise
|
// tslint:disable-next-line: await-promise
|
||||||
const result = await request.post(options);
|
const result = await request.post(options);
|
||||||
GBLog.info(result);
|
GBLog.info( `Audio ${url} sent to ${to}: ${result}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
GBLog.error(`Error sending audio message to Whatsapp provider ${error.message}`);
|
GBLog.error(`Error sending audio message to Whatsapp provider ${error.message}`);
|
||||||
}
|
}
|
||||||
|
@ -444,7 +444,7 @@ export class WhatsappDirectLine extends GBService {
|
||||||
try {
|
try {
|
||||||
// tslint:disable-next-line: await-promise
|
// tslint:disable-next-line: await-promise
|
||||||
const result = await request.post(options);
|
const result = await request.post(options);
|
||||||
GBLog.info(result);
|
GBLog.info( `Message [${msg}] sent to ${to}: ${result}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
GBLog.error(`Error sending message to Whatsapp provider ${error.message}`);
|
GBLog.error(`Error sending message to Whatsapp provider ${error.message}`);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue