forked from go-lark/lark
/
message_v1.go
37 lines (35 loc) · 1020 Bytes
/
message_v1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package lark
import "strconv"
// BuildOutcomingMessageReq for msg builder
func BuildOutcomingMessageReq(om OutcomingMessage) map[string]interface{} {
params := map[string]interface{}{
"msg_type": om.MsgType,
"chat_id": om.ChatID, // request must contain chat_id, even if it is empty
}
params[om.UIDType] = buildReceiveID(om)
if len(om.RootID) > 0 {
params["root_id"] = om.RootID
}
content := make(map[string]interface{})
if om.Content.Text != nil {
content["text"] = om.Content.Text.Text
}
if om.Content.Image != nil {
content["image_key"] = om.Content.Image.ImageKey
}
if om.Content.ShareChat != nil {
content["share_open_chat_id"] = om.Content.ShareChat.ChatID
}
if om.Content.Post != nil {
content["post"] = *om.Content.Post
}
if om.MsgType == MsgInteractive && om.Content.Card != nil {
params["card"] = *om.Content.Card
}
if len(om.Sign) > 0 {
params["sign"] = om.Sign
params["timestamp"] = strconv.FormatInt(om.Timestamp, 10)
}
params["content"] = content
return params
}