forked from ConnectAI-E/feishu-openai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
61 lines (49 loc) · 1.5 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"context"
larkim "github.com/larksuite/oapi-sdk-go/v3/service/im/v1"
"log"
"start-feishubot/handlers"
"start-feishubot/initialization"
"start-feishubot/services/openai"
larkcard "github.com/larksuite/oapi-sdk-go/v3/card"
"github.com/gin-gonic/gin"
"github.com/spf13/pflag"
sdkginext "github.com/larksuite/oapi-sdk-gin"
"github.com/larksuite/oapi-sdk-go/v3/event/dispatcher"
)
var (
cfg = pflag.StringP("config", "c", "./config.yaml", "apiserver config file path.")
)
func main() {
initialization.InitRoleList()
pflag.Parse()
config := initialization.LoadConfig(*cfg)
initialization.LoadLarkClient(*config)
gpt := openai.NewChatGPT(*config)
handlers.InitHandlers(gpt, *config)
eventHandler := dispatcher.NewEventDispatcher(
config.FeishuAppVerificationToken, config.FeishuAppEncryptKey).
OnP2MessageReceiveV1(handlers.Handler).
OnP2MessageReadV1(func(ctx context.Context, event *larkim.P2MessageReadV1) error {
return handlers.ReadHandler(ctx, event)
})
cardHandler := larkcard.NewCardActionHandler(
config.FeishuAppVerificationToken, config.FeishuAppEncryptKey,
handlers.CardHandler())
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.POST("/webhook/event",
sdkginext.NewEventHandlerFunc(eventHandler))
r.POST("/webhook/card",
sdkginext.NewCardActionHandlerFunc(
cardHandler))
err := initialization.StartServer(*config, r)
if err != nil {
log.Fatalf("failed to start server: %v", err)
}
}