- dingding msg api
This commit is contained in:
30
platformapi/dingdingapi/message.go
Normal file
30
platformapi/dingdingapi/message.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package dingdingapi
|
||||
|
||||
import "strings"
|
||||
|
||||
func (a *API) CorpAsyncSend(agentID int, userIDList, deptIDList []string, isToAllUser bool, msg map[string]interface{}) (err error) {
|
||||
params := map[string]interface{}{
|
||||
"agent_id": agentID,
|
||||
"msg": msg,
|
||||
}
|
||||
if len(userIDList) > 0 {
|
||||
params["userid_list"] = strings.Join(userIDList, ",")
|
||||
}
|
||||
if len(deptIDList) > 0 {
|
||||
params["dept_id_list"] = strings.Join(deptIDList, ",")
|
||||
}
|
||||
if isToAllUser {
|
||||
params["to_all_user"] = isToAllUser
|
||||
}
|
||||
_, err = a.AccessAPI("topapi/message/corpconversation/asyncsend_v2", nil, params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *API) CorpAsyncSendSimple(agentID int, userID, content string) (err error) {
|
||||
return a.CorpAsyncSend(agentID, []string{userID}, nil, false, map[string]interface{}{
|
||||
"msgtype": "text",
|
||||
"text": map[string]interface{}{
|
||||
"content": content,
|
||||
},
|
||||
})
|
||||
}
|
||||
28
platformapi/dingdingapi/message_test.go
Normal file
28
platformapi/dingdingapi/message_test.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package dingdingapi
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCorpAsyncSend(t *testing.T) {
|
||||
err := api.CorpAsyncSend(239461075, []string{
|
||||
"051063452224284964",
|
||||
}, nil, false, map[string]interface{}{
|
||||
"msgtype": "text",
|
||||
"text": map[string]interface{}{
|
||||
"content": `
|
||||
管理用户列表或角色列表。 Casbin 认为由项目自身来管理用户、角色列表更为合适, 用户通常有他们的密码,但是 Casbin 的设计思想并不是把它作为一个存储密码的容器。 而是存储RBAC方案中用户和角色之间的映射关系。
|
||||
`,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestCorpAsyncSendSimple(t *testing.T) {
|
||||
err := api.CorpAsyncSendSimple(239461075, "051063452224284964", `
|
||||
管理用户列表或角色列表。 Casbinadfs 认为由项目自身来管理用户、角色列表更为合适, 用户通常有他们的密码,但是 Casbin 的设计思想并不是把它作为一个存储密码的容器。 而是存储RBAC方案中用户和角色之间的映射关系。
|
||||
`)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user