mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-19 03:42:23 -06:00
Merge branch 'ev2' into v2.0.0
This commit is contained in:
@@ -166,51 +166,4 @@ export class WebhookController extends EventController implements EventControlle
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async receiveWebhook(data: any) {
|
||||
if (data.object === 'whatsapp_business_account') {
|
||||
if (data.entry[0]?.changes[0]?.field === 'message_template_status_update') {
|
||||
const template = await this.prisma.template.findFirst({
|
||||
where: { templateId: `${data.entry[0].changes[0].value.message_template_id}` },
|
||||
});
|
||||
|
||||
if (!template) {
|
||||
console.log('template not found');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const { webhookUrl } = template;
|
||||
|
||||
await axios.post(webhookUrl, data.entry[0].changes[0].value, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
for (const entry of data.entry) {
|
||||
const numberId = entry.changes[0].value.metadata.phone_number_id;
|
||||
|
||||
if (!numberId) {
|
||||
this.logger.error('WebhookService -> receiveWebhook -> numberId not found');
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
const instance = await this.prisma.instance.findFirst({
|
||||
where: { number: numberId },
|
||||
});
|
||||
|
||||
if (!instance) {
|
||||
this.logger.error('WebhookService -> receiveWebhook -> instance not found');
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
await this.monitor.waInstances[instance.name].connectToWhatsapp(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,17 +30,6 @@ export class WebhookRouter extends RouterBroker {
|
||||
});
|
||||
|
||||
res.status(HttpStatus.OK).json(response);
|
||||
})
|
||||
.get('meta', async (req, res) => {
|
||||
if (req.query['hub.verify_token'] === configService.get<WaBusiness>('WA_BUSINESS').TOKEN_WEBHOOK)
|
||||
res.send(req.query['hub.challenge']);
|
||||
else res.send('Error, wrong validation token');
|
||||
})
|
||||
.post('meta', async (req, res) => {
|
||||
const { body } = req;
|
||||
const response = await eventManager.webhook.receiveWebhook(body);
|
||||
|
||||
return res.status(200).json(response);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user