Loading... 在后台设置的“设置-通知”中,将“通知渠道”修改为“JavaScript”,将下面的代码填入“JavaScript代码”中,注意,需要修改代码开头的`token`、`chatId`和`panelUrl`三个变量,即可完成配置。 ```javascript async function sendMessage(message, title, instanceId = null) { const token = ""; const chatId = ""; const panelUrl = ""; if (!token || !chatId) return false; const url = `https://api.telegram.org/bot${token}/sendMessage`; // 构建交互按钮 let inline_keyboard = []; let row1 = [{ text: "📊 进入面板", url: panelUrl }]; // 这里的路径修正为 /instance/,匹配你提供的格式 if (instanceId && instanceId !== '未知') { row1.push({ text: "🌐 实例详情", url: `${panelUrl}/instance/${instanceId}` }); } inline_keyboard.push(row1); const resp = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ chat_id: chatId, text: `<b>${title}</b>\n\n${message}`, parse_mode: 'HTML', reply_markup: { inline_keyboard: inline_keyboard } }), }); return resp.ok; } async function sendEvent(event) { try { // ⏰ 时间转换函数 (处理 CST) const getCSTTime = (timeStr) => { if (!timeStr || timeStr.startsWith('0001')) return "1-01-01 08:00:00"; const date = new Date(timeStr.replace(/\.\d+Z$/, 'Z')); const cst = new Date(date.getTime() + 8 * 60 * 60 * 1000); const f = (n) => n.toString().padStart(2, '0'); return `${cst.getUTCFullYear()}-${f(cst.getUTCMonth() + 1)}-${f(cst.getUTCDate())} ${f(cst.getUTCHours())}:${f(cst.getUTCMinutes())}:${f(cst.getUTCSeconds())}`; }; // 📦 流量单位转换函数 const formatTraffic = (bytes) => { if (!bytes || bytes === 0) return '无限制'; const gb = bytes / (1024 ** 3); if (gb >= 1024) return `${(gb / 1024).toFixed(2)} TB`; return `${gb.toFixed(2)} GB`; }; // 内存和磁盘格式化函数 const formatMemory = (bytes) => { if (!bytes || bytes === 0) return '0'; const gb = bytes / (1024 ** 3); return gb < 1 ? `${Math.round(gb * 1024)}MB` : `${Math.round(gb)}G`; }; const formatSwapMemory = (bytes) => { if (!bytes || bytes === 0) return '0'; const gb = bytes / (1024 ** 3); return gb < 1 ? `${Math.round(gb * 1024)}MB` : `${Math.round(gb)}G`; }; // IP 地址部分隐藏函数 const hideIP = (ip) => { if (!ip) return '未知'; const parts = ip.split('.'); if (parts.length === 4) { return `${parts[0]}.${parts[1]}.xxx.xxx`; } // 对于 IPv6 地址,只显示前半部分 const v6Parts = ip.split(':'); return v6Parts.slice(0, 3).join(':') + ':xxxx:xxxx:xxxx'; }; // 标题映射 const eventTitles = { 'Online': '🟢 服务器上线', 'Offline': '🔴 服务器离线', 'Alert': '⚠️ 异常警报', 'Renew': '💰 续费通知', 'Expire': '🚨 到期预警', 'Test': '🧪 测试通知' }; const title = eventTitles[event.event] || '📌 系统通知'; let clientInfo = ''; let targetInstanceId = null; if (event.clients && event.clients.length > 0) { const c = event.clients[0]; targetInstanceId = c.uuid; const region = c.region ? ` [${c.region}]` : ''; const hiddenIPv4 = hideIP(c.ipv4); const hiddenIPv6 = hideIP(c.ipv6); const mem = c.mem_total ? formatMemory(c.mem_total) : '0'; const swap = c.swap_total ? formatSwapMemory(c.swap_total) : '0'; const disk = c.disk_total ? formatMemory(c.disk_total) : '0'; clientInfo += `🖥️服务器:${c.name}${region}\n`; clientInfo += `📝配置:${c.cpu_cores || '0'}C / ${mem}${swap !== '0' ? `+${swap}` : ''} / ${disk}\n`; clientInfo += `🌐IPv4:${hiddenIPv4}\n`; clientInfo += `🌐IPv6:${hiddenIPv6}\n`; // 流量管家 const trafficLimit = formatTraffic(c.traffic_limit); clientInfo += `📶流量限额:${trafficLimit}${c.traffic_limit_type ? ` (${c.traffic_limit_type})` : ''}\n`; if (event.event === 'Renew' || event.event === 'Expire') { clientInfo += `💰账单:${c.currency || '$'}${c.price || '0'} (${c.billing_cycle || '0'}天/付)\n`; } } else { clientInfo += `🖥️服务器:未知设备\n📝配置:未知\n🌐IPv4:未知\n🌐IPv6:未知\n📶流量限额:未知\n`; } let message = clientInfo; message += `\n🗒️状态:${event.event} (${eventTitles[event.event] || '未知'})\n`; message += `⌚️时间:${getCSTTime(event.time)} (CST)`; if (event.message && event.message.trim()) { message += `\n\n📄详细描述:\n<i>${event.message}</i>`; } // 发送通知,传入真正的 UUID 以生成正确的按钮链接 return await sendMessage(message, title, targetInstanceId); } catch (error) { return await sendMessage(`脚本解析出错: ${error.message}`, '❌ Error'); } } ``` 最后记录一下我实际配置中三个变量的值,大家填入自己的值即可: <div class="hideContent">该部分仅登录用户可见</div> 最后修改:2026 年 02 月 17 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏。