-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_test.go
100 lines (88 loc) · 2.23 KB
/
example_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
package slack_test
import (
"fmt"
"os"
"github.com/botopolis/bot"
"github.com/botopolis/slack"
slacker "github.com/nlopes/slack"
)
func Example() {
robot := bot.New(
slack.New(os.Getenv("SLACK_TOKEN")),
)
robot.Enter(func(r bot.Responder) error {
msg := r.Message.Envelope.(*slacker.Message)
r.Send(bot.Message{Text: "Any friend of " + msg.Inviter + " is a friend of mine"})
return nil
},
)
robot.Run()
}
func ExampleAdapter_Send() {
adapter := slack.New(os.Getenv("SLACK_TOKEN"))
adapter.Send(bot.Message{Text: "hello!"})
}
func ExampleAdapter_Send_custom() {
adapter := slack.New(os.Getenv("SLACK_TOKEN"))
adapter.Send(bot.Message{Params: slacker.PostMessageParameters{
Username: "ci",
Attachments: []slacker.Attachment{
{
Color: "danger",
Title: "CI Status",
TitleLink: "http://ci.org/123",
Fields: []slacker.AttachmentField{
{Title: "Passed", Value: "102"},
{Title: "Failed", Value: "3"},
},
},
},
}})
}
func ExampleAdapter_Reply() {
adapter := slack.New(os.Getenv("SLACK_TOKEN"))
fromMessage := bot.Message{
Text: "Hi bot! How are you?",
User: "ali",
Room: "general",
}
adapter.Reply(bot.Message{
Text: "I'm well, thanks!",
Envelope: fromMessage,
})
}
func ExampleAdapter_Topic() {
adapter := slack.New(os.Getenv("SLACK_TOKEN"))
adapter.Topic(bot.Message{
Room: "general",
Topic: "General conversation",
})
}
func ExampleAdapter_React() {
adapter := slack.New(os.Getenv("SLACK_TOKEN"))
fromMessage := slacker.Message{Msg: slacker.Msg{
Timestamp: "2020-01-03T18:23:14Z",
Channel: "general",
}}
adapter.React(bot.Message{
Room: "general",
Topic: "General conversation",
Envelope: fromMessage,
})
}
func ExampleStore() {
adapter := slack.New(os.Getenv("SLACK_TOKEN"))
// The store is only populated if:
// 1. You call adapter.Messages(), which connects it to RTM
adapter.Messages()
// 2. You call store.Update()
adapter.Store.Update()
// Gives access to slack.User
if u, ok := adapter.Store.UserByName("beardroid"); ok {
fmt.Println("Found the bot's real name: " + u.RealName)
}
// Gives access to slack.Channel
if c, ok := adapter.Store.ChannelByName("general"); ok {
fmt.Println(len(c.Members), " many people in general")
}
}