mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-09 01:49:37 -06:00
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { Logger } from '../../config/logger.config';
|
|
import { InstanceDto } from '../dto/instance.dto';
|
|
import { WebhookDto } from '../dto/webhook.dto';
|
|
import { WAMonitoringService } from './monitor.service';
|
|
|
|
export class WebhookService {
|
|
constructor(private readonly waMonitor: WAMonitoringService) {}
|
|
|
|
private readonly logger = new Logger(WebhookService.name);
|
|
|
|
public create(instance: InstanceDto, data: WebhookDto) {
|
|
this.logger.verbose('create webhook: ' + instance.instanceName);
|
|
this.waMonitor.waInstances[instance.instanceName].setWebhook(data);
|
|
|
|
return { webhook: { ...instance, webhook: data } };
|
|
}
|
|
|
|
public async find(instance: InstanceDto): Promise<WebhookDto> {
|
|
try {
|
|
this.logger.verbose('find webhook: ' + instance.instanceName);
|
|
const result = await this.waMonitor.waInstances[instance.instanceName].findWebhook();
|
|
|
|
if (Object.keys(result).length === 0) {
|
|
throw new Error('Webhook not found');
|
|
}
|
|
|
|
return result;
|
|
} catch (error) {
|
|
return { enabled: false, url: '', events: [], webhook_by_events: false, webhook_base64 : false };
|
|
}
|
|
}
|
|
}
|