new(core.gbapp): New param for disabling welcome messages.

This commit is contained in:
Rodrigo Rodriguez 2020-04-03 00:17:21 -03:00
parent 9e15b03d04
commit 134cf31695

View file

@ -137,33 +137,40 @@ export class GBMinService {
res.end(); res.end();
return; // Exit here. return; // Exit here.
} }
let activeMin;
if (process.env.WHATSAPP_WELCOME_DISABLED !== "true") {
const toSwitchMin = GBServer.globals.minInstances.filter(p => p.botId === text)[0]; const toSwitchMin = GBServer.globals.minInstances.filter(p => p.botId === text)[0];
let activeMin = toSwitchMin ? toSwitchMin : GBServer.globals.minBoot; activeMin = toSwitchMin ? toSwitchMin : GBServer.globals.minBoot;
let sec = new SecService(); let sec = new SecService();
let user = await sec.getUserFromPhone(id); let user = await sec.getUserFromPhone(id);
if (user === null) { if (user === null) {
user = await sec.ensureUser(activeMin.instance.instanceId, id, user = await sec.ensureUser(activeMin.instance.instanceId, id,
activeMin.botId, id, "", "whatsapp", id, id); activeMin.botId, id, "", "whatsapp", id, id);
await (activeMin as any).whatsAppDirectLine.sendToDevice(id, `Olá! Seja bem-vinda(o)!\nMe chamo ${activeMin.instance.title}. Como posso ajudar?`); await (activeMin as any).whatsAppDirectLine.sendToDevice(id, `Olá! Seja bem-vinda(o)!\nMe chamo ${activeMin.instance.title}. Como posso ajudar?`);
res.end();
} else {
// User wants to switch bots.
if (toSwitchMin !== undefined) {
await sec.updateCurrentBotId(id, text);
await (activeMin as any).whatsAppDirectLine.sendToDevice(id, `Agora falando com ${activeMin.instance.title}...`);
res.end(); res.end();
} else {
// User wants to switch bots.
if (toSwitchMin !== undefined) {
await sec.updateCurrentBotId(id, text);
await (activeMin as any).whatsAppDirectLine.sendToDevice(id, `Agora falando com ${activeMin.instance.title}...`);
res.end();
}
else {
activeMin = GBServer.globals.minInstances.filter(p => p.botId === user.currentBotId)[0];;
(activeMin as any).whatsAppDirectLine.received(req, res);
}
} }
else { }
activeMin = GBServer.globals.minInstances.filter(p => p.botId === user.currentBotId)[0];; else {
(activeMin as any).whatsAppDirectLine.received(req, res); (GBServer.globals.minBoot as any).whatsAppDirectLine.received(req, res);
}
} }
} catch (error) { } catch (error) {
GBLog.error(`Error on Whatsapp callback: ${error.message}`); GBLog.error(`Error on Whatsapp callback: ${error.message}`);
} }
}); });
await Promise.all( await Promise.all(