-
Notifications
You must be signed in to change notification settings - Fork 0
/
agent.go
46 lines (35 loc) · 1.25 KB
/
agent.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
package main
import (
"fmt"
"log"
"net/http"
"github.com/carrot-forest/CarrotaAgent/api"
"github.com/carrot-forest/CarrotaAgent/carrota"
"github.com/carrot-forest/CarrotaAgent/feishu"
plugincenter "github.com/carrot-forest/CarrotaAgent/plugin-center"
)
func main() {
carrota.LoadConfig("config.yaml")
pluginCenter := plugincenter.NewPluginCenter().
WithAddress(carrota.C.PluginCenter.IP, carrota.C.PluginCenter.Port).
WithBasePath(carrota.C.PluginCenter.API.BasePath).
WithMessageReport(carrota.C.PluginCenter.API.MessageReport)
pluginCenter.Build()
api := api.NewAPI().WithBasePath(carrota.C.API.BasePath)
for _, f := range carrota.C.Feishu {
fmt.Printf("add bot %s [%s]\n", f.BotName, f.BotID)
feishuBot := feishu.NewFeishuBot(f.BotName, f.BotID).
WithAppInfo(f.AppID, f.AppSecret).
WithCallBackInfo(f.EncryptKey, f.VerificationToken).
WithPluginCenter(pluginCenter)
feishuBot.Build()
feishuBot.AddHandlerP2PChatCreate()
feishuBot.AddHandlerIMMessageReceive()
feishuBot.AddHandlerChatMemberBotAdded()
feishuBot.Runhandler(f.CallbackAPI)
api = api.WithFeishuBot(feishuBot)
}
api.AddAPIMessageSend(carrota.C.API.MessageSendAPI)
fmt.Println("start server ...")
log.Fatal(http.ListenAndServe(":"+carrota.C.Port, nil))
}