new(whatsapp.gblib): Multiple service definition allowed per tenant.

This commit is contained in:
Rodrigo Rodriguez 2022-01-09 19:17:03 -03:00
parent b45f7372da
commit 4dcb581897
3 changed files with 15 additions and 4 deletions

View file

@ -333,7 +333,7 @@ export class GuaribasChannel extends Model<GuaribasChannel> {
export class GuaribasException extends Model<GuaribasException> {
@PrimaryKey
@AutoIncrement
@Column(DataType.STRING(255))
@Column(DataType.INTEGER)
public exceptionId: number;
@Column(DataType.STRING(255))

View file

@ -167,7 +167,7 @@ export class GBMinService {
// Servers the WhatsApp callback.
GBServer.globals.server.post('/webhooks/whatsapp', this.WhatsAppCallback.bind(this));
GBServer.globals.server.post('/webhooks/whatsapp/:botId', this.WhatsAppCallback.bind(this));
// Calls mountBot event to all bots.
@ -332,6 +332,13 @@ export class GBMinService {
}
let activeMin;
let botId = req.params.botId;
if (botId === '[default]' || botId === undefined) {
botId = GBConfigService.get('BOT_ID');
}
GBLog.info(`Client requested instance for: ${botId}.`);
// Processes group behaviour.
@ -442,10 +449,14 @@ export class GBMinService {
}
}
} else {
let minInstance = GBServer.globals.minInstances.filter(
p => p.instance.botId.toLowerCase() === botId
)[0];
// Just pass the message to the receiver.
await (GBServer.globals.minBoot as any).whatsAppDirectLine.received(req, res);
await minInstance.whatsAppDirectLine.received(req, res);
}
} catch (error) {
GBLog.error(`Error on Whatsapp callback: ${error.data ? error.data : error}`);

View file

@ -110,7 +110,7 @@ export class WhatsappDirectLine extends GBService {
timeout: 10000,
qs: {
token: this.whatsappServiceKey,
webhookUrl: `${GBServer.globals.publicAddress}/webhooks/whatsapp`,
webhookUrl: `${GBServer.globals.publicAddress}/webhooks/whatsapp/${this.botId}`,
set: true
},
headers: {