-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase_test.go
301 lines (294 loc) · 10.6 KB
/
base_test.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
package feishu
import (
"os"
"testing"
)
func TestTextMessage_ToMessageMap(t *testing.T) {
text := NewTextMessage("新更新提醒", false)
client := NewClient()
client.Webhook = os.Getenv("webhook")
client.Secret = os.Getenv("secret")
rep, err := client.SendMessage(text)
if err != nil {
t.Error("send message error", err)
}
if rep.IsSuccess() {
t.Log("send message success")
} else {
t.Errorf("send message failed: code %d, msg: %s", rep.Code, rep.Msg)
}
}
func TestTextMessage_ToMessageMap_AtAll(t *testing.T) {
text := NewTextMessage("新更新提醒", true)
client := NewClient()
client.Webhook = os.Getenv("webhook")
client.Secret = os.Getenv("secret")
rep, err := client.SendMessage(text)
if err != nil {
t.Error("send message error", err)
}
if rep.IsSuccess() {
t.Log("send message success")
} else {
t.Errorf("send message failed: code %d, msg: %s", rep.Code, rep.Msg)
}
}
func TestPostMessage_ToMessageMap(t *testing.T) {
message := NewPostMessage(
NewZhCnLangPostItem(
NewPostItems(
"项目更新通知",
NewPostTags(
NewTextTag("项目有更新: "),
),
).AddContent(
NewPostTags(
NewATag("请查看", "http://www.example.com/"),
NewAtAllAtTag(),
),
),
),
)
client := NewClient()
client.Webhook = os.Getenv("webhook")
client.Secret = os.Getenv("secret")
rep, err := client.SendMessage(message)
if err != nil {
t.Error("send message error", err)
}
if rep.IsSuccess() {
t.Log("send message success")
} else {
t.Errorf("send message failed: code %d, msg: %s", rep.Code, rep.Msg)
}
}
func TestImageMessage_ToMessageMap(t *testing.T) {
message := NewImageMessage("img_ecffc3b9-8f14-400f-a014-05eca1a4310g")
client := NewClient()
client.Webhook = os.Getenv("webhook")
client.Secret = os.Getenv("secret")
rep, err := client.SendMessage(message)
if err != nil {
t.Error("send message error", err)
}
if rep.IsSuccess() {
t.Log("send message success")
} else {
t.Errorf("send message failed: code %d, msg: %s", rep.Code, rep.Msg)
}
}
func TestInteractiveMessage_ToMessageMap(t *testing.T) {
message := NewInteractiveMessage()
message.SetConfig(
NewCardConfig().
SetWideScreenMode(true).
SetEnableForward(true),
).AddElements(
NewCardElement(
NewCardText(Md, "**西湖**,位于浙江省杭州市西湖区龙井路1号,杭州市区西部,景区总面积49平方千米,汇水面积为21.22平方千米,湖面面积为6.38平方千米。"),
),
NewCardAction(
NewButtonActionElement(
NewCardText(Md, "更多景点介绍 :玫瑰:"),
).SetUrl("https://www.example.com").SetType(DefaultType),
),
).SetHeader(
NewCardHeader(NewCardTitle("今日旅游推荐", nil)),
)
client := NewClient()
client.Webhook = os.Getenv("webhook")
client.Secret = os.Getenv("secret")
rep, err := client.SendMessage(message)
if err != nil {
t.Error("send message error", err)
}
if rep.IsSuccess() {
t.Log("send message success")
} else {
t.Errorf("send message failed: code %d, msg: %s", rep.Code, rep.Msg)
}
}
func TestInteractiveMessage_ToMessageMap1(t *testing.T) {
// 醒目的通知
message := NewInteractiveMessage()
message.SetConfig(
NewCardConfig().SetWideScreenMode(true),
).SetHeader(
NewCardHeader(NewCardTitle("你有一个休假申请待审批", nil)).SetTemplate(Indigo),
).AddElements(
NewCardElement(nil).
AddFields(
NewCardField(true, NewCardText(Md, "**申请人**\n王晓磊")),
NewCardField(true, NewCardText(Md, "**休假类型:**\n年假")),
NewCardField(false, NewCardText(Md, "")),
NewCardField(false, NewCardText(Md, "**时间:**\n2020-4-8 至 2020-4-10(共3天)")),
NewCardField(false, NewCardText(Md, "")),
NewCardField(true, NewCardText(Md, "**备注**\n因家中有急事,需往返老家,故请假")),
),
NewCardHr(),
NewCardAction(
NewButtonActionElement(NewCardText(Text, "批准")).
SetType(PrimaryType).SetValue(map[string]interface{}{"chosen": "approve"}),
NewButtonActionElement(NewCardText(Text, "拒绝")).
SetType(PrimaryType).SetValue(map[string]interface{}{"chosen": "decline"}),
).SetLayout(
Bisected,
),
)
client := NewClient()
client.Webhook = os.Getenv("webhook")
client.Secret = os.Getenv("secret")
rep, err := client.SendMessage(message)
if err != nil {
t.Error("send message error", err)
}
if rep.IsSuccess() {
t.Log("send message success")
} else {
t.Errorf("send message failed: code %d, msg: %s", rep.Code, rep.Msg)
}
}
func TestInteractiveMessage_ToMessageMap2(t *testing.T) {
// 醒目的通知
message := NewInteractiveMessage()
message.SetConfig(
NewCardConfig().SetWideScreenMode(true),
).SetHeader(
NewCardHeader(NewCardTitle("🥤 下午的奶茶发车了,你要上车么", nil)).SetTemplate(Indigo),
).AddElements(
NewCardHr(),
NewCardAction(
NewButtonActionElement(NewCardText(Text, "😍 带我!带我!!")).
SetType(DefaultType).SetValue(map[string]interface{}{"chosen": "option1"}),
NewButtonActionElement(NewCardText(Text, "🤐 告辞…")).
SetType(DefaultType).SetValue(map[string]interface{}{"chosen": "option2"}),
),
NewCardNote(
NewCardText(Text, "创建者:王大明 🔐本投票为匿名投票"),
),
)
client := NewClient()
client.Webhook = os.Getenv("webhook")
client.Secret = os.Getenv("secret")
rep, err := client.SendMessage(message)
if err != nil {
t.Error("send message error", err)
}
if rep.IsSuccess() {
t.Log("send message success")
} else {
t.Errorf("send message failed: code %d, msg: %s", rep.Code, rep.Msg)
}
}
func TestInteractiveMessage_ToMessageMap3(t *testing.T) {
// 醒目的通知
message := NewInteractiveMessage()
message.SetConfig(
NewCardConfig().SetWideScreenMode(true),
).SetHeader(
NewCardHeader(NewCardTitle("🐈 英国短毛猫", nil)).SetTemplate(Indigo),
).AddElements(
NewCardElement(
NewCardText(Md, "英国短毛猫,体形圆胖,四肢短粗发达,毛短而密,头大脸圆,对人友善。 \n其历史可追溯至古罗马时期的家猫,由于拥有悠久的育种历史,称得上是猫家族中的典范。"),
).SetExtra(
NewCardImage("img_1cad0e51-26f6-492a-8280-a47057b09a0g", NewCardText(Text, "图片")),
),
NewCardElement(
nil,
).AddFields(
NewCardField(true, NewCardText(Md, "**中文学名:**\n英国短毛猫")),
NewCardField(true, NewCardText(Md, "**拉丁学名:**\nFelinae")),
NewCardField(false, NewCardText(Text, "")),
NewCardField(true, NewCardText(Md, "**体形:**\n圆胖")),
NewCardField(true, NewCardText(Md, "**被毛:**\n短而浓密、俗称地毯毛")),
),
NewCardHr(),
NewCardElement(
NewCardText(Md, "**1 形态特征**\n\n 🔵 外形:身体厚实,胸部饱满宽阔,腿部粗壮,爪子浑圆,尾巴的根部粗壮,尾尖钝圆。\n\n🔵 毛色:共有十五种品种被承认,其中最著名的是蓝色系的英国短毛猫。 "),
).SetExtra(
NewCardImage("img_70558e3a-2eef-4e8f-9a07-a701c165431g", NewCardText(Text, "图片")),
),
NewCardNote(
NewCardImage("img_e61db329-2469-4da7-8f13-2d2f284c3b1g", NewCardText(Text, "图片")),
NewCardText(Text, "以上资料来自头条百科"),
),
)
client := NewClient()
client.Webhook = os.Getenv("webhook")
client.Secret = os.Getenv("secret")
rep, err := client.SendMessage(message)
if err != nil {
t.Error("send message error", err)
}
if rep.IsSuccess() {
t.Log("send message success")
} else {
t.Errorf("send message failed: code %d, msg: %s", rep.Code, rep.Msg)
}
}
func TestInteractiveMessage_ToMessageMap4(t *testing.T) {
// 醒目的通知
message := NewInteractiveMessage()
message.SetConfig(
NewCardConfig().SetWideScreenMode(true),
).SetHeader(
NewCardHeader(NewCardTitle("🎉第一天,做点什么好呢?", nil)).SetTemplate(Wathet),
).AddElements(
NewCardImage("img_770020cd-f92e-4a1f-ac5f-20047cf1731g", NewCardText(Text, "")),
NewCardElement(NewCardText(Md, "**换个头像吧!这6件事助你开启Lark第一天** [点击查看>>](https://www.larksuite.com/hc/en-US/articles/360042500034)")),
NewCardHr(),
NewCardElement(NewCardText(Md, "**【聊天】消息串、表情回复?高效沟通很轻松** \n[点击查看>>](https://www.larksuite.com/hc/en-US/articles/360023545914)")).SetExtra(
NewCardImage("img_50b4fd3f-4077-4e4b-b92c-664039a6153g", NewCardText(Text, "")),
),
NewCardHr(),
NewCardElement(NewCardText(Md, "**【会议】多人异地办公难?音视频会议来帮你** \n[点击查看>>](https://www.larksuite.com/hc/en-US/articles/360035593213)")).
SetExtra(
NewCardImage("img_54b18a36-81b0-4776-9f47-854f9da6cd3g", NewCardText(Text, "")),
),
NewCardHr(),
NewCardNote(
NewCardImage("img_5aea87b0-63bc-4a52-9ca4-ce2e58468e5g", NewCardText(Text, "")),
NewCardText(Text, "回复“退订”不再接收此订阅信息"),
),
)
client := NewClient()
client.Webhook = os.Getenv("webhook")
client.Secret = os.Getenv("secret")
rep, err := client.SendMessage(message)
if err != nil {
t.Error("send message error", err)
}
if rep.IsSuccess() {
t.Log("send message success")
} else {
t.Errorf("send message failed: code %d, msg: %s", rep.Code, rep.Msg)
}
}
func TestInteractiveMessage_ToMessageMap5(t *testing.T) {
// 醒目的通知
message := NewInteractiveMessage()
message.SetConfig(
NewCardConfig().SetWideScreenMode(true),
).SetHeader(
NewCardHeader(NewCardTitle("📚晒挚爱好书,赢读书礼金", nil)).SetTemplate(Turquoise),
).AddElements(
NewCardImage("img_7ea74629-9191-4176-998c-2e603c9c5e8g", NewCardText(Text, "图片")),
NewCardElement(NewCardText(Md, "你是否曾因为一本书而产生心灵共振,开始感悟人生?\n你有哪些想极力推荐给他人的珍藏书单?\n\n加入 **4·23 飞书读书节**,分享你的**挚爱书单**及**读书笔记**,**赢取千元读书礼**!\n\n📬 填写问卷,晒出你的珍藏好书\n😍 想知道其他人都推荐了哪些好书?马上[入群围观](https://feishu.cn)\n📝 用[读书笔记模板](https://feishu.cn)(桌面端打开),记录你的心得体会\n🙌 更有惊喜特邀嘉宾 4月12日起带你共读")),
NewCardAction(
NewButtonActionElement(NewCardText(Text, "立即推荐好书")).SetType(PrimaryType).SetUrl("https://feishu.cn"),
NewButtonActionElement(NewCardText(Text, "查看活动指南")).SetType(DefaultType).SetUrl("https://feishu.cn"),
),
)
client := NewClient()
client.Webhook = os.Getenv("webhook")
client.Secret = os.Getenv("secret")
rep, err := client.SendMessage(message)
if err != nil {
t.Error("send message error", err)
}
if rep.IsSuccess() {
t.Log("send message success")
} else {
t.Errorf("send message failed: code %d, msg: %s", rep.Code, rep.Msg)
}
}