Skip to content

Repository files navigation

Lark Channel SDK for Go

中文文档

channel-sdk-go is a Go package for building Feishu and Lark conversational bots. It provides one high-level Channel entry point for WebSocket event listening, normalized inbound events, outbound messaging, media handling, interactive card callbacks, policy controls, and streaming replies.

Requires Go 1.18 or later.

Install

go get github.com/larksuite/channel-sdk-go

Minimal Example

package main

import (
	"context"
	"log"
	"os"

	channel "github.com/larksuite/channel-sdk-go"
)

func main() {
	ch, err := channel.New(os.Getenv("APP_ID"), os.Getenv("APP_SECRET"))
	if err != nil {
		log.Fatalf("create channel: %v", err)
	}

	ch.OnMessage(func(ctx context.Context, msg *channel.NormalizedMessage) error {
		_, err := ch.Send(ctx, &channel.SendInput{
			ReceiveID: msg.ChatID,
			Text:      "received: " + msg.Content,
		})
		return err
	})

	if err := ch.Start(context.Background()); err != nil {
		log.Fatalf("start channel: %v", err)
	}
}

Start(ctx) opens the WebSocket connection and blocks until the connection ends. Send and Stream use REST APIs and can be called without Start.

Documentation

Topic Description
Documentation index All user guides and examples
Quickstart Prepare an app, configure events, and run an echo bot
API reference Constructor options, defaults, methods, models, and errors
Receiving events Message normalization, callbacks, ordering, and concurrency
Sending messages SendInput parameters, target detection, message types, and replies
Streaming replies Markdown and interactive-card stream controllers
Media Upload from keys, files, bytes, or URLs and download resources
Policy and safety Admission policy, batching, deduplication, and stale-event handling
Migration guide Move from oapi-sdk-go/v3/channel
Troubleshooting Events, permissions, sending, media, and streaming diagnostics
E2E testing Run real Feishu/Lark end-to-end tests

Examples

Package Boundary

Application code should normally import only the root package:

import channel "github.com/larksuite/channel-sdk-go"

The public types package is available when explicit type imports or default configuration values are useful. Packages under internal are implementation details and are not part of the compatibility contract.

This release receives events and callbacks through WebSocket long connections. It does not expose an HTTP webhook adapter. Use RawClient() or the main oapi-sdk-go/v3 module when an integration needs OpenAPI capabilities outside the Channel surface.

Local Development

go test ./...
go test -race ./...
go test ./examples/...

Real E2E tests use the e2e build tag and are not included in normal unit tests:

CHANNEL_E2E_DRY_RUN=1 go test -tags=e2e ./e2e -run TestChannelE2E -v

Contributing

Please read CONTRIBUTING.md before submitting a pull request. All contributors must follow our Code of Conduct.

Security

Report potential vulnerabilities according to SECURITY.md. Please do not disclose security vulnerabilities through public GitHub issues.

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages