forked from web3bothub/gradient-bot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebhook.js
35 lines (29 loc) · 956 Bytes
/
webhook.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const axios = require('axios');
async function sendWebhookMessage(message, user = process.env.APP_USER) {
if (!process.env.ENABLE_WEBHOOK || !process.env.WEBHOOK_URL) {
return;
}
try {
const timestamp = new Date().toLocaleString();
const formattedMessage = `🔍 【Gradient 状态报告】\n⏰ 时间: ${timestamp}\n👤 账户: ${user}\n\n${message}`;
const payload = {
msgtype: "text",
text: {
content: formattedMessage
}
};
const response = await axios.post(process.env.WEBHOOK_URL, payload, {
headers: {
'Content-Type': 'application/json'
}
});
if (response.status === 200) {
console.log("Webhook message sent successfully");
} else {
console.error("Failed to send webhook message:", response.status);
}
} catch (error) {
console.error("Error sending webhook message:", error.message);
}
}
module.exports = { sendWebhookMessage };