Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51d26533b9 |
+13
-3
@@ -1,4 +1,3 @@
|
|||||||
const axios = require('axios');
|
|
||||||
const logger = require('./logger');
|
const logger = require('./logger');
|
||||||
|
|
||||||
// Function to send a note to a webhook
|
// Function to send a note to a webhook
|
||||||
@@ -18,10 +17,21 @@ async function publishNoteWithKey(content, relays, privateKeyHex) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send the payload to the webhook
|
// 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}`);
|
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) {
|
} catch (error) {
|
||||||
logger.error('Error sending note to webhook:', error);
|
logger.error('Error sending note to webhook:', error);
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
const axios = require('axios');
|
|
||||||
const logger = require('./logger');
|
const logger = require('./logger');
|
||||||
|
|
||||||
// Function to send webhook notifications
|
// Function to send webhook notifications
|
||||||
@@ -10,10 +9,14 @@ async function sendWebhookNotification(action, data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await axios.post(webhookUrl, {
|
const response = await fetch(webhookUrl, {
|
||||||
action,
|
method: 'POST',
|
||||||
data
|
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}`);
|
logger.info(`Webhook notification sent for action: ${action}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to send webhook notification:', error);
|
logger.error('Failed to send webhook notification:', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user