lark

package module
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

README

NotificationLark Plugin

English | 中文

How to use

To use the NotificationLark plugin with your application, install it using the following command:

./answer build --with github.com/apache/answer-plugins/notification-lark

How to config

For Administrators
Creating a Bot
  1. Create a Bot in Lark or Feishu:

    • Visit Lark or Feishu to create a new bot.
    • Add im:message:send_as_bot Permission to the bot in the Permission & Scopes tab.
    • In the bot settings, enable the Custom Bot Menu and set the action type to Push Event.
    • Configure the menu event with 10001 as the event code. bot menu set
  2. Configure Events and Callbacks:

    • Navigate to the Events & Callbacks tab.
    • Set the Mode of event subscription to Receive events through persistent connection.
    • Add the application.bot.menu_v6 event ID to your Event Configuration. event config
  3. Release the Bot Version: Once the above settings are configured, proceed to release your bot version.

Website Configuration

Set the following parameters based on your requirements:

  • Brand: Choose between Lark and Feishu as they are separate brands.
  • App ID: Your bot's App ID, typically formatted as cli_xxx.
  • App Secret: Your bot's secret key.
  • Verification Token: (Optional) Verification token from the bot Events & Callbacks => Encryption Strategy.
  • Encrypt Key: (Optional) Encrypt key from the bot Events & Callbacks => Encryption Strategy.
For User
  1. Interact with the Bot:
    • Click on the bot menu in the chat interface to trigger interactions.
    • Upon interaction, you will receive your open ID from the bot.
  2. User Settings:
    • Enter your Open ID in the user settings.
    • Select which notifications you wish to receive under Notifications Choices.

Documentation

Index

Constants

View Source
const (
	LarkBindAccountMenuEventKey = "10001"
	NotificationTypeInteractive = "interactive"
	MsgTypeText                 = "text"
	ReceiveIdTypeOpenId         = "open_id"
)

Variables

View Source
var Info embed.FS
View Source
var (
	TagColor = []string{"neutral", "blue", "turquoise", "lime", "orange", "violet", "indigo", "wathet", "green", "yellow", "red", "purple", "carmine"}
)

Functions

func GenerateRandomString

func GenerateRandomString(args *GenerateRandomStringArgs) string

GenerateRandomString use crypto to generate a random string

func PtrBool

func PtrBool(b bool) *bool

func RandomInt

func RandomInt(min, max int64) int64

Types

type Action

type Action struct {
	Tag     string    `json:"tag"`
	Actions []*Button `json:"actions,omitempty"`
}

Action represents actions in a ColumnSet.

type Behavior

type Behavior struct {
	Type       string `json:"type"`
	DefaultURL string `json:"default_url"`
	AndroidURL string `json:"android_url"`
	IOSURL     string `json:"ios_url"`
	PCURL      string `json:"pc_url"`
}

Behavior represents the behavior of a button.

type Button

type Button struct {
	Tag       string         `json:"tag,omitempty"`
	Width     string         `json:"width,omitempty"`
	Text      *Text          `json:"text,omitempty"`
	Behaviors []Behavior     `json:"behaviors,omitempty"`
	Type      string         `json:"type,omitempty"`
	HoverTips *Text          `json:"hover_tips,omitempty"`
	Value     map[string]any `json:"value,omitempty"`
}

Button represents a button component.

func (*Button) MarshalJSON

func (b *Button) MarshalJSON() ([]byte, error)

MarshalJSON customizes the JSON encoding for Button.

type Card

type Card struct {
	Config       *Config       `json:"config"`
	CardLink     *CardLink     `json:"card_link,omitempty"`
	I18nElements *I18nElements `json:"i18n_elements,omitempty"`
	Header       *Header       `json:"header,omitempty"`
}

Card represents the entire JSON structure of a card.

type CardLink struct {
	URL        string `json:"url,omitempty"`
	PCURL      string `json:"pc_url,omitempty"`
	IOSURL     string `json:"ios_url,omitempty"`
	AndroidURL string `json:"android_url,omitempty"`
}

CardLink represents the URLs for different platforms.

type Color

type Color string

Color represents color effects enumeration.

const (
	ColorNeutral   Color = "neutral"
	ColorBlue      Color = "blue"
	ColorTurquoise Color = "turquoise"
	ColorLime      Color = "lime"
	ColorOrange    Color = "orange"
	ColorViolet    Color = "violet"
	ColorIndigo    Color = "indigo"
	ColorWathet    Color = "wathet"
	ColorGreen     Color = "green"
	ColorYellow    Color = "yellow"
	ColorRed       Color = "red"
	ColorPurple    Color = "purple"
	ColorCarmine   Color = "carmine"
)

type Column

type Column struct {
	Tag             string    `json:"tag,omitempty"`
	Elements        []Element `json:"elements,omitempty"`
	Width           string    `json:"width,omitempty"`
	Weight          int       `json:"weight,omitempty"`
	BackgroundStyle string    `json:"background_style,omitempty"`
	VerticalAlign   string    `json:"vertical_align,omitempty"`
	VerticalSpacing string    `json:"vertical_spacing,omitempty"`
	Padding         string    `json:"padding,omitempty"`
}

Column represents a column in a ColumnSet.

func (*Column) MarshalJSON

func (c *Column) MarshalJSON() ([]byte, error)

MarshalJSON customizes the JSON encoding for Column.

type ColumnSet

type ColumnSet struct {
	*Show
	*Action
}

ColumnSet represents a set of columns.

func (*ColumnSet) MarshalJSON

func (cs *ColumnSet) MarshalJSON() ([]byte, error)

MarshalJSON customizes the JSON encoding for ColumnSet.

type Config

type Config struct {
	StreamingMode            *bool    `json:"streaming_mode,omitempty"`
	Summary                  *Summary `json:"summary,omitempty"`
	EnableForward            *bool    `json:"enable_forward,omitempty"`
	UpdateMulti              *bool    `json:"update_multi,omitempty"`
	WidthMode                string   `json:"width_mode,omitempty"`
	UseCustomTranslation     *bool    `json:"use_custom_translation,omitempty"`
	EnableForwardInteraction *bool    `json:"enable_forward_interaction,omitempty"`
	Style                    Style    `json:"style,omitempty"`
}

Config represents the configuration of a card.

type ConfigColor

type ConfigColor struct {
	LightMode string `json:"light_mode,omitempty"`
	DarkMode  string `json:"dark_mode,omitempty"`
}

ConfigColor represents the custom color configuration.

type Element

type Element struct {
	*PlainText
	*Button
}

Element represents a generic element in a card.

func (*Element) MarshalJSON

func (e *Element) MarshalJSON() ([]byte, error)

MarshalJSON customizes the JSON encoding for Element.

type GenerateRandomStringArgs

type GenerateRandomStringArgs struct {
	Length     uint64
	StringPool string
}
type Header struct {
	Title       *Text     `json:"title,omitempty"`
	Subtitle    *Text     `json:"subtitle,omitempty"`
	TextTagList []TextTag `json:"text_tag_list,omitempty"`
	Template    Template  `json:"template,omitempty"`
	UdIcon      *Icon     `json:"ud_icon,omitempty"`
}

Header represents the header component of a card.

type I18n

type I18n struct {
	ZhCn string `json:"zh_cn,omitempty"`
	EnUs string `json:"en_us,omitempty"`
}

I18n represents internationalized text.

type I18nElements

type I18nElements struct {
	ZhCn []ColumnSet `json:"zh_cn,omitempty"`
	EnUs []ColumnSet `json:"en_us,omitempty"`
}

I18nElements represents internationalized elements.

type Icon

type Icon struct {
	Tag    string `json:"tag,omitempty"`
	Token  string `json:"token,omitempty"`
	Color  string `json:"color,omitempty"`
	ImgKey string `json:"img_key,omitempty"`
	Style  *struct {
		Color Color `json:"color,omitempty"`
	} `json:"style,omitempty"`
}

Icon represents an icon component.

type LarkClient

type LarkClient struct {
	// contains filtered or unexported fields
}

func (*LarkClient) Start

func (n *LarkClient) Start() error

type LarkLogger

type LarkLogger struct{}

func (LarkLogger) Debug

func (l LarkLogger) Debug(ctx context.Context, args ...interface{})

func (LarkLogger) Error

func (l LarkLogger) Error(ctx context.Context, args ...interface{})

func (LarkLogger) Info

func (l LarkLogger) Info(ctx context.Context, args ...interface{})

func (LarkLogger) Warn

func (l LarkLogger) Warn(ctx context.Context, args ...interface{})

type Notification

type Notification struct {
	// contains filtered or unexported fields
}

func (*Notification) ConfigFields

func (n *Notification) ConfigFields() []plugin.ConfigField

func (*Notification) ConfigReceiver

func (n *Notification) ConfigReceiver(config []byte) error

func (*Notification) GetNewQuestionSubscribers

func (n *Notification) GetNewQuestionSubscribers() (userIDs []string)

GetNewQuestionSubscribers returns the subscribers of the new question notification

func (Notification) Info

func (n Notification) Info() plugin.Info

func (*Notification) LarkWsEventHub

func (n *Notification) LarkWsEventHub() *dispatcher.EventDispatcher

func (*Notification) LarkWsEventMenuClick

func (n *Notification) LarkWsEventMenuClick(ctx context.Context, event *larkApplication.P2BotMenuV6) error

LarkWsEventMenuClick is the event handler for the menu click event

func (*Notification) Notify

func (n *Notification) Notify(msg plugin.NotificationMessage)

Notify sends a notification to the user

func (*Notification) UserConfigFields

func (n *Notification) UserConfigFields() []plugin.ConfigField

func (*Notification) UserConfigReceiver

func (n *Notification) UserConfigReceiver(userID string, config []byte) error

type NotificationConfig

type NotificationConfig struct {
	Version           string `json:"version"`
	AppID             string `json:"app_id"`
	AppSecret         string `json:"app_secret"`
	VerificationToken string `json:"verification_token"`
	EventEncryptKey   string `json:"event_encrypt_key"`
}

func (*NotificationConfig) GetAppID

func (n *NotificationConfig) GetAppID() string

func (*NotificationConfig) GetAppSecret

func (n *NotificationConfig) GetAppSecret() string

func (*NotificationConfig) GetEventEncryptKey

func (n *NotificationConfig) GetEventEncryptKey() string

func (*NotificationConfig) GetVerificationToken

func (n *NotificationConfig) GetVerificationToken() string

func (*NotificationConfig) GetVersion

func (n *NotificationConfig) GetVersion() string

type PlainText

type PlainText struct {
	Tag  string `json:"tag,omitempty"`
	Text *Text  `json:"text,omitempty"`
	Icon *Icon  `json:"icon,omitempty"`
}

PlainText represents plain text component.

type Show

type Show struct {
	Tag               string   `json:"tag"`
	FlexMode          string   `json:"flex_mode,omitempty"`
	HorizontalSpacing string   `json:"horizontal_spacing,omitempty"`
	BackgroundStyle   string   `json:"background_style,omitempty"`
	Columns           []Column `json:"columns,omitempty"`
}

Show represents the display properties of a ColumnSet.

type Style

type Style struct {
	TextSize map[string]TextSize    `json:"text_size,omitempty"`
	Color    map[string]ConfigColor `json:"color,omitempty"`
}

Style represents the custom font size and color configuration.

type Summary

type Summary struct {
	Content     string            `json:"content,omitempty"`
	I18nContent map[string]string `json:"i18n_content,omitempty"`
}

Summary represents the summary information of a card.

type Template

type Template string

Template represents theme styles enumeration.

const (
	ThemeBlue      Template = "blue"
	ThemeWathet    Template = "wathet"
	ThemeTurquoise Template = "turquoise"
	ThemeGreen     Template = "green"
	ThemeYellow    Template = "yellow"
	ThemeOrange    Template = "orange"
	ThemeRed       Template = "red"
	ThemeCarmine   Template = "carmine"
	ThemeViolet    Template = "violet"
	ThemePurple    Template = "purple"
	ThemeIndigo    Template = "indigo"
	ThemeGrey      Template = "grey"
	ThemeDefault   Template = "default"
)

type Text

type Text struct {
	Tag       string `json:"tag,omitempty"`
	Content   string `json:"content,omitempty"`
	I18n      *I18n  `json:"i18n,omitempty"`
	TextSize  string `json:"text_size,omitempty"`
	TextAlign string `json:"text_align,omitempty"`
	TextColor string `json:"text_color,omitempty"`
	Icon      *Icon  `json:"icon,omitempty"`
}

Text represents a text component with optional internationalization.

type TextSize

type TextSize struct {
	Default string `json:"default,omitempty"`
	PC      string `json:"pc,omitempty"`
	Mobile  string `json:"mobile,omitempty"`
}

TextSize represents the custom text size configuration.

type TextTag

type TextTag struct {
	Tag   string `json:"tag,omitempty"`
	Text  *Text  `json:"text,omitempty"`
	Color string `json:"color,omitempty"`
}

TextTag represents a text tag component.

func (*TextTag) MarshalJSON

func (tt *TextTag) MarshalJSON() ([]byte, error)

MarshalJSON customizes the JSON encoding for TextTag.

type UserConfig

type UserConfig struct {
	OpenId                       string `json:"open_id"`
	InboxNotifications           bool   `json:"inbox_notifications"`
	AllNewQuestions              bool   `json:"all_new_questions"`
	NewQuestionsForFollowingTags bool   `json:"new_questions_for_following_tags"`
}

type UserConfigCache

type UserConfigCache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewUserConfigCache

func NewUserConfigCache() *UserConfigCache

func (*UserConfigCache) SetUserConfig

func (ucc *UserConfigCache) SetUserConfig(userID string, config *UserConfig)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL