Home

Awesome

lark

codecov go report card test status Apache-2.0 license Go.Dev reference Mentioned in Awesome Go Go project version Used by

中文版 README

Feishu/Lark Open API Go Sdk, Support ALL Open API and Event Callback.

Supported Features

Chat

⁣Click Lark Chat Link to discuss.

Install

go get github.com/chyroc/lark

Docs

https://godoc.org/github.com/chyroc/lark

Support APIs

API Count: 1098, Event Count: 152

<details> <summary> Click This to See ALL </summary> </details>

Usage

Example: create lark client

cli := lark.New(lark.WithAppCredential("<APP_ID>", "<APP_SECRET>"))
cli := lark.New(
    lark.WithAppCredential("<APP_ID>", "<APP_SECRET>"),
    lark.WithOpenBaseURL("https://open.larksuite.com"),
    lark.WithWWWBaseURL("https://www.larksuite.com"),
)
cli := lark.New(
    lark.WithAppCredential("<APP_ID>", "<APP_SECRET>"),
    lark.WithEventCallbackVerify("<ENCRYPT_KEY>", "<VERIFICATION_TOKEN>"),
)
cli := lark.New(
    lark.WithAppCredential("<APP_ID>", "<APP_SECRET>"),
    lark.WithHelpdeskCredential("<HELPDESK_ID>", "HELPDESK_TOKEN"),
)

Example: handle event callback

for more about event callback example, see ./_examples/event_callback.go .

handle message callback example:

cli := lark.New(
    lark.WithAppCredential("<APP_ID>", "<APP_SECRET>"),
    lark.WithEventCallbackVerify("<ENCRYPT_KEY>", "<VERIFICATION_TOKEN>"),
)

// handle message callback
cli.EventCallback.HandlerEventIMMessageReceiveV1(func(ctx context.Context, cli *lark.Lark, schema string, header *lark.EventV2Header, event *lark.EventV2IMMessageReceiveV1) (string, error) {
    _, _, err := cli.Message.Reply(event.Message.MessageID).SendText(ctx, "hi, "+event.Message.Content)
    return "", err
})

http.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) {
    cli.EventCallback.ListenCallback(r.Context(), r.Body, w)
})

fmt.Println("start server ...")
log.Fatal(http.ListenAndServe(":9726", nil))

Example: ISV APP

for more about isv example, see ./_examples/isv.go .

create isv chat:

cli := lark.New(
    lark.WithAppCredential("<APP_ID>", "<APP_SECRET>"),
    lark.WithISV(true),
    lark.WithStore("<NEW_STORE>"),
)

tenantKey1Cli := cli.WithTenant("<TENANT_KEY_1>")
resp, _, err := tenantKey1cli.Chat.CreateChat(ctx, &lark.CreateChatReq{
    Name: ptrString("<CHAT_NAME_1>"),
})
fmt.Println(resp, err)

Example: get bot info

for more about bot example, see ./_examples/bot.go .

get bot info example:

cli := lark.New(lark.WithAppCredential("<APP_ID>", "<APP_SECRET>"))

resp, _, err := cli.Bot.GetBotInfo(ctx, &lark.GetBotInfoReq{})
fmt.Println(resp, err)

Example: send message

for more about send message example, see ./_examples/send_message.go .

send text message example:

cli := lark.New(lark.WithAppCredential("<APP_ID>", "<APP_SECRET>"))

resp, _, err := cli.Message.Send().ToChatID("<CHAT_ID>").SendText(ctx, "<TEXT>")
fmt.Println(resp, err)

Example: other message

for more about other message example, see ./_examples/other_message.go .

send delete message example:

cli := lark.New(lark.WithAppCredential("<APP_ID>", "<APP_SECRET>"))

resp, _, err := cli.Message.DeleteMessage(ctx, &lark.DeleteMessageReq{
    MessageID: "<MESSAGE_ID>",
})
fmt.Println(resp, err)

Example: chat

for more about chat example, see ./_examples/chat.go .

create chat example:

cli := lark.New(lark.WithAppCredential("<APP_ID>", "<APP_SECRET>"))

resp, _, err := cli.Chat.CreateChat(ctx, &lark.CreateChatReq{
    Name: ptrString("<CHAT_NAME>"),
})
fmt.Println(resp, err)

Example: file

for more about file example, see ./_examples/file.go .

upload image example:

cli := lark.New(lark.WithAppCredential("<APP_ID>", "<APP_SECRET>"))

f, err := os.Open("<FILE_PATH>")
if err != nil {
    panic(err)
}
resp, _, err := cli.File.UploadImage(ctx, &lark.UploadImageReq{
    ImageType: lark.ImageTypeMessage,
    Image:     f,
})
fmt.Println(resp, err)

Example: calendar

for more about calendar example, see ./_examples/calendar.go .

create calendar example:

cli := lark.New(lark.WithAppCredential("<APP_ID>", "<APP_SECRET>"))

resp, _, err := cli.Calendar.CreateCalendar(ctx, &lark.CreateCalendarReq{
    Summary: ptrString("<SUMMARY>"),
})
fmt.Println(resp, err)