fix(whatsapp.gblib): Fix in bot switching.
This commit is contained in:
parent
6c4a546202
commit
929b36d578
2 changed files with 34 additions and 11 deletions
|
@ -803,6 +803,11 @@ export class GBMinService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const botNumber = min.core.getParam<string>(min.instance, 'Bot Number', null);
|
||||||
|
if (botNumber){
|
||||||
|
WhatsappDirectLine.botsByNumber[botNumber] = min.whatsAppDirectLine;
|
||||||
|
}
|
||||||
|
|
||||||
// Setups default BOT Framework dialogs.
|
// Setups default BOT Framework dialogs.
|
||||||
|
|
||||||
min.userProfile = conversationState.createProperty('userProfile');
|
min.userProfile = conversationState.createProperty('userProfile');
|
||||||
|
|
|
@ -58,6 +58,7 @@ const { List, Buttons, Client, MessageMedia } = pkg;
|
||||||
*/
|
*/
|
||||||
export class WhatsappDirectLine extends GBService {
|
export class WhatsappDirectLine extends GBService {
|
||||||
public static conversationIds = {};
|
public static conversationIds = {};
|
||||||
|
public static botsByNumber = {};
|
||||||
public static mobiles = {};
|
public static mobiles = {};
|
||||||
public static phones = {};
|
public static phones = {};
|
||||||
public static chatIds = {};
|
public static chatIds = {};
|
||||||
|
@ -303,14 +304,31 @@ export class WhatsappDirectLine extends GBService {
|
||||||
public async received(req, res) {
|
public async received(req, res) {
|
||||||
const provider = WhatsappDirectLine.providerFromRequest(req);
|
const provider = WhatsappDirectLine.providerFromRequest(req);
|
||||||
|
|
||||||
let message, from, fromName, text: string;
|
let message, to, from, fromName, text: string;
|
||||||
let group = '';
|
let group = '';
|
||||||
let answerText = null;
|
let answerText = null;
|
||||||
let attachments = null;
|
let attachments = null;
|
||||||
|
|
||||||
|
|
||||||
switch (provider) {
|
switch (provider) {
|
||||||
case 'GeneralBots':
|
case 'GeneralBots':
|
||||||
|
|
||||||
message = req;
|
message = req;
|
||||||
|
to = message.to.endsWith('@g.us') ? message.to.split('@')[0] : message.to.split('@')[0];
|
||||||
|
const newThis= WhatsappDirectLine.botsByNumber[to];
|
||||||
|
if (newThis === undefined){
|
||||||
|
throw GBError.create(`Bot Number ${to} not setup for any loaded bot.`);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (newThis.min.botId !== this.min.botId)
|
||||||
|
{
|
||||||
|
await newThis.received (req, res);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
text = message.body;
|
text = message.body;
|
||||||
from = message.from.endsWith('@g.us') ? message.author.split('@')[0] : message.from.split('@')[0];
|
from = message.from.endsWith('@g.us') ? message.author.split('@')[0] : message.from.split('@')[0];
|
||||||
fromName = message._data.notifyName;
|
fromName = message._data.notifyName;
|
||||||
|
|
Loading…
Add table
Reference in a new issue