feat(notify): 新增站级 Webhook 与用户级 Telegram 通知通道
在现有邮件通知之外补两条广播/点对点通道: - 站级 Webhook([notify] webhook_url):新提问 / 新回答 / 新追问 / 新私聊 / 新投票回复统一 POST JSON 到通用 Webhook(Discord / Slack / 企业微信机器人等)。 消息体同时带 content(Discord 直接可用)与结构化 event/title/body/link 字段。 - 用户级 Telegram([notify] telegram_bot_token + users.telegram_chat_id):箱主 自填 Chat ID,新提问 / 新投票回复点对点推送。 设计约束:通知是「尽力而为」旁路 —— 任一通道发送失败只记日志、不向上抛错, 绝不影响提问/回答的主流程;通道未配置时静默跳过。发送放在 shared.SafeGo 异步 执行,与现有邮件通知同一条路径。 6 处业务触发点接入 notify;私聊消息保留仅邮件(已有 5 分钟节流,避免广播刷屏)。 profile 页新增 Telegram Chat ID 输入框 + 四语言字典。app.sample.ini 加 [notify] 段。 测试覆盖 webhook 的 JSON 结构与未配置时的静默跳过。
This commit is contained in:
@@ -30,6 +30,7 @@ import (
|
||||
"github.com/tamakyi/TamaBox/internal/db"
|
||||
"github.com/tamakyi/TamaBox/internal/i18n"
|
||||
"github.com/tamakyi/TamaBox/internal/mail"
|
||||
"github.com/tamakyi/TamaBox/internal/notify"
|
||||
"github.com/tamakyi/TamaBox/internal/security/censor"
|
||||
"github.com/tamakyi/TamaBox/internal/security/moderation"
|
||||
"github.com/tamakyi/TamaBox/internal/shared"
|
||||
@@ -761,6 +762,20 @@ func Submit(ctx context.Context, recaptcha recaptcha.RecaptchaV3) {
|
||||
}
|
||||
})
|
||||
}
|
||||
if vote.Type == db.VoteTypeForm {
|
||||
title := vote.Title
|
||||
voteID := vote.ID
|
||||
shared.SafeGo(func() {
|
||||
notify.Send(stdctx.Background(), "new_vote_submission",
|
||||
"新的投票回复", title,
|
||||
fmt.Sprintf("%s/user/votes/%d/results", conf.App.ExternalURL, voteID))
|
||||
if owner.TelegramChatID != "" {
|
||||
notify.SendToTelegram(stdctx.Background(), owner.TelegramChatID,
|
||||
fmt.Sprintf("🗳️ 投票「%s」收到新回复\n%s/user/votes/%d/results",
|
||||
title, conf.App.ExternalURL, voteID))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
ctx.SetSuccessFlash(i18n.T(lang, "vote.flash.success"))
|
||||
ctx.Redirect("/vote/" + vote.LinkToken)
|
||||
|
||||
Reference in New Issue
Block a user