feat: channel adapters — dingtalk, wecom, bark

This commit is contained in:
2026-06-27 13:15:57 +08:00
parent 54af29e4fc
commit 414c8c7cbf
5 changed files with 196 additions and 1 deletions
+51
View File
@@ -0,0 +1,51 @@
package adapter
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
type wecomConfig struct {
WebhookURL string `json:"webhook_url"`
}
type wecomMessage struct {
MsgType string `json:"msgtype"`
Markdown *wecomMD `json:"markdown"`
}
type wecomMD struct {
Content string `json:"content"`
}
type WeComSender struct{}
func (s *WeComSender) Type() string { return "wecom" }
func (s *WeComSender) Send(title, content string, config json.RawMessage) error {
var cfg wecomConfig
if err := json.Unmarshal(config, &cfg); err != nil {
return fmt.Errorf("parse wecom config: %w", err)
}
msg := wecomMessage{
MsgType: "markdown",
Markdown: &wecomMD{
Content: fmt.Sprintf("## %s\n%s", title, content),
},
}
body, _ := json.Marshal(msg)
resp, err := http.Post(cfg.WebhookURL, "application/json", bytes.NewReader(body))
if err != nil {
return fmt.Errorf("wecom send: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode >= 400 {
return fmt.Errorf("wecom returned status %d", resp.StatusCode)
}
return nil
}