From cfe3ab30f47af4f5c058c1de4c7707140fbc2312 Mon Sep 17 00:00:00 2001 From: rodrigorodriguez Date: Tue, 7 Mar 2023 10:01:36 -0300 Subject: [PATCH] fix(whatsapp.gblib): #309 unify channel detection. --- packages/core.gbapp/services/GBMinService.ts | 5 +++++ .../services/WhatsappDirectLine.ts | 16 ++-------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 31a7fa4a..9dcf4797 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -831,6 +831,11 @@ export class GBMinService { adapter = min['fbAdapter']; } + // Unifies channel detection. + + req.body.channelId = + (req.body.from.channelIdEx === 'whatsapp' ? 'omnichannel' : req.body.channelId); + // Default activity processing and handler. await adapter['processActivity'](req, res, async context => { diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index cd1e287c..bd2c020f 100644 --- a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts +++ b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts @@ -113,18 +113,6 @@ export class WhatsappDirectLine extends GBService { } } - public async sendButton(number) { - let url = 'https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE1Mu3b?ver=5c31'; - const media = await MessageMedia.fromUrl(url, {unsafeMime: true}); - media.mimetype = 'image/png'; - media.filename = 'hello.png'; - let btnClickableMenu = new Buttons(media as any, [ - { id: 'customId', body: 'button1' }, { body: 'button2' }, - { body: 'button3' }, { body: 'button4' }, - { body: 'button4' }, { body: 'button6' }, - ]); - await this.sendToDevice(number, btnClickableMenu as any, null); - } public async setup(setUrl: boolean) { const client = await new SwaggerClient({ spec: JSON.parse(Fs.readFileSync('directline-3.0.json', 'utf8')), @@ -180,12 +168,11 @@ export class WhatsappDirectLine extends GBService { }).bind(this) ); client.on('authenticated', async () => { - GBLog.verbose(`GBWhatsApp: QR Code authenticated for ${this.botId}.`); }); client.on('ready', async () => { GBLog.verbose(`GBWhatsApp: Emptying chat list for ${this.botId}...`); - + // Keeps the chat list cleaned. const chats = await client.getChats(); await CollectionUtil.asyncForEach(chats, async chat => { @@ -630,6 +617,7 @@ export class WhatsappDirectLine extends GBService { attachments: attachments, from: { id: from, + channelIdEx: 'whatsapp', name: fromName }, replyToId: from