mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-19 20:02:20 -06:00
refactor: change webhook reception for all instances
This commit refactors the webhook reception to handle all instances at once. Previously, each instance had its own webhook endpoint, but now there is a single endpoint for all instances. This change simplifies the codebase and reduces the potential for errors. The main changes include: - Modifying the `InstanceController` to update the webhook URL for all instances. - Modifying the `WebhookController` to handle the reception of webhooks for all instances. - Modifying the `IndexRouter` and `WebhookRouter` to add a new route for the webhook reception endpoint. - Modifying the `ServerModule` to inject the `PrismaRepository` into the `WebhookService`. - Modifying the `WebhookService` to handle the reception of webhooks for all instances. These changes improve the maintainability and scalability of the application, as there is no longer a need to manage individual webhook endpoints for each instance.
This commit is contained in:
@@ -392,7 +392,7 @@ export class InstanceController {
|
||||
throw new BadRequestException('number is required');
|
||||
}
|
||||
const urlServer = this.configService.get<HttpServer>('SERVER').URL;
|
||||
webhookWaBusiness = `${urlServer}/webhook/whatsapp/${encodeURIComponent(instance.instanceName)}`;
|
||||
webhookWaBusiness = `${urlServer}/webhook/meta`;
|
||||
accessTokenWaBusiness = this.configService.get<WaBusiness>('WA_BUSINESS').TOKEN_WEBHOOK;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,12 @@ export class WebhookController {
|
||||
return this.webhookService.find(instance);
|
||||
}
|
||||
|
||||
public async receiveWebhook(instance: InstanceDto, data: any) {
|
||||
return await this.waMonitor.waInstances[instance.instanceName].connectToWhatsapp(data);
|
||||
public async receiveWebhook(data: any) {
|
||||
console.log('webhook/meta', data);
|
||||
this.webhookService.receiveWebhook(data);
|
||||
|
||||
return {
|
||||
message: 'Webhook received',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user