Skip to content

Commit

Permalink
fix(whatsapp.gblib): #309 unify channel detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Mar 7, 2023
1 parent 565ad4a commit cfe3ab3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
5 changes: 5 additions & 0 deletions packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
16 changes: 2 additions & 14 deletions packages/whatsapp.gblib/services/WhatsappDirectLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -630,6 +617,7 @@ export class WhatsappDirectLine extends GBService {
attachments: attachments,
from: {
id: from,
channelIdEx: 'whatsapp',
name: fromName
},
replyToId: from
Expand Down

0 comments on commit cfe3ab3

Please sign in to comment.