feat: add pushplus
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package channels
|
||||
|
||||
import "github.com/engigu/baihu-panel/internal/sdk/message"
|
||||
|
||||
type PushPlusChannel struct{ *BaseChannel }
|
||||
|
||||
func NewPushPlusChannel() Channel {
|
||||
return &PushPlusChannel{NewBaseChannel(ChannelPushPlus, []string{FormatTypeText, FormatTypeHTML, FormatTypeMarkdown})}
|
||||
}
|
||||
|
||||
func (c *PushPlusChannel) Send(config ChannelConfig, msg *Message) (*Result, error) {
|
||||
token := config.GetString("token")
|
||||
if token == "" {
|
||||
return SendError("pushplus config missing: token is required"), nil
|
||||
}
|
||||
|
||||
cli := message.PushPlus{
|
||||
Token: token,
|
||||
Topic: config.GetString("topic"),
|
||||
Template: config.GetString("template"),
|
||||
Channel: config.GetString("channel"),
|
||||
Webhook: config.GetString("webhook"),
|
||||
CallbackUrl: config.GetString("callback_url"),
|
||||
To: config.GetString("to"),
|
||||
}
|
||||
|
||||
res, err := cli.Request(msg.Title, msg.Text)
|
||||
if err != nil {
|
||||
return ErrorResult(string(res), err), nil
|
||||
}
|
||||
return SuccessResult(string(res)), nil
|
||||
}
|
||||
@@ -72,4 +72,5 @@ const (
|
||||
ChannelPushMe = "PushMe"
|
||||
ChannelNtfy = "Ntfy"
|
||||
ChannelGotify = "Gotify"
|
||||
ChannelPushPlus = "PushPlus"
|
||||
)
|
||||
|
||||
@@ -47,6 +47,7 @@ const (
|
||||
ChannelPushMe = channels.ChannelPushMe
|
||||
ChannelNtfy = channels.ChannelNtfy
|
||||
ChannelGotify = channels.ChannelGotify
|
||||
ChannelPushPlus = channels.ChannelPushPlus
|
||||
)
|
||||
|
||||
// 重导出辅助函数
|
||||
@@ -78,6 +79,7 @@ func init() {
|
||||
RegisterChannel(ChannelCustom, func() Channel { return channels.NewCustomChannel() })
|
||||
RegisterChannel(ChannelWeChatOFAccount, func() Channel { return channels.NewWeChatOFAccountChannel() })
|
||||
RegisterChannel(ChannelAliyunSMS, func() Channel { return channels.NewAliyunSMSChannel() })
|
||||
RegisterChannel(ChannelPushPlus, func() Channel { return channels.NewPushPlusChannel() })
|
||||
}
|
||||
|
||||
// RegisterChannel 注册自定义渠道(可用于扩展)
|
||||
|
||||
Reference in New Issue
Block a user