feat: add vocechat push #82
This commit is contained in:
@@ -73,4 +73,5 @@ const (
|
||||
ChannelNtfy = "Ntfy"
|
||||
ChannelGotify = "Gotify"
|
||||
ChannelPushPlus = "PushPlus"
|
||||
ChannelVoceChat = "VoceChat"
|
||||
)
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package channels
|
||||
|
||||
import "github.com/engigu/baihu-panel/internal/sdk/message"
|
||||
|
||||
type VoceChatChannel struct{ *BaseChannel }
|
||||
|
||||
func NewVoceChatChannel() Channel {
|
||||
return &VoceChatChannel{NewBaseChannel(ChannelVoceChat, []string{FormatTypeMarkdown})}
|
||||
}
|
||||
|
||||
func (c *VoceChatChannel) Send(config ChannelConfig, msg *Message) (*Result, error) {
|
||||
server := config.GetString("server")
|
||||
apiKey := config.GetString("api_key")
|
||||
targetID := config.GetString("target_id")
|
||||
|
||||
if server == "" || apiKey == "" || targetID == "" {
|
||||
return SendError("vocechat config missing: server, api_key and target_id are required"), nil
|
||||
}
|
||||
|
||||
cli := message.VoceChat{
|
||||
Server: server,
|
||||
APIKey: apiKey,
|
||||
TargetType: config.GetString("target_type"), // defaults to "user" in SDK if not matched differently
|
||||
TargetID: targetID,
|
||||
}
|
||||
|
||||
res, err := cli.Request(msg.Title, msg.Text)
|
||||
if err != nil {
|
||||
return ErrorResult(string(res), err), nil
|
||||
}
|
||||
return SuccessResult(string(res)), nil
|
||||
}
|
||||
@@ -48,6 +48,7 @@ const (
|
||||
ChannelNtfy = channels.ChannelNtfy
|
||||
ChannelGotify = channels.ChannelGotify
|
||||
ChannelPushPlus = channels.ChannelPushPlus
|
||||
ChannelVoceChat = channels.ChannelVoceChat
|
||||
)
|
||||
|
||||
// 重导出辅助函数
|
||||
@@ -80,6 +81,7 @@ func init() {
|
||||
RegisterChannel(ChannelWeChatOFAccount, func() Channel { return channels.NewWeChatOFAccountChannel() })
|
||||
RegisterChannel(ChannelAliyunSMS, func() Channel { return channels.NewAliyunSMSChannel() })
|
||||
RegisterChannel(ChannelPushPlus, func() Channel { return channels.NewPushPlusChannel() })
|
||||
RegisterChannel(ChannelVoceChat, func() Channel { return channels.NewVoceChatChannel() })
|
||||
}
|
||||
|
||||
// RegisterChannel 注册自定义渠道(可用于扩展)
|
||||
|
||||
Reference in New Issue
Block a user