feishu

package
v0.3.9-5 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2022 License: Apache-2.0 Imports: 9 Imported by: 5

Documentation

Index

Constants

View Source
const (
	// 获取 tenant_access_token(企业自建应用)
	ApiTenantAccessTokenInternal = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal/"
	// 获取群列表
	ApiChatList = "https://open.feishu.cn/open-apis/chat/v4/list"
	// 机器人发送消息
	ApiRobotSendMessage = "https://open.feishu.cn/open-apis/message/v4/send/"
	// 批量发送消息
	ApiRobotBatchSendMessage = "https://open.feishu.cn/open-apis/message/v4/batch_send/"
	// 使用手机号或邮箱获取用户ID
	ApiFetchUserID = "https://open.feishu.cn/open-apis/user/v1/batch_get_id"
	// 使用 webhook 机器人发送消息
	ApiWebhookRobotSendMessage = "https://open.feishu.cn/open-apis/bot/hook/"
)
View Source
const (
	MsgTypePost        = "post"
	MsgTypeInteractive = "interactive"
)
View Source
const (
	TagDiv       = "div"
	TagPlainText = "plain_text"
	TagImg       = "img"
	TagNote      = "note"
	TagLarkMd    = "lark_md"
	TagHR        = "hr"
)

Variables

This section is empty.

Functions

func BuildTokenHeader

func BuildTokenHeader(token string) http.Header

func Request

func Request(method httputils.THttpMethod, url string, header http.Header, body jsonutils.JSONObject) (jsonutils.JSONObject, error)

Types

type BatchMsgReq

type BatchMsgReq struct {
	DepartMentIds []string    `json:"department_ids"`
	OpenIds       []string    `json:"open_ids"`
	UserIds       []string    `json:"user_ids"`
	MsgType       string      `json:"msg_type,omitempty"`
	Content       *MsgContent `json:"content,omitempty"`
}

type BatchMsgResp

type BatchMsgResp struct {
	CommonResp

	Data BatchMsgRespData
}

type BatchMsgRespData

type BatchMsgRespData struct {
	MessageId            string   `json:"message_id"`
	InvalidDepartmentIds string   `json:"invalid_department_ids"`
	InvalidOpenIds       []string `json:"invalid_open_ids"`
	InvalidUserIds       []string `json:"invalid_user_ids"`
}

type Card

type Card struct {
	Config       *CardConfig     `json:"config,omitempty"`
	CardLink     *CardElementUrl `json:"card_link,omitempty"`
	Header       *CardHeader     `json:"header,omitempty"`
	I18nElements *I18nElement    `json:"i18n_elements"`
	Elements     []interface{}   `json:"elements"`
}

机器人消息Card字段数据格式定义

type CardConfig

type CardConfig struct {
	WideScreenMode bool `json:"wide_screen_mode"`
}

type CardElement

type CardElement struct {
	Tag      string              `json:"tag"`
	Content  string              `json:"content"`
	Text     *CardElement        `json:"text"`
	Fields   []*CardElementField `json:"fields"`
	Elements []*CardElement      `json:"elements"`
}

func NewCardElementHR

func NewCardElementHR() *CardElement

func NewCardElementText

func NewCardElementText(content string) *CardElement

type CardElementField

type CardElementField struct {
	IsShort bool         `json:"is_short"`
	Text    *CardElement `json:"text"`
}

func NewCardElementTextField

func NewCardElementTextField(isShort bool, content string) *CardElementField

type CardElementUrl

type CardElementUrl struct {
	Url        string `json:"url"`
	AndroidUrl string `json:"android_url"`
	IosUrl     string `json:"ios_url"`
	PcUrl      string `json:"pc_url"`
}

type CardHeader

type CardHeader struct {
	Title *CardHeaderTitle `json:"title,omitempty"`
}

type CardHeaderTitle

type CardHeaderTitle struct {
	Tag     string    `json:"tag"`
	Content string    `json:"content"`
	Lines   int       `json:"lines,omitempty"`
	I18n    *CardI18n `json:"i18n,omitempty"`
}

type CardI18n

type CardI18n struct {
	ZhCn string `json:"zh_cn"`
	EnUs string `json:"en_us"`
	JaJp string `json:"ja_jp"`
}

type ChatGroupData

type ChatGroupData struct {
	ChatId  string       `json:"chat_id"`
	HasMore bool         `json:"has_more"`
	Members []MemberData `json:"members"`
}

type ChatMembersResp

type ChatMembersResp struct {
	CommonResp
	Data *ChatGroupData `json:"data"`
}

type CommonResp

type CommonResp struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
}

func (CommonResp) GetCode

func (r CommonResp) GetCode() int

func (CommonResp) GetMsg

func (r CommonResp) GetMsg() string

type CommonResponser

type CommonResponser interface {
	GetCode() int
	GetMsg() string
}

type FileCache

type FileCache struct {
	Path string
}

func NewFileCache

func NewFileCache(path string) *FileCache

func (*FileCache) Get

func (c *FileCache) Get(data IExpirable) error

func (*FileCache) Set

func (c *FileCache) Set(data IExpirable) error

type GroupData

type GroupData struct {
	Avatar      string `json:"avatar"`
	ChatId      string `json:"chat_id"`
	Description string `json:"description"`
	Name        string `json:"name"`
	OwnerOpenId string `json:"owner_open_id"`
	OwnerUserId string `json:"owner_user_id"`
}

type GroupListResp

type GroupListResp struct {
	CommonResp
	Data *UserGroupListData `json:"data"`
}

type I18nElement

type I18nElement struct {
	ZhCn []interface{} `json:"zh_cn"`
	EnUs []interface{} `json:"en_us"`
	JaJp []interface{} `json:"ja_jp"`
}

type ICache

type ICache interface {
	Set(data IExpirable) error
	Get(data IExpirable) error
}

type IExpirable

type IExpirable interface {
	CreatedAt() int64
	ExpiresIn() int64
}

type MemberData

type MemberData struct {
	OpenId string `json:"open_id"`
	UserId string `json:"user_id"`
	Name   string `json:"name"`
}

type MsgContent

type MsgContent struct {
	Text     string   `json:"text"`
	ImageKey string   `json:"image_key"`
	Post     *MsgPost `json:"post,omitempty"`
}

type MsgPost

type MsgPost struct {
	ZhCn *MsgPostValue `json:"zh_cn,omitempty"`
	EnUs *MsgPostValue `json:"en_us,omitempty"`
	JaJp *MsgPostValue `json:"ja_jp,omitempty"`
}

type MsgPostContentA

type MsgPostContentA struct {
	Tag  string `json:"tag"`
	Text string `json:"text"`
	Href string `json:"href"`
}

type MsgPostContentAt

type MsgPostContentAt struct {
	Tag    string `json:"tag"`
	UserId string `json:"user_id"`
}

type MsgPostContentImage

type MsgPostContentImage struct {
	Tag      string  `json:"tag"`
	ImageKey string  `json:"image_key"`
	Width    float64 `json:"width"`
	Height   float64 `json:"height"`
}

type MsgPostContentText

type MsgPostContentText struct {
	Tag      string `json:"tag"`
	UnEscape bool   `json:"un_escape"`
	Text     string `json:"text"`
}

type MsgPostValue

type MsgPostValue struct {
	Title   string      `json:"title"`
	Content interface{} `json:"content"`
}

type MsgReq

type MsgReq struct {
	OpenId      string `json:"open_id,omitempty"`
	UserId      string `json:"user_id,omitempty"`
	Email       string `json:"email,omitempty"`
	ChatId      string `json:"chat_id,omitempty"`
	MsgType     string `json:"msg_type"`
	RootId      string `json:"root_id,omitempty"`
	UpdateMulti bool   `json:"update_multi"`

	Card    *Card       `json:"card,omitempty"`
	Content *MsgContent `json:"content,omitempty"`
}

定义参照: https://open.feishu.cn/open-apis/message/v4/send/

type MsgResp

type MsgResp struct {
	CommonResp

	Data MsgRespData `json:"data"`
}

type MsgRespData

type MsgRespData struct {
	MessageId string `json:"message_id"`
}

type Tenant

type Tenant struct {
	AppId       string
	AppSecret   string
	AccessToken string
	Cache       ICache
}

func NewTenant

func NewTenant(appId, appSecret string) (*Tenant, error)

func (*Tenant) BatchSendMessage

func (t *Tenant) BatchSendMessage(msg BatchMsgReq) (*BatchMsgResp, error)

BatchSendMessage batch send messages. Doc: https://open.feishu.cn/document/ukTMukTMukTM/ucDO1EjL3gTNx4yN4UTM

func (*Tenant) ChatList

func (t *Tenant) ChatList(pageSize int, pageToken string) (*GroupListResp, error)

func (*Tenant) RefreshAccessToken

func (t *Tenant) RefreshAccessToken() error

RefreshAccessToken is to get a valid access token

func (*Tenant) SendMessage

func (t *Tenant) SendMessage(msg MsgReq) (*MsgResp, error)

func (*Tenant) UserIdByMobile

func (t *Tenant) UserIdByMobile(mobile string) (string, error)

UserIdByMobile query the open id of user by mobile number. https://open.feishu.cn/document/ukTMukTMukTM/uUzMyUjL1MjM14SNzITN

type TenantAccesstoken

type TenantAccesstoken struct {
	TenantAccessToken string `json:"tenant_access_token"`
	Expire            int64  `json:"expire"`
	Created           int64
}

func (TenantAccesstoken) CreatedAt

func (t TenantAccesstoken) CreatedAt() int64

func (TenantAccesstoken) ExpiresIn

func (t TenantAccesstoken) ExpiresIn() int64

type TenantAccesstokenResp

type TenantAccesstokenResp struct {
	CommonResp
	TenantAccesstoken
}

func GetTenantAccessTokenInternal

func GetTenantAccessTokenInternal(appId string, appSecret string) (*TenantAccesstokenResp, error)

获取 tenant_access_token(企业自建应用)https://open.feishu.cn/document/ukTMukTMukTM/uIjNz4iM2MjLyYzM

type UserGroupListData

type UserGroupListData struct {
	HasMore   bool        `json:"has_more"`
	PageToken string      `json:"page_token"`
	Groups    []GroupData `json:"groups"`
}

type UserIDResp

type UserIDResp struct {
	CommonResp

	Data UserIDRespData `json:"data"`
}

type UserIDRespData

type UserIDRespData struct {
	EmailUsers      jsonutils.JSONObject `json:"email_users"`
	EmailsNotExist  []string             `json:"emails_not_exist"`
	MobileUsers     jsonutils.JSONObject `json:"mobile_users"`
	MobilesNotExist []string             `json:"mobiles_not_exist"`
}

type WebhookRobotMsgReq

type WebhookRobotMsgReq struct {
	Title string `json:"title"`
	Text  string `json:"text"`
}

type WebhookRobotMsgResp

type WebhookRobotMsgResp struct {
	Error string `json:"error"`
	Ok    bool   `json:"ok"`
}

func SendWebhookRobotMessage

func SendWebhookRobotMessage(hook string, msg WebhookRobotMsgReq) (*WebhookRobotMsgResp, error)

SendWebhookRobotMessage will send to message to Webhook address. Webhook's format: https://open.feishu.cn/open-apis/bot/hook/xxxxxxxxxxxxxxxxxxxxxxxxxxx. The hook represents the last part of webhook: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'.

Jump to

Keyboard shortcuts

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