fix(all): Fix user switching on a single chip.
This commit is contained in:
parent
c577b64369
commit
da02804ac9
1 changed files with 125 additions and 130 deletions
|
@ -198,8 +198,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
};
|
||||
if (setUrl) {
|
||||
createClient.bind(this)();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this.customClient = minBoot.whatsAppDirectLine.customClient;
|
||||
}
|
||||
setUrl = false;
|
||||
|
@ -309,21 +308,16 @@ export class WhatsappDirectLine extends GBService {
|
|||
let answerText = null;
|
||||
let attachments = null;
|
||||
|
||||
|
||||
switch (provider) {
|
||||
case 'GeneralBots':
|
||||
|
||||
message = req;
|
||||
to = message.to.endsWith('@g.us') ? message.to.split('@')[0] : message.to.split('@')[0];
|
||||
const newThis= WhatsappDirectLine.botsByNumber[to];
|
||||
if (newThis === undefined){
|
||||
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);
|
||||
} else {
|
||||
if (newThis.min.botId !== this.min.botId) {
|
||||
await newThis.received(req, res);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -336,9 +330,14 @@ export class WhatsappDirectLine extends GBService {
|
|||
if (message.hasMedia) {
|
||||
const base64Image = await message.downloadMedia();
|
||||
|
||||
let buf: any = Buffer.from(base64Image.data, "base64");
|
||||
let buf: any = Buffer.from(base64Image.data, 'base64');
|
||||
const gbaiName = DialogKeywords.getGBAIPath(this.min.botId);
|
||||
const localName = Path.join('work', gbaiName, 'cache', `tmp${GBAdminService.getRndReadableIdentifier()}.docx`);
|
||||
const localName = Path.join(
|
||||
'work',
|
||||
gbaiName,
|
||||
'cache',
|
||||
`tmp${GBAdminService.getRndReadableIdentifier()}.docx`
|
||||
);
|
||||
Fs.writeFileSync(localName, buf, { encoding: null });
|
||||
const url = urlJoin(GBServer.globals.publicAddress, this.min.botId, 'cache', Path.basename(localName));
|
||||
|
||||
|
@ -546,7 +545,6 @@ export class WhatsappDirectLine extends GBService {
|
|||
);
|
||||
|
||||
if (user.agentSystemId.indexOf('@') !== -1) {
|
||||
|
||||
// Agent is from Teams.
|
||||
await this.min.conversationalService['sendOnConversation'](
|
||||
this.min,
|
||||
|
@ -584,7 +582,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
|
||||
const prompt = `the person said: ${text}. what can I tell her?`;
|
||||
const answer = await ChatServices.continue(this.min, prompt, 0);
|
||||
text = `${text} \n\nGeneral Bots: ${answer}`
|
||||
text = `${text} \n\nGeneral Bots: ${answer}`;
|
||||
|
||||
if (user.agentSystemId.indexOf('@') !== -1) {
|
||||
// Agent is from Teams or Google Chat.
|
||||
|
@ -627,11 +625,9 @@ export class WhatsappDirectLine extends GBService {
|
|||
}
|
||||
|
||||
private async endTransfer(id: string, locale: string, user: GuaribasUser, agent: GuaribasUser, sec: SecService) {
|
||||
|
||||
await this.sendToDeviceEx(id, Messages[this.locale].notify_end_transfer(this.min.instance.botId), locale, null);
|
||||
|
||||
if (user.agentSystemId.indexOf('@') !== -1) {
|
||||
|
||||
// Agent is from Teams.
|
||||
|
||||
await this.min.conversationalService['sendOnConversation'](
|
||||
|
@ -639,9 +635,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
agent,
|
||||
Messages[this.locale].notify_end_transfer(this.min.instance.botId)
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
await this.sendToDeviceEx(
|
||||
user.agentSystemId,
|
||||
Messages[this.locale].notify_end_transfer(this.min.instance.botId),
|
||||
|
@ -677,7 +671,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
}
|
||||
});
|
||||
} catch (e) {
|
||||
GBLog .error(e);
|
||||
GBLog.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -696,7 +690,8 @@ export class WhatsappDirectLine extends GBService {
|
|||
await this.printMessages(response.obj.activities, conversationId, from, fromName);
|
||||
} catch (err) {
|
||||
GBLog.error(
|
||||
`Error calling printMessages on Whatsapp channel ${err.data === undefined ? err : err.data} ${err.errObj ? err.errObj.message : ''
|
||||
`Error calling printMessages on Whatsapp channel ${err.data === undefined ? err : err.data} ${
|
||||
err.errObj ? err.errObj.message : ''
|
||||
}`
|
||||
);
|
||||
}
|
||||
|
@ -730,15 +725,13 @@ export class WhatsappDirectLine extends GBService {
|
|||
|
||||
if (activity.attachments) {
|
||||
await CollectionUtil.asyncForEach(activity.attachments, async attachment => {
|
||||
|
||||
switch (attachment.contentType) {
|
||||
case 'application/vnd.microsoft.card.hero':
|
||||
output += `\n${this.renderHeroCard(attachment)}`;
|
||||
break;
|
||||
|
||||
case 'image/png':
|
||||
await this.sendFileToDevice(to, attachment.contentUrl,
|
||||
attachment.name, attachment.name, 0);
|
||||
await this.sendFileToDevice(to, attachment.contentUrl, attachment.name, attachment.name, 0);
|
||||
|
||||
return;
|
||||
|
||||
|
@ -982,11 +975,9 @@ export class WhatsappDirectLine extends GBService {
|
|||
|
||||
switch (provider) {
|
||||
case 'GeneralBots':
|
||||
|
||||
// Ignore E2E messages and status updates.
|
||||
|
||||
if (req.type && req.type === 'e2e_notification'
|
||||
|| req.isStatus) {
|
||||
if ((req.type && req.type === 'e2e_notification') || req.isStatus) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1092,12 +1083,24 @@ export class WhatsappDirectLine extends GBService {
|
|||
|
||||
// Detects if the welcome message is enabled.
|
||||
|
||||
if (process.env.WHATSAPP_WELCOME_DISABLED !== 'true') {
|
||||
if (process.env.WHATSAPP_WELCOME_DISABLED === 'true') {
|
||||
let minInstance = GBServer.globals.minInstances.filter(
|
||||
p => p.instance.botId.toLowerCase() === botId.toLowerCase()
|
||||
)[0];
|
||||
|
||||
// Just pass the message to the receiver.
|
||||
|
||||
await minInstance.whatsAppDirectLine.received(req, res);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Tries to find if user wants to switch bots.
|
||||
|
||||
let toSwitchMin = GBServer.globals.minInstances.filter(
|
||||
p => p.instance.botId.toLowerCase() === text.toLowerCase()
|
||||
)[0];
|
||||
|
||||
if (!toSwitchMin) {
|
||||
toSwitchMin = GBServer.globals.minInstances.filter(p =>
|
||||
p.instance.activationCode ? p.instance.activationCode.toLowerCase() === text.toLowerCase() : false
|
||||
|
@ -1147,6 +1150,8 @@ export class WhatsappDirectLine extends GBService {
|
|||
// User wants to switch bots.
|
||||
|
||||
if (toSwitchMin !== undefined) {
|
||||
GBLog.info(`Switching bots from ${botId} to ${toSwitchMin.botId}...`);
|
||||
|
||||
// So gets the new bot instance information and prepares to
|
||||
// auto start dialog if any is specified.
|
||||
|
||||
|
@ -1186,8 +1191,7 @@ export class WhatsappDirectLine extends GBService {
|
|||
id,
|
||||
`O outro Bot que você estava falando(${user.instanceId}), não está mais disponível. Agora você está falando comigo, ${activeMin.instance.title}...`
|
||||
);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if ((activeMin as any).whatsAppDirectLine) {
|
||||
t = (activeMin as any).whatsAppDirectLine;
|
||||
} else {
|
||||
|
@ -1198,15 +1202,6 @@ export class WhatsappDirectLine extends GBService {
|
|||
t.received(req, res);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let minInstance = GBServer.globals.minInstances.filter(
|
||||
p => p.instance.botId.toLowerCase() === botId.toLowerCase()
|
||||
)[0];
|
||||
|
||||
// Just pass the message to the receiver.
|
||||
|
||||
await minInstance.whatsAppDirectLine.received(req, res);
|
||||
}
|
||||
} catch (error) {
|
||||
GBLog.error(`Error on Whatsapp callback: ${error.data ? error.data : error} ${error.stack}`);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue