feat: add message push function call

This commit is contained in:
engigu
2026-03-04 21:45:43 +08:00
parent d4663cb492
commit 81b8d2a93d
53 changed files with 4161 additions and 33 deletions
+35
View File
@@ -0,0 +1,35 @@
package channels
import "github.com/engigu/baihu-panel/internal/sdk/message"
type CustomChannel struct{ *BaseChannel }
func NewCustomChannel() Channel {
return &CustomChannel{NewBaseChannel(ChannelCustom, []string{FormatTypeText})}
}
func (c *CustomChannel) Send(config ChannelConfig, msg *Message) (*Result, error) {
webhook := config.GetString("webhook")
body := config.GetString("body")
if webhook == "" {
return SendError("custom config missing: webhook is required"), nil
}
_, formattedContent := c.FormatContent(msg)
cli := message.CustomWebhook{}
// 替换 body 模板中的 TEXT 占位符
bodyStr := body
if bodyStr != "" {
bodyStr = replaceBodyPlaceholder(bodyStr, formattedContent)
} else {
bodyStr = formattedContent
}
res, err := cli.Request(webhook, bodyStr)
if err != nil {
return ErrorResult(string(res), err), nil
}
return SuccessResult(string(res)), nil
}