fix(whatsapp.gblib): .gbapp message subprocessing.

This commit is contained in:
Rodrigo Rodriguez 2022-09-02 10:32:07 -03:00
parent e72b030e95
commit c14a766047

View file

@ -227,14 +227,15 @@ export class WhatsappDirectLine extends GBService {
const express = require('express'); const express = require('express');
GBServer.globals.server.use(`/audios`, express.static('work')); GBServer.globals.server.use(`/audios`, express.static('work'));
if (options) {
try { try {
const res = await request.post(options); await request.post(options);
} catch (error) { } catch (error) {
GBLog.error(`Error initializing 3rd party Whatsapp provider(1) ${error.message}`); GBLog.error(`Error initializing 3rd party Whatsapp provider(1) ${error.message}`);
} }
} }
} }
}
public async resetConversationId(botId, number, group = '') { public async resetConversationId(botId, number, group = '') {
WhatsappDirectLine.conversationIds[botId + number + group] = undefined; WhatsappDirectLine.conversationIds[botId + number + group] = undefined;
@ -698,6 +699,7 @@ export class WhatsappDirectLine extends GBService {
break; break;
} }
if (options) {
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);
@ -706,6 +708,7 @@ export class WhatsappDirectLine extends GBService {
GBLog.error(`Error sending file to Whatsapp provider ${error.message}`); GBLog.error(`Error sending file to Whatsapp provider ${error.message}`);
} }
} }
}
public async sendAudioToDevice(to, url, chatId) { public async sendAudioToDevice(to, url, chatId) {
@ -742,15 +745,15 @@ export class WhatsappDirectLine extends GBService {
break; break;
} }
if (options) {
try { try {
// tslint:disable-next-line: await-promise
const result = await request.post(options); const result = await request.post(options);
GBLog.info(`Audio ${url} sent to ${to}: ${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}`);
} }
} }
}
public async sendTextAsAudioToDevice(to, msg, chatId) { public async sendTextAsAudioToDevice(to, msg, chatId) {
@ -817,19 +820,19 @@ export class WhatsappDirectLine extends GBService {
break; break;
} }
if (options) {
try { try {
GBLog.info(`Message [${msg}] is being sent to ${to}...`); GBLog.info(`Message [${msg}] is being sent to ${to}...`);
// tslint:disable-next-line: await-promise
if (this.provider !== "GeneralBots") {
await request.post(options); await request.post(options);
} }
} catch (error) { catch (error) {
GBLog.error(`Error sending message to Whatsapp provider ${error.message}`); GBLog.error(`Error sending message to Whatsapp provider ${error.message}`);
// TODO: Handle Error: socket hang up and retry. // TODO: Handle Error: socket hang up and retry.
} }
} }
} }
}
public async sendToDeviceEx(to, text, locale, conversationId) { public async sendToDeviceEx(to, text, locale, conversationId) {
text = await this.min.conversationalService.translate( text = await this.min.conversationalService.translate(