tttlkkkl / lark

飞书api封装,按需扩展

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lark

飞书 api 简单封装,按需扩展

// 服务器交互测试
import (
	"fmt"
	"log"
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/tttlkkkl/lark"
)

var router *gin.Engine
var chat *lark.Lark

func init() {
	router = gin.Default()
	var err error
	chat, err = lark.NewLark(
		"xx",
		"xx",
		lark.SetReceiveMessageAPI("xx", "xx"),
	)
	if err != nil {
		log.Fatalln("初始化失败", err)
	}
	router.GET("/", func(c *gin.Context) {
		c.Data(200, "", []byte("hello lark!"))
	})
	// 事件处理
	router.Any("/lark/event", func(c *gin.Context) {
		m, err := chat.ReceiveMessage.Handle(c.Request, c.Writer)
		if err != nil {
			log.Println(err)
			c.Data(http.StatusInternalServerError, "", []byte("fail"))
		}
		fmt.Println("--------->>>>>", m, err)
		switch m.GetMessageType() {
		case lark.MTEventCallback:
			// 回调事件
		}
	})
	// card 事件处理
	router.Any("/lark/card/event", func(c *gin.Context) {
		m, err := chat.ReceiveMessage.HandleCard(c.Request, c.Writer)
		if err != nil {
			log.Println(err)
			c.Data(http.StatusInternalServerError, "", []byte("fail"))
		}
		fmt.Println("--------->>>>>", m, err)
	})
}
func main() {
	svr := http.Server{
		Addr:    ":80",
		Handler: router,
	}
	if err := svr.ListenAndServe(); err != nil {
		log.Fatalln(err)
	}
}

About

飞书api封装,按需扩展

License:MIT License


Languages

Language:Go 99.1%Language:Makefile 0.9%