From 805695a955d90426c79ff6efc7213a5467d7e760 Mon Sep 17 00:00:00 2001 From: David Zhang Date: Thu, 4 Jan 2024 11:17:25 +0800 Subject: [PATCH] chore: minor fixes and hello 2024 --- README.md | 20 ++++++++++++++++++-- event_v2.go | 4 ++-- logger.go | 8 -------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 305ed3f..51ee14d 100644 --- a/README.md +++ b/README.md @@ -219,6 +219,7 @@ We have already implemented HTTP middlewares to support event handling: - [Hertz Middleware](https://github.com/go-lark/lark-hertz) Example: [examples/gin-middleware](https://github.com/go-lark/examples/tree/main/gin-middleware) +Example: [examples/hertz-middleware](https://github.com/go-lark/examples/tree/main/hertz-middleware) #### URL Challenge @@ -253,7 +254,20 @@ r.POST("/", func(c *gin.Context) { }) ``` -#### Receiving Message +#### Card Callback + +We may also setup callback for card actions (e.g. button). The URL challenge part is the same. + +We may use `LarkCardHandler` to handle the actions: +```go +r.Use(middleware.LarkCardHandler()) +r.POST("/callback", func(c *gin.Context) { + if card, ok := middleware.GetCardCallback(c); ok { + } +}) +``` + +#### Receiving Message (Event V1) For older bots, please use v1: @@ -310,6 +324,8 @@ Example: [examples/event-forward](https://github.com/go-lark/examples/tree/main/ LARK_OPEN_ID LARK_CHAT_ID LARK_MESSAGE_ID + LARK_WEBHOOK_V2 + LARK_WEBHOOK_V2_SIGNED ``` `LARK_APP_ID` and `LARK_APP_SECRET` are mandatory. Others are required only by specific API tests. @@ -388,4 +404,4 @@ func CopyFile(bot *lark.Bot, fileToken, dstFolderToken, dstName string) (*CopyFi ## License -Copyright (c) David Zhang, 2018-2023. Licensed under MIT License. +Copyright (c) David Zhang, 2018-2024. Licensed under MIT License. diff --git a/event_v2.go b/event_v2.go index b8296e0..c735fa8 100644 --- a/event_v2.go +++ b/event_v2.go @@ -52,9 +52,9 @@ type EventV2UserID struct { // PostEvent with event v2 format // and it's part of EventV2 instead of package method -func (e EventV2) PostEvent(client *http.Client, hookURL string, event EventV2) (*http.Response, error) { +func (e EventV2) PostEvent(client *http.Client, hookURL string) (*http.Response, error) { buf := new(bytes.Buffer) - err := json.NewEncoder(buf).Encode(event) + err := json.NewEncoder(buf).Encode(e) if err != nil { log.Printf("Encode json failed: %+v\n", err) return nil, err diff --git a/logger.go b/logger.go index d8c155c..d51311f 100644 --- a/logger.go +++ b/logger.go @@ -78,11 +78,3 @@ func (bot *Bot) WithContext(ctx context.Context) *Bot { bot.ctx = ctx return bot } - -func (bot Bot) captureOutput(f func()) string { - var buf bytes.Buffer - bot.logger.SetOutput(&buf) - f() - bot.logger.SetOutput(os.Stderr) - return buf.String() -}