Files
mirror-3x-ui/internal/web/controller/wechat.go
T
17 3cb5bb7187 feat(wechat): add WeCom and webhook notifications (#7086)
Panel alerts and the scheduled status report could go to Telegram, Discord or email, but not to a WeCom group robot or a generic webhook.

Add a WeChat channel, off by default, with two modes: a WeCom group robot, or a webhook that receives a small signed-free JSON envelope with an optional bearer token. It carries the same events as the other channels (logins, CPU and memory, Xray crash, node and outbound state) and a scheduled text report. Delivery goes through the SSRF-guarded dialer, follows no redirects, and the URL and token are stored and redacted like the other notification secrets.
2026-11-24 21:54:39 +03:30

35 lines
928 B
Go

package controller
import (
"errors"
"github.com/gin-gonic/gin"
"github.com/mhsanaei/3x-ui/v3/internal/web/service/wechat"
)
var (
wechatService *wechat.Service
reloadWechatFunc func()
)
func SetWechatService(s *wechat.Service) { wechatService = s }
func SetReloadWechatFunc(fn func()) { reloadWechatFunc = fn }
func (a *SettingController) testWechat(c *gin.Context) {
if wechatService == nil {
jsonMsg(c, I18nWeb(c, "pages.settings.wechatTestFailed"), errors.New("WeChat service is unavailable"))
return
}
enabled, err := a.settingService.GetWechatEnable()
if err != nil || !enabled {
jsonMsg(c, I18nWeb(c, "pages.settings.wechatTestFailed"), errors.New("WeChat notifications are disabled"))
return
}
if err := wechatService.SendTest(); err != nil {
jsonMsg(c, I18nWeb(c, "pages.settings.wechatTestFailed"), err)
return
}
jsonMsg(c, I18nWeb(c, "pages.settings.wechatTestSuccess"), nil)
}