forked from xen0n/go-workwx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
70 lines (55 loc) · 1.46 KB
/
example_test.go
File metadata and controls
70 lines (55 loc) · 1.46 KB
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
package workwx_test
import (
"net/http"
"github.com/xen0n/go-workwx"
)
func ExampleWorkwx() {
corpID := "your_corpid"
corpSecret := "your_corpsecret"
agentID := int64(1234567)
client := workwx.New(corpID)
// there're advanced options
_ = workwx.New(
corpID,
workwx.WithQYAPIHost("http://localhost:8888"),
workwx.WithHTTPClient(&http.Client{}),
)
// work with individual apps
app := client.WithApp(corpSecret, agentID)
app.SpawnAccessTokenRefresher()
// see other examples for more details
}
func ExampleWorkwxApp_SendTextMessage() {
corpID := "your_corpid"
corpSecret := "your_corpsecret"
agentID := int64(1234567)
client := workwx.New(corpID)
app := client.WithApp(corpSecret, agentID)
// preferably do this at app initialization
app.SpawnAccessTokenRefresher()
// send to user(s)
to1 := workwx.Recipient{
UserIDs: []string{"testuser"},
}
_ = app.SendTextMessage(&to1, "send to user(s)", false)
// "safe" message
to2 := workwx.Recipient{
UserIDs: []string{"testuser"},
}
_ = app.SendTextMessage(&to2, "safe message", true)
// send to party(parties)
to3 := workwx.Recipient{
PartyIDs: []string{"testdept"},
}
_ = app.SendTextMessage(&to3, "send to party(parties)", false)
// send to tag(s)
to4 := workwx.Recipient{
TagIDs: []string{"testtag"},
}
_ = app.SendTextMessage(&to4, "send to tag(s)", false)
// send to chatid
to5 := workwx.Recipient{
ChatID: "testchat",
}
_ = app.SendTextMessage(&to5, "send to chatid", false)
}