-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample_test.go
43 lines (37 loc) · 923 Bytes
/
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
package traqwsbot_test
import (
"context"
"log"
"os"
"github.com/traPtitech/go-traq"
"github.com/traPtitech/traq-ws-bot"
"github.com/traPtitech/traq-ws-bot/payload"
)
func Example() {
bot, err := traqwsbot.NewBot(&traqwsbot.Options{
AccessToken: os.Getenv("ACCESS_TOKEN"), // Required
Origin: "wss://q.trap.jp", // Optional (default: wss://q.trap.jp)
})
if err != nil {
panic(err)
}
bot.OnError(func(message string) {
log.Println("Received ERROR message: " + message)
})
bot.OnMessageCreated(func(p *payload.MessageCreated) {
log.Println("Received MESSAGE_CREATED event: " + p.Message.Text)
_, _, err := bot.API().
MessageApi.
PostMessage(context.Background(), p.Message.ChannelID).
PostMessageRequest(traq.PostMessageRequest{
Content: "oisu-",
}).
Execute()
if err != nil {
log.Println(err)
}
})
if err := bot.Start(); err != nil {
panic(err)
}
}