-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
message_v1.go
68 lines (65 loc) · 1.8 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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
}
func buildOutcomingNotification(om OutcomingMessage) map[string]interface{} {
params := map[string]interface{}{
"msg_type": om.MsgType,
}
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
}