diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index 2023621e..36af8a0e 100644 --- a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts +++ b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts @@ -227,11 +227,12 @@ export class WhatsappDirectLine extends GBService { const express = require('express'); GBServer.globals.server.use(`/audios`, express.static('work')); - - try { - const res = await request.post(options); - } catch (error) { - GBLog.error(`Error initializing 3rd party Whatsapp provider(1) ${error.message}`); + if (options) { + try { + await request.post(options); + } catch (error) { + GBLog.error(`Error initializing 3rd party Whatsapp provider(1) ${error.message}`); + } } } } @@ -698,12 +699,14 @@ export class WhatsappDirectLine extends GBService { break; } - try { - // tslint:disable-next-line: await-promise - const result = await request.post(options); - GBLog.info(`File ${url} sent to ${to}: ${result}`); - } catch (error) { - GBLog.error(`Error sending file to Whatsapp provider ${error.message}`); + if (options) { + try { + // tslint:disable-next-line: await-promise + const result = await request.post(options); + GBLog.info(`File ${url} sent to ${to}: ${result}`); + } catch (error) { + GBLog.error(`Error sending file to Whatsapp provider ${error.message}`); + } } } @@ -742,13 +745,13 @@ export class WhatsappDirectLine extends GBService { break; } - try { - - // tslint:disable-next-line: await-promise - const result = await request.post(options); - GBLog.info(`Audio ${url} sent to ${to}: ${result}`); - } catch (error) { - GBLog.error(`Error sending audio message to Whatsapp provider ${error.message}`); + if (options) { + try { + const result = await request.post(options); + GBLog.info(`Audio ${url} sent to ${to}: ${result}`); + } catch (error) { + GBLog.error(`Error sending audio message to Whatsapp provider ${error.message}`); + } } } @@ -817,16 +820,16 @@ export class WhatsappDirectLine extends GBService { break; } - try { - GBLog.info(`Message [${msg}] is being sent to ${to}...`); - // tslint:disable-next-line: await-promise - if (this.provider !== "GeneralBots") { + if (options) { + try { + GBLog.info(`Message [${msg}] is being sent to ${to}...`); await request.post(options); } - } catch (error) { - GBLog.error(`Error sending message to Whatsapp provider ${error.message}`); + catch (error) { + 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. + } } } }