Skip to content

Commit 25a4b12

Browse files
committed
add method SendTaskCardMessage
1 parent 7d42206 commit 25a4b12

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

message.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package workwx
22

33
import (
4+
"encoding/json"
45
"errors"
56
)
67

@@ -187,6 +188,38 @@ func (c *WorkwxApp) SendMarkdownMessage(
187188
return c.sendMessage(recipient, "markdown", map[string]interface{}{"content": content}, isSafe)
188189
}
189190

191+
// SendTaskCardMessage 发送 任务卡片 消息
192+
func (c *WorkwxApp) SendTaskCardMessage(
193+
recipient *Recipient,
194+
title string,
195+
description string,
196+
url string,
197+
taskid string,
198+
btn []TaskCardBtn,
199+
isSafe bool,
200+
) error {
201+
btnByte, err := json.Marshal(btn)
202+
if err != nil {
203+
return errors.New("btn convert to json fail: " + err.Error())
204+
}
205+
var btnSlice []map[string]interface{}
206+
err = json.Unmarshal(btnByte, &btnSlice)
207+
if err != nil {
208+
return errors.New("btn convert to []map fail: " + err.Error())
209+
}
210+
return c.sendMessage(
211+
recipient,
212+
"taskcard",
213+
map[string]interface{}{
214+
"title": title,
215+
"description": description,
216+
"url": url,
217+
"task_id": taskid,
218+
"btn": btnSlice,
219+
}, isSafe,
220+
)
221+
}
222+
190223
// sendMessage 发送消息底层接口
191224
//
192225
// 收件人参数如果仅设置了 `ChatID` 字段,则为【发送消息到群聊会话】接口调用;

models.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,3 +938,12 @@ type respOAGetApprovalDetail struct {
938938
// Info 审批申请详情
939939
Info OAApprovalDetail `json:"info"`
940940
}
941+
942+
// TaskCardBtn 任务卡片消息按钮
943+
type TaskCardBtn struct {
944+
Key string `json:"key"`
945+
Name string `json:"name"`
946+
ReplaceName string `json:"replace_name"`
947+
Color string `json:"color"`
948+
IsBold bool `json:"is_bold"`
949+
}

0 commit comments

Comments
 (0)