Skip to content

Commit

Permalink
feat: no blocking callback (#72)
Browse files Browse the repository at this point in the history
* feat: no blocking callback

* update example
  • Loading branch information
chyroc authored Jan 12, 2023
1 parent 70cb144 commit 4e44907
Show file tree
Hide file tree
Showing 5 changed files with 516 additions and 99 deletions.
8 changes: 8 additions & 0 deletions _examples/event_callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ func ExampleEventCallback() {
lark.WithEventCallbackVerify("<ENCRYPT_KEY>", "<VERIFICATION_TOKEN>"),
)

// 如果你希望你的回调是非阻塞的
// if you want your callback is non-blocking
cli = lark.New(
lark.WithAppCredential("<APP_ID>", "<APP_SECRET>"),
lark.WithEventCallbackVerify("<ENCRYPT_KEY>", "<VERIFICATION_TOKEN>"),
lark.WithNonBlockingCallback(true),
)

// handle chat create callback
cli.EventCallback.HandlerEventV1P2PChatCreate(func(ctx context.Context, cli *lark.Lark, schema string, header *lark.EventHeaderV1, event *lark.EventV1P2PChatCreate) (string, error) {
_, _, err := cli.Message.Send().ToChatID(event.ChatID).SendText(ctx, "hi")
Expand Down
4 changes: 4 additions & 0 deletions api_event_callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ func (r *EventCallbackService) handlerAllEvent(ctx context.Context, writer io.Wr

func (r *EventCallbackService) handlerCardEvent(ctx context.Context, req *EventCardCallback) (handled bool, s string, err error) {
if r.cli.eventHandler.eventCardHandler != nil {
if r.cli.noBlocking {
go r.cli.eventHandler.eventCardHandler(ctx, r.cli, req)
return true, "", nil
}
s, err := r.cli.eventHandler.eventCardHandler(ctx, r.cli, req)
return true, s, err
}
Expand Down
Loading

0 comments on commit 4e44907

Please sign in to comment.