Skip to content

Commit

Permalink
add method SendTaskCardMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaikangqi committed Jan 7, 2021
1 parent 7d42206 commit 25a4b12
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
33 changes: 33 additions & 0 deletions message.go
@@ -1,6 +1,7 @@
package workwx

import (
"encoding/json"
"errors"
)

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

// SendTaskCardMessage 发送 任务卡片 消息
func (c *WorkwxApp) SendTaskCardMessage(
recipient *Recipient,
title string,
description string,
url string,
taskid string,
btn []TaskCardBtn,
isSafe bool,
) error {
btnByte, err := json.Marshal(btn)
if err != nil {
return errors.New("btn convert to json fail: " + err.Error())
}
var btnSlice []map[string]interface{}
err = json.Unmarshal(btnByte, &btnSlice)
if err != nil {
return errors.New("btn convert to []map fail: " + err.Error())
}
return c.sendMessage(
recipient,
"taskcard",
map[string]interface{}{
"title": title,
"description": description,
"url": url,
"task_id": taskid,
"btn": btnSlice,
}, isSafe,
)
}

// sendMessage 发送消息底层接口
//
// 收件人参数如果仅设置了 `ChatID` 字段,则为【发送消息到群聊会话】接口调用;
Expand Down
9 changes: 9 additions & 0 deletions models.go
Expand Up @@ -938,3 +938,12 @@ type respOAGetApprovalDetail struct {
// Info 审批申请详情
Info OAApprovalDetail `json:"info"`
}

// TaskCardBtn 任务卡片消息按钮
type TaskCardBtn struct {
Key string `json:"key"`
Name string `json:"name"`
ReplaceName string `json:"replace_name"`
Color string `json:"color"`
IsBold bool `json:"is_bold"`
}

0 comments on commit 25a4b12

Please sign in to comment.