From 51d26533b9eb897e08969ebda03eca3eac69c7be Mon Sep 17 00:00:00 2001 From: Michilis Date: Fri, 26 Jun 2026 22:31:37 +0000 Subject: [PATCH] Replace axios with native fetch in webhook utils axios was required by src/utils/message.js and src/utils/webhook.js but was never declared in package.json, so `npm install` never fetched it and the app crashed on startup with MODULE_NOT_FOUND. Switch both webhook POST calls to Node's built-in fetch (available since Node 18; running on 22.12), removing the missing dependency entirely. Behavior is preserved: JSON body with Content-Type header, and an explicit response.ok check to keep axios's throw-on-non-2xx semantics. message.js now returns parsed JSON (or text fallback) in place of axios's response.data. Co-Authored-By: Claude Opus 4.8 --- src/utils/message.js | 16 +++++++++++++--- src/utils/webhook.js | 11 +++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/utils/message.js b/src/utils/message.js index f96a7f7..aa5ea99 100644 --- a/src/utils/message.js +++ b/src/utils/message.js @@ -1,4 +1,3 @@ -const axios = require('axios'); const logger = require('./logger'); // Function to send a note to a webhook @@ -18,10 +17,21 @@ async function publishNoteWithKey(content, relays, privateKeyHex) { } // Send the payload to the webhook - const response = await axios.post(webhookUrl, payload); + const response = await fetch(webhookUrl, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(payload) + }); + if (!response.ok) { + throw new Error(`Webhook responded with status ${response.status}`); + } logger.info(`✅ Successfully sent note to webhook: ${response.status}`); - return response.data; // Assuming the webhook returns some data + // Parse JSON if the webhook returns it, otherwise fall back to text + const contentType = response.headers.get('content-type') || ''; + return contentType.includes('application/json') + ? await response.json() + : await response.text(); } catch (error) { logger.error('Error sending note to webhook:', error); throw error; diff --git a/src/utils/webhook.js b/src/utils/webhook.js index 4b2fa40..c7bb9ea 100644 --- a/src/utils/webhook.js +++ b/src/utils/webhook.js @@ -1,4 +1,3 @@ -const axios = require('axios'); const logger = require('./logger'); // Function to send webhook notifications @@ -10,10 +9,14 @@ async function sendWebhookNotification(action, data) { } try { - await axios.post(webhookUrl, { - action, - data + const response = await fetch(webhookUrl, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ action, data }) }); + if (!response.ok) { + throw new Error(`Webhook responded with status ${response.status}`); + } logger.info(`Webhook notification sent for action: ${action}`); } catch (error) { logger.error('Failed to send webhook notification:', error);