飞书通知推送基本实现
This commit is contained in:
parent
06399e1da9
commit
6216af500f
1
go.mod
1
go.mod
|
@ -22,6 +22,7 @@ require (
|
|||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.11.2 // indirect
|
||||
github.com/go-resty/resty/v2 v2.7.0 // indirect
|
||||
github.com/goccy/go-json v0.10.0 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/gopherjs/gopherjs v1.17.2 // indirect
|
||||
|
|
5
go.sum
5
go.sum
|
@ -31,6 +31,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
|
|||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU=
|
||||
github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s=
|
||||
github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY=
|
||||
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
|
||||
github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA=
|
||||
github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
|
@ -191,6 +193,7 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R
|
|||
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
|
||||
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
|
@ -208,6 +211,7 @@ golang.org/x/sys v0.0.0-20200808120158-1030fc2bf1d9/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211204120058-94396e421777/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
@ -217,6 +221,7 @@ golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
|
||||
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package notifies
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
const (
|
||||
FeiShuMsgTypeText = "text" // 文本
|
||||
FeiShuMsgTypeRichText = "post" // 富文本
|
||||
FeiShuMsgTypeImage = "image" // 图片
|
||||
FeiShuMsgTypeInteractive = "interactive" // 消息卡片
|
||||
FeiShuMsgTypeShareChat = "share_chat" // 分享群名片
|
||||
FeiShuMsgTypeShareUser = "share_user" // 分享个人名片
|
||||
FeiShuMsgTypeAudio = "audio" // 音频
|
||||
FeiShuMsgTypeMedia = "media" // 视频
|
||||
FeiShuMsgTypeFile = "file" // 文件
|
||||
FeiShuMsgTypeSticker = "sticker" // 表情包
|
||||
|
||||
)
|
||||
|
||||
func NewFeiShu(msgType, receiveId, content string) *FeiShu {
|
||||
return &FeiShu{
|
||||
ReceiveId: receiveId,
|
||||
Content: content,
|
||||
MsgType: msgType,
|
||||
}
|
||||
}
|
||||
|
||||
type FeiShu struct {
|
||||
ReceiveId string `json:"receive_id"`
|
||||
Content string `json:"content"`
|
||||
MsgType string `json:"msg_type"`
|
||||
}
|
||||
|
||||
func (slf *FeiShu) GetTitle() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (slf *FeiShu) GetContent() (string, error) {
|
||||
data, err := json.Marshal(slf)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(data), nil
|
||||
}
|
|
@ -5,5 +5,5 @@ type Notify interface {
|
|||
// GetTitle 获取通知标题
|
||||
GetTitle() string
|
||||
// GetContent 获取通知内容
|
||||
GetContent() string
|
||||
GetContent() (string, error)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package readers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/go-resty/resty/v2"
|
||||
"minotaur/notify"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func NewFeiShu(webhook, receiveId string) *FeiShu {
|
||||
return &FeiShu{
|
||||
client: resty.New(),
|
||||
webhook: webhook,
|
||||
receiveId: receiveId,
|
||||
}
|
||||
}
|
||||
|
||||
type FeiShu struct {
|
||||
client *resty.Client
|
||||
webhook string
|
||||
receiveId string
|
||||
}
|
||||
|
||||
func (slf *FeiShu) Push(notify notify.Notify) error {
|
||||
content, err := notify.GetContent()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resp, err := slf.client.R().
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetBody(content).
|
||||
Post(slf.webhook)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp.StatusCode() != http.StatusOK {
|
||||
return fmt.Errorf("FeiShu notify reader push failed, err: %s", resp.String())
|
||||
}
|
||||
return err
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
package notify
|
||||
|
||||
type Sender interface {
|
||||
Push(notify Notify)
|
||||
Push(notify Notify) error
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue