|
|
@ -69,15 +69,32 @@ export class WebhookManager {
|
|
|
|
|
|
|
|
|
|
|
|
static async registerWebhook(): Promise<WebhookResponse> {
|
|
|
|
static async registerWebhook(): Promise<WebhookResponse> {
|
|
|
|
this.validateConfig();
|
|
|
|
this.validateConfig();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const config = this.getConfig();
|
|
|
|
|
|
|
|
const apiUrl = this.getApiUrl();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log('ℹ️ Attempting to register webhook:', {
|
|
|
|
|
|
|
|
apiUrl,
|
|
|
|
|
|
|
|
config: {
|
|
|
|
|
|
|
|
...config,
|
|
|
|
|
|
|
|
// Don't log full URL for security
|
|
|
|
|
|
|
|
url: `${config.url.substring(0, 20)}...`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const response = await fetch(this.getApiUrl(), {
|
|
|
|
const response = await fetch(apiUrl, {
|
|
|
|
method: 'POST',
|
|
|
|
method: 'POST',
|
|
|
|
headers: this.getHeaders(),
|
|
|
|
headers: this.getHeaders(),
|
|
|
|
body: JSON.stringify(this.getConfig()),
|
|
|
|
body: JSON.stringify(config),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error(`Failed to register webhook: ${response.statusText}`);
|
|
|
|
let errorDetails = response.statusText;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const errorBody = await response.text();
|
|
|
|
|
|
|
|
errorDetails += ` - ${errorBody}`;
|
|
|
|
|
|
|
|
} catch {}
|
|
|
|
|
|
|
|
throw new Error(`Failed to register webhook: ${errorDetails}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const data = await response.json();
|
|
|
|
const data = await response.json();
|
|
|
|