forked from tencent-connect/botgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
39 lines (34 loc) · 843 Bytes
/
main.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
package main
import (
"botgo/handler/group"
"botgo/sdk"
"botgo/sdk/event"
"botgo/sdk/openapi"
"botgo/sdk/token"
"botgo/sdk/websocket"
"context"
"github.com/jinzhu/configor"
"log"
"os"
"time"
)
func main() {
ctx, _ := context.WithCancel(context.Background())
var cfg Config
err := configor.New(&configor.Config{Verbose: true}).Load(&cfg, "config.yaml")
if err != nil {
log.Fatalln(err)
}
botToken := token.BotToken(cfg.AppID, cfg.AccessToken, string(token.TypeBot))
api := sdk.NewOpenAPI(botToken).WithTimeout(3 * time.Second)
openapi.DefaultImpl = api
ws, err := api.WS(ctx, nil, "")
if err != nil {
log.Printf("%+v, err:%v", ws, err)
os.Exit(1)
}
intent := websocket.RegisterHandlers(
event.GroupAtMessageEventHandler(group.HandleGroupAtMessage),
)
sdk.NewSessionManager().Start(ws, botToken, &intent)
}