Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ 修复了news类型无法使用的问题,添加了message的测试,新增模板卡片消息 #177

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions cmd/workwxctl/commands/cmd_send_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func cmdSendMessage(c *cli.Context) error {
url := c.String(flagURL)
picURL := c.String(flagPicURL)
buttonText := c.String(flagButtonText)
sourceContentURL := c.String(flagSourceContentURL)
// sourceContentURL := c.String(flagSourceContentURL)
digest := c.String(flagDigest)

app := cfg.MakeWorkwxApp()
Expand Down Expand Up @@ -73,21 +73,29 @@ func cmdSendMessage(c *cli.Context) error {
case "news":
err = app.SendNewsMessage(
&recipient,
title,
description,
url,
picURL,
[]workwx.Article{
workwx.Article{
Title: title,
Description: description,
URL: url,
PicURL: picURL,
AppID: "",
PagePath: "",
},
},
isSafe,
)
case "mpnews":
err = app.SendMPNewsMessage(
&recipient,
title,
thumbMediaID,
author,
sourceContentURL,
content,
digest,
[]workwx.MPArticle{workwx.MPArticle{
Title: title,
ThumbMediaID: thumbMediaID,
Author: author,
ContentSourceURL: content,
Content: content,
Digest: digest,
}},
isSafe,
)
default:
Expand Down
44 changes: 19 additions & 25 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,14 @@ func (c *WorkwxApp) SendTextCardMessage(
// 否则为单纯的【发送应用消息】接口调用。
func (c *WorkwxApp) SendNewsMessage(
recipient *Recipient,
title string,
description string,
url string,
picURL string,
articles []Article,
isSafe bool,
) error {
return c.sendMessage(
recipient,
"news",
map[string]interface{}{
"title": title,
"description": description, // TODO: 零值
"url": url,
"picurl": picURL, // TODO: 零值
"articles": articles,
}, isSafe,
)
}
Expand All @@ -146,29 +140,14 @@ func (c *WorkwxApp) SendNewsMessage(
// 否则为单纯的【发送应用消息】接口调用。
func (c *WorkwxApp) SendMPNewsMessage(
recipient *Recipient,
title string,
thumbMediaID string,
author string,
sourceContentURL string,
content string,
digest string,
mparticles []MPArticle,
isSafe bool,
) error {
return c.sendMessage(
recipient,
"mpnews",
map[string]interface{}{
// TODO: 支持发送多条图文
"articles": []interface{}{
map[string]interface{}{
"title": title,
"thumb_media_id": thumbMediaID,
"author": author, // TODO: 零值
"content_source_url": sourceContentURL, // TODO: 零值
"content": content,
"digest": digest,
},
},
"articles": mparticles,
}, isSafe,
)
}
Expand Down Expand Up @@ -210,6 +189,21 @@ func (c *WorkwxApp) SendTaskCardMessage(
)
}

// SendTemplateCardMessage 发送卡片模板消息
func (c *WorkwxApp) SendTemplateCardMessage(
recipient *Recipient,
templateCard TemplateCard,
isSafe bool,
) error {
return c.sendMessage(
recipient,
"template_card",
map[string]interface{}{
"template_card": templateCard,
}, isSafe,
)
}

// sendMessage 发送消息底层接口
//
// 收件人参数如果仅设置了 `ChatID` 字段,则为【发送消息到群聊会话】接口调用;
Expand Down
Loading
Loading