forked from zhaoyunxing92/dingtalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_corp_conv_msg_test.go
243 lines (189 loc) · 6.1 KB
/
api_corp_conv_msg_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
/*
* Copyright 2020 zhaoyunxing.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dingtalk
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/zhaoyunxing92/dingtalk/v2/domain/message"
"github.com/zhaoyunxing92/dingtalk/v2/request"
)
func TestDingTalk_SendTemplateMessage(t *testing.T) {
t.Skip()
res, err := isv.SendTemplateMessage(
request.NewSendTemplateMessage(1332307896, "80424a44cb444c53a071aae34c0fd140").
SetUserIds("manager7556", "manager7556").
SetData("msg", "发送模板消息测试").
Build())
assert.Nil(t, err)
assert.NotNil(t, res)
}
func TestDingTalk_GetMessageProgress(t *testing.T) {
t.Skip()
res, err := client.GetMessageSendResult(1332307896, 474307154979)
assert.Nil(t, err)
assert.NotNil(t, res)
}
func TestDingTalk_SendCorpConvMessage_Text(t *testing.T) {
msg := message.NewTextMessage("可以撤回的消息")
res, err := client.SendCorpConvMessage(
request.NewCorpConvMessage(msg).
SetAgentId(1244553273).
SetUserIds("manager164").
Build())
assert.Nil(t, err)
assert.NotNil(t, res)
assert.Equal(t, res.TaskId > 0, true)
}
func TestDingTalk_SendCorpConvMessage_Link(t *testing.T) {
msg := message.NewLinkMessage("消息标题,建议100字符以内",
"消息描述,建议500字符以内", "@lADOADmaWMzazQKA", "https://github.com/zhaoyunxing92/dingtalk")
res, err := client.SendCorpConvMessage(
request.NewCorpConvMessage(msg).
SetUserIds("manager164").
Build())
assert.Nil(t, err)
assert.NotNil(t, res)
}
func TestDingTalk_SendCorpConvMessage_Image(t *testing.T) {
msg := message.NewImageMessages("@lADOADmaWMzazQKA")
res, err := client.SendCorpConvMessage(
request.NewCorpConvMessage(msg).
SetUserIds("manager164").
Build())
assert.Nil(t, err)
assert.NotNil(t, res)
}
func TestDingTalk_SendCorpConvMessage_File(t *testing.T) {
msg := message.NewFileMessage("@lADOADmaWMzazQKA")
res, err := client.SendCorpConvMessage(
request.NewCorpConvMessage(msg).
SetUserIds("manager164").
Build())
assert.Nil(t, err)
assert.NotNil(t, res)
}
func TestDingTalk_SendCorpConvMessage_Voice(t *testing.T) {
voice := message.NewVoiceMessage("@lADOADmaWMzazQKA", 10)
res, err := client.SendCorpConvMessage(
request.NewCorpConvMessage(voice).
SetUserIds("manager7556").
Build())
assert.Nil(t, err)
assert.NotNil(t, res)
}
func TestDingTalk_SendCorpConvMessage_OA(t *testing.T) {
msg := message.NewOaMessage("消息的头部标题", "FFBBBBBB", "http://dingtalk.com",
"http://dingtalk.com")
msg.Body.Title = "消息体标题消息体标题"
msg.Body.Content = "消息体的内容,最多显示3行"
msg.Body.MediaId = "@lADOADmaWMzazQKA"
msg.Body.Forms = []message.Form{
{Key: "姓名", Value: "张三"},
{Key: "年龄", Value: "20"},
{Key: "身高", Value: "1.8m"},
{Key: "体重", Value: "70kg"},
{Key: "学历", Value: "本科"},
{Key: "爱好", Value: "打球、听歌"},
}
msg.Rich = &message.Rich{
Num: "15.6",
Unit: "元",
}
msg.Author = "李四"
msg.StatusBar.Value = "进行中"
msg.StatusBar.BackColor = "0xFFF65E5E"
res, err := client.SendCorpConvMessage(
request.NewCorpConvMessage(msg).
SetAgentId(1332307896).
SetUserIds("manager164").
Build())
assert.Nil(t, err)
assert.NotNil(t, res)
}
func TestDingTalk_SendCorpConvMessage_Markdown(t *testing.T) {
markdown := `# 这是支持markdown的文本
## 标题2
* 列表1
![alt 啊](https://img.alicdn.com/tps/TB1XLjqNVXXXXc4XVXXXXXXXXXX-170-64.png)`
msg := message.NewMarkDownMessage("首屏会话透出的展示内容", markdown)
res, err := client.SendCorpConvMessage(
request.NewCorpConvMessage(msg).
SetUserIds("manager164").
Build())
assert.Nil(t, err)
assert.NotNil(t, res)
}
func TestDingTalk_SendCorpConvMessage_Card(t *testing.T) {
content := `# 这是支持markdown的文本
## 标题2
* 列表1
![alt 啊](https://img.alicdn.com/tps/TB1XLjqNVXXXXc4XVXXXXXXXXXX-170-64.png)`
msg := message.NewCardMessage(content)
msg.Title = "是透出到会话列表和通知的文案"
msg.SingleTitle = "查看详情"
msg.SingleUrl = "https://open.dingtalk.com"
res, err := client.SendCorpConvMessage(
request.NewCorpConvMessage(msg).
SetUserIds("manager164").
Build())
assert.Nil(t, err)
assert.NotNil(t, res)
}
func TestDingTalk_SendCorpConvMessage_CardButtons(t *testing.T) {
content := `# 这是支持markdown的文本
## 标题2
* 列表1
![alt 啊](https://img.alicdn.com/tps/TB1XLjqNVXXXXc4XVXXXXXXXXXX-170-64.png)`
msg := message.NewCardMessage(content)
msg.Title = "是透出到会话列表和通知的文案"
msg.BtnOrientation = "1"
msg.CardButtons = []message.CardButton{
{"一个按钮", "https://www.taobao.com"},
{"两个按钮", "https://www.tmall.com"},
}
res, err := client.SendCorpConvMessage(
request.NewCorpConvMessage(msg).
SetUserIds("manager164").
Build())
assert.Nil(t, err)
assert.NotNil(t, res)
}
func TestDingTalk_UpdateCorpConvMessageStatus(t *testing.T) {
t.Skip()
res, err := isv.UpdateCorpConvMessageStatus(
request.NewUpdateCorpConvMsgStatus(472420145901, "完成").
SetAgentId(1332307896).
SetStatusBgColor("0xFF78C06E").
Build())
assert.Nil(t, err)
assert.NotNil(t, res)
}
func TestDingTalk_GetMessageSendResult(t *testing.T) {
t.Skip()
res, err := isv.GetMessageSendResult(1332307896, 474307154979)
assert.Nil(t, err)
assert.NotNil(t, res)
}
func TestDingTalk_RecallCorpConvMessage(t *testing.T) {
t.Skip()
res, err := isv.RecallCorpConvMessage(472428178475, 1332307896)
assert.Nil(t, err)
assert.NotNil(t, res)
}
func TestNewTextMessage_Json(t *testing.T) {
msg := message.NewTextMessage("可以撤回的消息")
println(msg.String())
}