Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions biz/client/larkbot/larkbot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package larkbot

import (
"context"
"fmt"
larkcore "github.com/larksuite/oapi-sdk-go/v3/core"
"github.com/larksuite/oapi-sdk-go/v3/event/dispatcher"
larkim "github.com/larksuite/oapi-sdk-go/v3/service/im/v1"
"rainbot/biz/config"
)

type LarkEvent interface {
}
type larkEventClient struct {
event *dispatcher.EventDispatcher
}

func NewClient() LarkEvent {
return &larkEventClient{
event: dispatcher.NewEventDispatcher(config.LarkBotConfig.Token, ""),
}
}
func (l *larkEventClient) SendMsg() {

}
func callBackEvent(ctx context.Context, event *larkim.P2MessageReceiveV1) error {
fmt.Println(larkcore.Prettify(event))
fmt.Println(event.RequestId())
return nil
}
11 changes: 9 additions & 2 deletions biz/config/global.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package config

const defaultConfigName = "global"
const miniMaxConfigName = "minimax"
const larkbotConfigName = "larkbot"

type global struct {
type miniMax struct {
GroupID string `json:"group_id" yaml:"group_id"`
Secret string `json:"secret" yaml:"secret"`
Host string `json:"host" yaml:"host"`
}

type larkBot struct {
AppID string `json:"app_id" yaml:"app_id"`
Secret string `json:"secret" yaml:"secret"`
Token string `json:"token" yaml:"token"`
}
15 changes: 11 additions & 4 deletions biz/config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ import (
"os"
)

var BaseConfig global
var MiniMaxConfig miniMax
var LarkBotConfig larkBot

func InstallBaseConfig() {
dataBytes, err := os.ReadFile(fmt.Sprintf("./conf/%s.yaml", defaultConfigName))
miniMaxBytes, err := os.ReadFile(fmt.Sprintf("./conf/%s.yaml", miniMaxConfigName))
if err != nil {
panic(err)
}
BaseConfig = global{}
err = yaml.Unmarshal(dataBytes, &BaseConfig)
larkBotBytes, err := os.ReadFile(fmt.Sprintf("./conf/%s.yaml", larkbotConfigName))
MiniMaxConfig = miniMax{}
LarkBotConfig = larkBot{}
err = yaml.Unmarshal(miniMaxBytes, &MiniMaxConfig)
if err != nil {
panic(err)
}
err = yaml.Unmarshal(larkBotBytes, &LarkBotConfig)
if err != nil {
panic(err)
}
Expand Down
5 changes: 5 additions & 0 deletions biz/handler/larkbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handler
import (
"context"
"github.com/cloudwego/hertz/pkg/app"
lark_hertz "github.com/hertz-contrib/lark-hertz"
"net/http"
"rainbot/biz/model"
)
Expand All @@ -15,3 +16,7 @@ func Verify(ctx context.Context, c *app.RequestContext) {
}
c.JSON(http.StatusOK, &model.VerifyResp{Challenge: req.Challenge})
}

func ReceiveEvent(ctx context.Context, c *app.RequestContext) {
lark_hertz.NewEventHandlerFunc("")
}
6 changes: 5 additions & 1 deletion biz/service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ package service
import (
"rainbot/biz/config"
"rainbot/biz/service/chat"
"rainbot/biz/service/larkbot"
)

type Service interface {
chat.MiniMaxGPTService
larkbot.LarkBotService
}

type serviceImpl struct {
chat.MiniMaxGPTServiceImpl
larkbot.LarkBotServiceImpl
}

func (s *serviceImpl) Init() {
s.MiniMaxGPTServiceImpl.Init(config.BaseConfig.GroupID, config.BaseConfig.Secret, config.BaseConfig.Host)
s.MiniMaxGPTServiceImpl.Init(config.MiniMaxConfig.GroupID, config.MiniMaxConfig.Secret, config.MiniMaxConfig.Host)
s.LarkBotServiceImpl.Init(config.LarkBotConfig.AppID, config.LarkBotConfig.Secret)
}

func Build() Service {
Expand Down
27 changes: 27 additions & 0 deletions biz/service/larkbot/larkbot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package larkbot

import (
lark_hertz "github.com/hertz-contrib/lark-hertz"
lark "github.com/larksuite/oapi-sdk-go/v3"
"github.com/larksuite/oapi-sdk-go/v3/event/dispatcher"
)

type LarkBotService interface {
}

type LarkBotServiceImpl struct {
Cli *lark.Client
}

func (l *LarkBotServiceImpl) Init(appID string, secret string) {
l.Cli = lark.NewClient(appID, secret)
}

func (l *LarkBotServiceImpl) loop() {
handler := dispatcher.NewEventDispatcher("", "").OnP2MessageReceiveV1()
lark_hertz.NewEventHandlerFunc(handler)
}

func (l *LarkBotServiceImpl) Revice() {

}
2 changes: 1 addition & 1 deletion conf/config.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# you should new global.yaml for example
# you should new minimax.yaml for example


# minimax config
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ require (
github.com/bytedance/gopkg v0.0.0-20220413063733-65bf48ffb3a7 // indirect
github.com/bytedance/sonic v1.8.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/chyroc/lark v0.0.110 // indirect
github.com/cloudwego/netpoll v0.3.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/golang/protobuf v1.5.0 // indirect
github.com/henrylee2cn/ameda v1.4.10 // indirect
github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8 // indirect
github.com/hertz-contrib/lark-hertz v1.0.0 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/larksuite/oapi-sdk-go/v3 v3.0.20 // indirect
github.com/nyaruka/phonenumbers v1.0.55 // indirect
github.com/tidwall/gjson v1.13.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/bytedance/sonic v1.8.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZX
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams=
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
github.com/chyroc/lark v0.0.110 h1:iZYOkL+KApif4tQb7fQZvzKFo1X7Yt+h/MdUAXAH/0s=
github.com/chyroc/lark v0.0.110/go.mod h1:pwj/p5/dHocDYkTPvHF9ig+O+xSkqfFC4T0cjcjMhUc=
github.com/cloudwego/hertz v0.6.2 h1:8NM0yHbyv8B4dNYgICirk733S7monTNB+uR9as1It1Y=
github.com/cloudwego/hertz v0.6.2/go.mod h1:2em2hGREvCBawsTQcQxyWBGVlCeo+N1pp2q0HkkbwR0=
github.com/cloudwego/netpoll v0.3.1 h1:xByoORmCLIyKZ8gS+da06WDo3j+jvmhaqS2KeKejtBk=
Expand All @@ -31,10 +33,14 @@ github.com/henrylee2cn/ameda v1.4.10 h1:JdvI2Ekq7tapdPsuhrc4CaFiqw6QXFvZIULWJgQy
github.com/henrylee2cn/ameda v1.4.10/go.mod h1:liZulR8DgHxdK+MEwvZIylGnmcjzQ6N6f2PlWe7nEO4=
github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8 h1:yE9ULgp02BhYIrO6sdV/FPe0xQM6fNHkVQW2IAymfM0=
github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8/go.mod h1:Nhe/DM3671a5udlv2AdV2ni/MZzgfv2qrPL5nIi3EGQ=
github.com/hertz-contrib/lark-hertz v1.0.0 h1:dWzPvB4TozmEhJD2vxIsSEcIycSrHCVK2MhZiOvtKGc=
github.com/hertz-contrib/lark-hertz v1.0.0/go.mod h1:b6g6kT5vnrN0xEtRBv+LWk+I5+2pfN7zqkHyIPVfxIg=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/larksuite/oapi-sdk-go/v3 v3.0.20 h1:qwH7lEr2WNWgbxI/v2jGWujFmKMht2ZCw3bYS1fXkDE=
github.com/larksuite/oapi-sdk-go/v3 v3.0.20/go.mod h1:FKi8vBgtkBt/xNRQUwdWvoDmsPh7/wP75Sn5IBIBQLk=
github.com/nyaruka/phonenumbers v1.0.55 h1:bj0nTO88Y68KeUQ/n3Lo2KgK7lM1hF7L9NFuwcCl3yg=
github.com/nyaruka/phonenumbers v1.0.55/go.mod h1:sDaTZ/KPX5f8qyV9qN+hIm+4ZBARJrupC6LuhshJq1U=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -53,6 +59,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/tidwall/gjson v1.9.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.13.0 h1:3TFY9yxOQShrvmjdM76K+jc66zJeT6D3/VFFYCGQf7M=
github.com/tidwall/gjson v1.13.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
Expand Down
1 change: 1 addition & 0 deletions router.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.