feishu

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2021 License: Apache-2.0 Imports: 11 Imported by: 1

README

feishu

通过飞书群组机器人发送消息。

Documentation

Index

Constants

View Source
const (
	MsgTypeText        = "text"
	MsgTypeImage       = "image"
	MsgTypePost        = "post"
	MsgTypeShareChat   = "sharechat"
	MsgTypeInteractive = "interactive"

	// Underlying, we use interactive to implement markdown
	MsgTypeMarkdown = "markdown"
)
View Source
const ChannelTypeFeishu = "feishu"

Variables

View Source
var SupportedMsgtype = make(map[string]bool)

Functions

func GenSign

func GenSign(secret string, timestamp int64) (string, error)

func ValidMsgtype

func ValidMsgtype(msgtype string) bool

Types

type Card

type Card struct {
	Config       *CardConfig       `json:"config,omitempty"`
	Header       *CardHeader       `json:"header,omitempty"`
	CardLink     *card.MultiURL    `json:"card_link,omitempty"`
	Elements     []card.CardModule `json:"elements"` // 最多可堆叠 50 个模块
	I18NElements *I18NElements     `json:"i18n_elements,omitempty"`
}

func NewCardMarkdown

func NewCardMarkdown(title string, markdown string) *Card

type CardConfig

type CardConfig struct {
	WideScreenMode bool `json:"wide_screen_mode,omitempty"` // 2021/03/22 之后,此字段废弃,所有卡片均升级为自适应屏幕宽度的宽版卡片
	EnableForward  bool `json:"enable_forward"`             // 是否允许卡片被转发,默认 false
}

CardConfig 卡片配置

type CardHeader

type CardHeader struct {
	Title    *card.Text `json:"title"`              // 卡片标题内容, text 对象(仅支持 "plain_text")
	Template string     `json:"template,omitempty"` // 控制标题背景颜色, https://open.feishu.cn/document/ukTMukTMukTM/ukTNwUjL5UDM14SO1ATN
}

type Content

type Content struct {
	Text        string `json:"text,omitempty"`
	ImageKey    string `json:"image,omitempty"`
	Post        *Post  `json:"post,omitempty"`
	ShareChatID string `json:"share_chat_id,omitempty"`
}

type FeishuGroupBot

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

FeishuBot can send messages to feishu group ref: https://www.feishu.cn/hc/zh-CN/articles/360024984973

func NewFeishuGroupBot

func NewFeishuGroupBot(token string) *FeishuGroupBot

func (*FeishuGroupBot) Addr

func (bot *FeishuGroupBot) Addr() string

func (*FeishuGroupBot) AddrForDownloadFile

func (bot *FeishuGroupBot) AddrForDownloadFile(fileKey string) string

func (*FeishuGroupBot) AddrForFetchImage

func (bot *FeishuGroupBot) AddrForFetchImage() string

func (*FeishuGroupBot) AddrForUploadFile

func (bot *FeishuGroupBot) AddrForUploadFile() string

func (*FeishuGroupBot) AddrForUploadImage

func (bot *FeishuGroupBot) AddrForUploadImage() string

func (*FeishuGroupBot) DownloadFile

func (bot *FeishuGroupBot) DownloadFile(fileKey string) ([]byte, error)

func (*FeishuGroupBot) FetchImage

func (bot *FeishuGroupBot) FetchImage(imageKey string) ([]byte, error)

func (*FeishuGroupBot) Send

func (bot *FeishuGroupBot) Send(msg *Msg) error

func (*FeishuGroupBot) SendImage

func (bot *FeishuGroupBot) SendImage(imageKey string) error

func (*FeishuGroupBot) UploadFile

func (bot *FeishuGroupBot) UploadFile(filename string, filetype string, fileReader io.Reader) (fileKey string, err error)

func (*FeishuGroupBot) UploadImage

func (bot *FeishuGroupBot) UploadImage(filename string, fileReader io.Reader) (imageKey string, err error)

type I18NElements

type I18NElements struct {
	ZHCN []card.CardModule `json:"zh_cn"`
	ENUS []card.CardModule `json:"en_us"`
	JAJP []card.CardModule `json:"jn_jp"`
}

type Line

type Line []*Segment // 每行由多个片段组成

type Msg

type Msg struct {
	MsgType string `json:"msg_type"`

	Content *Content `json:"content,omitempty"`

	Card        *Card  `json:"card,omitempty"`
	RootID      string `json:"root_id,omitempty"`      // 需要回复的消息的open_message_id
	UpdateMulti bool   `json:"update_multi,omitempty"` // 控制卡片是否是共享卡片(所有用户共享同一张消息卡片),默认为 false
}

func NewMsgCard

func NewMsgCard(card *Card) *Msg

func NewMsgImage

func NewMsgImage(imageKey string) *Msg

func NewMsgImageFromPayload

func NewMsgImageFromPayload(payload *models.Payload) *Msg

func NewMsgInteractiveFromPayload

func NewMsgInteractiveFromPayload(payload *models.Payload) *Msg

func NewMsgMarkdownFromPayload

func NewMsgMarkdownFromPayload(payload *models.Payload) *Msg

func NewMsgPost

func NewMsgPost(title string, lines []*Line) *Msg

func NewMsgPostFromPayload

func NewMsgPostFromPayload(payload *models.Payload) *Msg

func NewMsgShareChat

func NewMsgShareChat(shareChatID string) *Msg

func NewMsgShareChatFromPayload

func NewMsgShareChatFromPayload(payload *models.Payload) *Msg

func NewMsgText

func NewMsgText(text string) *Msg

func NewMsgTextFromPayload

func NewMsgTextFromPayload(payload *models.Payload) *Msg

type Post

type Post struct {
	*ZHCN `json:"zh_ch"`
}

type Segment

type Segment struct {
	Tag      string `json:"tag"` // text, img, a, at
	UnEscape bool   `json:"un_escape"`
	Text     string `json:"text"`
	Href     string `json:"href"`
	UserID   string `json:"user_id"`
	ImageKey string `json:"image_key"`
	Height   int    `json:"height"`
	Width    int    `json:"width"`
}

func NewSegmentA

func NewSegmentA(text string, unescape bool, href string) *Segment

func NewSegmentAt

func NewSegmentAt(userID string) *Segment

func NewSegmentImg

func NewSegmentImg(imageKey string, height int, width int) *Segment

func NewSegmentText

func NewSegmentText(text string, unescape bool) *Segment

type Sender

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

func NewSender

func NewSender(token string, msgType string) *Sender

func (*Sender) Send

func (s *Sender) Send(payload *models.Payload) error

type ZHCN

type ZHCN struct {
	Title   string  `json:"title"`   // 文章标题
	Content []*Line `json:"content"` // 文章内容,有多个行组成
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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