Files
message-pusher/channel/custom.go
T
fghwettandGitHub ef7c2d0a9d fix: resolve message sending failure when containing "\n" using webhook and custom channel (#111)
* 使用webhook和custom通道发送消息时如果内容中包含\n会推送失败的问题

* 消息查看页面增加markdown内容解析,访问链接页面增加GFM拓展解析

* 访问链接页面GFM footnote支持
2024-11-10 10:58:12 +08:00

36 lines
1.0 KiB
Go

package channel
import (
"bytes"
"errors"
"message-pusher/common"
"message-pusher/model"
"net/http"
"strings"
)
func SendCustomMessage(message *model.Message, user *model.User, channel_ *model.Channel) error {
url := channel_.URL
if strings.HasPrefix(url, "http:") {
return errors.New("自定义通道必须使用 HTTPS 协议")
}
if strings.HasPrefix(url, common.ServerAddress) {
return errors.New("自定义通道不能使用本服务地址")
}
template := channel_.Other
template = common.Replace(template, "$url", message.URL, -1)
template = common.Replace(template, "$to", message.To, -1)
template = common.Replace(template, "$title", message.Title, -1)
template = common.Replace(template, "$description", message.Description, -1)
template = common.Replace(template, "$content", message.Content, -1)
reqBody := []byte(template)
resp, err := http.Post(url, "application/json", bytes.NewReader(reqBody))
if err != nil {
return err
}
if resp.StatusCode != 200 {
return errors.New(resp.Status)
}
return nil
}