Skip to content

Commit

Permalink
chore: minor fixes and hello 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
crispgm committed Jan 4, 2024
1 parent 2a5a100 commit 805695a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
4 changes: 2 additions & 2 deletions event_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

0 comments on commit 805695a

Please sign in to comment.