Skip to content

Commit 58c2253

Browse files
author
yisu
committed
added Robot API
1 parent 29fb517 commit 58c2253

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

Diff for: api_callback_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import (
55
)
66

77
func TestRegisterCallback(t *testing.T) {
8-
err := c.UpdateCallback([]string{"user_modify_org"}, "hello", "1234567890123456789012345678901234567890aes", "https://myalert.info/dingtalk/callback/")
8+
err := c.UpdateCallback([]string{"user_modify_org"}, "hello", "1234567890123456789012345678901234567890aes", "https://go.myalert.info/dingtalk/callback/")
99
if err != nil {
1010
t.Error(err)
1111
}
1212
err = c.DeleteCallback()
1313
if err != nil {
1414
t.Error(err)
1515
}
16-
err = c.RegisterCallback([]string{"user_add_org"}, "hello", "1234567890123456789012345678901234567890aes", "https://myalert.info/dingtalk/callback/")
16+
err = c.RegisterCallback([]string{"user_add_org"}, "hello", "1234567890123456789012345678901234567890aes", "https://go.myalert.info/dingtalk/callback/")
1717
if err != nil {
1818
t.Error(err)
1919
}

Diff for: api_robot.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package godingtalk
2+
3+
import (
4+
"net/url"
5+
)
6+
7+
//SendRobotTextMessage can send a text message to a group chat
8+
func (c *DingTalkClient) SendRobotTextMessage(accessToken string, msg string) error {
9+
var data OAPIResponse
10+
params := url.Values{}
11+
params.Add("access_token", accessToken)
12+
request := map[string]interface{}{
13+
"msgtype": "text",
14+
"text": map[string]interface{}{
15+
"content": msg,
16+
},
17+
}
18+
err := c.httpRPC("robot/send", params, request, &data)
19+
return err
20+
}

Diff for: godingtalk.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type DingTalkClient struct {
2929
//社交相关的属性
3030
SnsAppID string
3131
SnsAppSecret string
32-
SnsAccessToken string
32+
SnsAccessToken string
3333
}
3434

3535
//Unmarshallable is

Diff for: godingtalk_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,11 @@ func TestVoiceMessage(t *testing.T) {
127127
t.Error(err)
128128
}
129129
}
130+
131+
132+
func TestRobotMessage(t *testing.T) {
133+
err := c.SendRobotTextMessage("b7e4b04c66b5d53669affb0b92cf533b9eff9b2bc47f86ff9f4227a2ba73798e", "这是一条测试消息")
134+
if err != nil {
135+
t.Error(err)
136+
}
137+
}

Diff for: transport.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ func (c *DingTalkClient) httpRPC(path string, params url.Values, requestData int
3232
if params == nil {
3333
params = url.Values{}
3434
}
35-
params.Set("access_token", c.AccessToken)
35+
if (params.Get("access_token")=="") {
36+
params.Set("access_token", c.AccessToken)
37+
}
3638
}
3739
return c.httpRequest(path, params, requestData, responseData)
3840
}

0 commit comments

Comments
 (0)