Documentation
¶
Overview ¶
Package feishu provides a client for sending notifications via Feishu (Lark).
It supports two modes of operation:
Webhook mode: Send text and rich-text (post) messages through a Feishu bot webhook URL. This requires only a webhook URL and no app credentials.
SDK mode: Send messages and trigger phone urgent calls through the official Lark Open Platform SDK. This requires an App ID, App Secret, and optionally a User Open ID for urgent calls.
Quick Start ¶
For simple webhook-only usage with the global convenience API:
feishu.Init(feishu.Config{
Webhook: "https://open.feishu.cn/open-apis/bot/v2/hook/xxx",
})
if err := feishu.SendText("Hello from Go!"); err != nil {
log.Fatal(err)
}
For multi-instance or SDK-based usage:
client := feishu.NewClient("webhook-url", "app-id", "app-secret")
if err := client.SendWebhook(feishu.TextReq{...}); err != nil {
log.Fatal(err)
}
Index ¶
- Variables
- func Init(cfg Config)
- func SendRichText(title string, content [][]PostElem) error
- func SendText(text string) error
- func SendUrgentText(text string) error
- type BaseReq
- type Bot
- type Client
- type Config
- type MsgType
- type PostBody
- type PostContent
- type PostContentWrapper
- type PostElem
- type PostReq
- type TextContent
- type TextReq
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotInitialized = errors.New("feishu: client not initialized") ErrNoUserOpenID = errors.New("feishu: user_open_id not configured, cannot send urgent message") )
Common sentinel errors.
Functions ¶
func Init ¶
func Init(cfg Config)
Init initializes the global Feishu bot. It is safe to call multiple times; subsequent calls replace the global instance.
func SendRichText ¶
SendRichText sends a post message with title and content lines via webhook using the global bot.
func SendUrgentText ¶
SendUrgentText sends a text message and triggers a phone call notification using the global bot. Falls back to SendText if SDK is not configured.
Types ¶
type Bot ¶
type Bot struct {
// contains filtered or unexported fields
}
Bot holds the Feishu client and user configuration. Use NewBot for multi-instance usage or Init for the global convenience API.
func NewBot ¶
NewBot creates a new Bot instance from the given Config. Returns nil if neither Webhook nor AppID is configured.
func (*Bot) SendRichText ¶
SendRichText sends a post message with title and content lines via webhook.
func (*Bot) SendUrgentText ¶
SendUrgentText sends a text message to the configured user via SDK, then triggers a phone call notification on that message. Falls back to SendText if SDK is not configured.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps both webhook and official Lark SDK capabilities.
func NewClient ¶
NewClient creates a Client with webhook support. If appID and appSecret are provided, the official Lark SDK client is also initialized.
func (*Client) SendMessage ¶
func (c *Client) SendMessage(ctx context.Context, receiveIDType, receiveID, msgType, content string) (string, error)
SendMessage sends a message via the official SDK and returns the message_id. receiveIDType: "open_id", "user_id", "union_id", "email", "chat_id"
func (*Client) SendWebhook ¶
SendWebhook sends a message via the webhook URL (for text/rich-text bot messages).
type Config ¶
type Config struct {
Webhook string // Webhook URL for bot messages
AppID string // Lark App ID (optional, for SDK features)
AppSecret string // Lark App Secret (optional, for SDK features)
UserOpenID string // User Open ID (optional, for urgent calls)
}
Config holds Feishu notification settings.
type PostBody ¶
type PostBody struct {
ZhCN *PostContent `json:"zh_cn,omitempty"`
EnUS *PostContent `json:"en_us,omitempty"`
}
type PostContent ¶
type PostContentWrapper ¶
type PostContentWrapper struct {
Post PostBody `json:"post"`
}
type PostElem ¶
type PostElem struct {
Tag string `json:"tag"`
Text string `json:"text,omitempty"`
Href string `json:"href,omitempty"`
UserId string `json:"user_id,omitempty"`
UserName string `json:"user_name,omitempty"`
}
func NewTextElem ¶
type PostReq ¶
type PostReq struct {
BaseReq
Content PostContentWrapper `json:"content"`
}
type TextContent ¶
type TextContent struct {
Text string `json:"text"`
}
type TextReq ¶
type TextReq struct {
BaseReq
Content TextContent `json:"content"`
}