feat: update webhook config to match API requirements

main
borja (aider) 3 months ago
parent 7616e9f268
commit 72e7a804b5

@ -2,6 +2,7 @@ import { REQUIRED_ENV } from '../server';
type WebhookConfig = {
url: string;
enabled: boolean;
webhook_by_events: boolean;
webhook_base64: boolean;
events: string[];
@ -47,12 +48,15 @@ export class WebhookManager {
}
}
private static getConfig(): WebhookConfig {
private static getConfig(): { webhook: WebhookConfig } {
return {
webhook: {
url: process.env.WEBHOOK_URL!,
enabled: true,
webhook_by_events: true,
webhook_base64: true,
events: this.REQUIRED_EVENTS,
}
};
}
@ -99,13 +103,14 @@ export class WebhookManager {
const data = await response.json();
if (!data?.webhook?.webhook?.enabled) {
if (!data?.enabled) {
throw new Error('Webhook registration failed - not enabled in response');
}
console.log('✅ Webhook successfully registered:', {
url: data.webhook.webhook.url,
events: data.webhook.webhook.events,
url: data.url,
events: data.events,
id: data.id
});
return data;

@ -0,0 +1,53 @@
import { describe, test, expect, mock } from 'bun:test';
import { WebhookManager } from '../../../src/services/webhook-manager';
describe('WebhookManager', () => {
const envBackup = process.env;
beforeEach(() => {
process.env = {
...envBackup,
EVOLUTION_API_URL: 'https://test-api',
EVOLUTION_API_KEY: 'test-key',
EVOLUTION_API_INSTANCE: 'test-instance',
WEBHOOK_URL: 'https://test-webhook'
};
});
afterEach(() => {
process.env = envBackup;
});
test('should create correct config structure', () => {
const config = WebhookManager['getConfig']();
expect(config).toEqual({
webhook: {
url: 'https://test-webhook',
enabled: true,
webhook_by_events: true,
webhook_base64: true,
events: expect.any(Array)
}
});
});
test('should validate successful response', () => {
const validResponse = {
id: 'test-id',
url: 'https://test-webhook',
enabled: true,
events: ['APPLICATION_STARTUP']
};
expect(() => WebhookManager['validateResponse'](validResponse)).not.toThrow();
});
test('should reject disabled webhook response', () => {
const invalidResponse = {
id: 'test-id',
url: 'https://test-webhook',
enabled: false,
events: ['APPLICATION_STARTUP']
};
expect(() => WebhookManager['validateResponse'](invalidResponse)).toThrow();
});
});
Loading…
Cancel
Save