Skip to content

Commit

Permalink
feat: Added sys message (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
flc1125 authored Aug 3, 2023
1 parent 350c4bc commit 93dc888
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 34 deletions.
2 changes: 1 addition & 1 deletion feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- [x] 图文消息 `message.go@SendMpNewsMessage`
- [x] 隐式链接 `message.go@SendLinkMessage`
- [x] 外链消息 `message.go@SendExLinkMessage`
- [ ] 系统消息
- [x] 系统消息 `message.go@SendSysMessage`
- [ ] 短信消息
- [ ] 邮件消息

Expand Down
61 changes: 28 additions & 33 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,6 @@ import (
"net/http"
)

type MessageMpNews struct {
Title string `json:"title"`
MediaId string `json:"media_id"`
Content string `json:"content"`
Digest string `json:"digest,omitempty"`
ShowFront int `json:"showFront,omitempty"`
}

type MessageLink struct {
Title string `json:"title"`
Url string `json:"url"`
Action int `json:"action,omitempty"`
}

type MessageExLink struct {
Title string `json:"title"`
Url string `json:"url"`
MediaId string `json:"media_id"`
Digest string `json:"digest,omitempty"`
}

type InterfaceMessageRequest interface{}

var (
Expand All @@ -36,18 +15,26 @@ var (
_ InterfaceMessageRequest = MpNewsMessageRequest{}
_ InterfaceMessageRequest = LinkMessageRequest{}
_ InterfaceMessageRequest = ExLinkMessageRequest{}
_ InterfaceMessageRequest = MessageSysMessageRequest{}
)

type MessageRequest struct {
ToUser string `json:"toUser"`
ToDept string `json:"toDept"`
MsgType MsgType `json:"msgType"`
Text MessageText `json:"text,omitempty"`
Image MessageMedia `json:"image,omitempty"`
File MessageMedia `json:"file,omitempty"`
MpNews []MessageMpNews `json:"mpnews,omitempty"`
Link MessageLink `json:"link,omitempty"`
ExLink []MessageExLink `json:"exlink,omitempty"`
// General
ToUser string `json:"toUser"`
ToDept string `json:"toDept"`
MsgType MsgType `json:"msgType"`

// Text, Image, File, MpNews, Link, ExLink
Text MessageText `json:"text,omitempty"`
Image MessageMedia `json:"image,omitempty"`
File MessageMedia `json:"file,omitempty"`
MpNews []MessageMpNews `json:"mpnews,omitempty"`
Link MessageLink `json:"link,omitempty"`
ExLink []MessageExLink `json:"exlink,omitempty"`

// SysMsg
ToAll MessageSysMessageToAll `json:"toAll,omitempty"`
SysMsg MessageSysMessageSysMsg `json:"sysMsg"`
}

type TextMessageRequest struct {
Expand Down Expand Up @@ -92,9 +79,12 @@ type ExLinkMessageRequest struct {
ExLink []MessageExLink `json:"exlink"`
}

type MessageResponse struct {
ErrCode int `json:"errcode"`
ErrMsg string `json:"errmsg"`
type MessageSysMessageRequest struct {
ToUser string `json:"toUser,omitempty"`
ToDept string `json:"toDept,omitempty"`
ToAll MessageSysMessageToAll `json:"toAll,omitempty"`
MsgType MsgType `json:"msgType"`
SysMsg MessageSysMessageSysMsg `json:"sysMsg"`
}

func (c *Client) SendMessage(ctx context.Context, request InterfaceMessageRequest) (response Response, err error) {
Expand Down Expand Up @@ -137,3 +127,8 @@ func (c *Client) SendExLinkMessage(ctx context.Context, request ExLinkMessageReq
request.MsgType = MsgTypeExLink
return c.SendMessage(ctx, request)
}

func (c *Client) SendSysMessage(ctx context.Context, request MessageSysMessageRequest) (response Response, err error) {
request.MsgType = MsgTypeSysMsg
return c.SendMessage(ctx, request)
}
37 changes: 37 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const (
MsgTypeExLink MsgType = "exlink"
MsgTypeVoice MsgType = "voice"
MsgTypeVideo MsgType = "video"
MsgTypeSysMsg MsgType = "sysMsg"
)

type MessageText struct {
Expand All @@ -26,3 +27,39 @@ type MessageFile struct {
Name string `json:"name"`
Size int64 `json:"size"`
}

type MessageMpNews struct {
Title string `json:"title"`
MediaId string `json:"media_id"`
Content string `json:"content"`
Digest string `json:"digest,omitempty"`
ShowFront int `json:"showFront,omitempty"`
}

type MessageLink struct {
Title string `json:"title"`
Url string `json:"url"`
Action int `json:"action,omitempty"`
}

type MessageExLink struct {
Title string `json:"title"`
Url string `json:"url"`
MediaId string `json:"media_id"`
Digest string `json:"digest,omitempty"`
}

type MessageSysMessageToAll struct {
OnliyOnline interface{} `json:"onliyOnline"`
}

type MessageSysMessageSysMsgMsg struct {
Text MessageText `json:"text,omitempty"`
Link MessageLink `json:"link,omitempty"`
}

type MessageSysMessageSysMsg struct {
Title string `json:"title"`
PopDuration int `json:"popDuration,omitempty"`
Msg []MessageSysMessageSysMsgMsg `json:"msg"`
}

0 comments on commit 93dc888

Please sign in to comment.