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 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);
|
||||
|
||||
return await step.endDialog(true);
|
||||
|
@ -208,7 +208,7 @@ export class AdminDialog extends IGBDialog {
|
|||
await step.beginDialog('/admin-auth');
|
||||
}
|
||||
else {
|
||||
step.next(true);
|
||||
await step.next(true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -224,7 +224,7 @@ export class AdminDialog extends IGBDialog {
|
|||
}
|
||||
|
||||
const botId = min.instance.botId;
|
||||
|
||||
|
||||
await min.conversationalService.sendText(min, step, Messages[locale].working('Publishing'));
|
||||
|
||||
step.activeDialog.state.options.args = (step.options as any).args;
|
||||
|
|
|
@ -89,16 +89,13 @@ export class GBConversationalService {
|
|||
public getCurrentLanguage(step: GBDialogStep) {
|
||||
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> {
|
||||
|
||||
|
||||
if (step !== null) {
|
||||
mobile = step.context.activity.from.id;
|
||||
if (GBConversationalService.getChannel(step) === 'whatsapp') {
|
||||
if (!isNaN(step.context.activity.from.id as any)) {
|
||||
GBLog.info(`Sending file ${url} to ${step.context.activity.from.id}...`)
|
||||
const filename = url.substring(url.lastIndexOf('/') + 1);
|
||||
await min.whatsAppDirectLine.sendFileToDevice(mobile, url, filename, caption);
|
||||
|
@ -108,6 +105,12 @@ export class GBConversationalService {
|
|||
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> {
|
||||
|
@ -600,7 +603,13 @@ export class GBConversationalService {
|
|||
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 {
|
||||
// tslint:disable-next-line: await-promise
|
||||
const result = await request.post(options);
|
||||
GBLog.info(result);
|
||||
GBLog.info( `File ${url} sent to ${to}: ${result}`);
|
||||
} catch (error) {
|
||||
GBLog.error(`Error sending file to Whatsapp provider ${error.message}`);
|
||||
}
|
||||
|
@ -392,7 +392,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
try {
|
||||
// tslint:disable-next-line: await-promise
|
||||
const result = await request.post(options);
|
||||
GBLog.info(result);
|
||||
GBLog.info( `Audio ${url} sent to ${to}: ${result}`);
|
||||
} catch (error) {
|
||||
GBLog.error(`Error sending audio message to Whatsapp provider ${error.message}`);
|
||||
}
|
||||
|
@ -444,7 +444,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
try {
|
||||
// tslint:disable-next-line: await-promise
|
||||
const result = await request.post(options);
|
||||
GBLog.info(result);
|
||||
GBLog.info( `Message [${msg}] sent to ${to}: ${result}`);
|
||||
} catch (error) {
|
||||
GBLog.error(`Error sending message to Whatsapp provider ${error.message}`);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue