larki

package module
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: AGPL-3.0 Imports: 24 Imported by: 0

README

Larki

github action GitHub release (latest by date)

lark-oapi-go 的再封装

Usage

Init Client
package larki
func NewClient(appId, appSecret, verifyToken, encryptKey string) (*Client, error) {
	return NewClientWithConfig(&Config{
		AppID:       appId,
		AppSecret:   appSecret,
		VerifyToken: verifyToken,
		EncryptKey:  encryptKey,
	})
}

Use it:

package main

import (
    "fmt"
    "github.com/wintbiit/larki"
)

func main() {
    client, err := larki.NewClient("appId", "appSecret", "verifyToken", "encryptKey")
    if err != nil {
        panic(err)
    }
	
	// set global client
	larki.SetGlobalClient(client)
	
	// do something
}
Send Message
package main

import (
    "fmt"
    "github.com/wintbiit/larki"
)

var client *larki.Client

func main() {
	client.ReplyText(ctx, "om_v1234151", "hello world title", "hello world content")
}
Subscribe Event
package main

import (
    "fmt"
    "github.com/wintbiit/larki"
)

var client *larki.Client

func main() {
	// larkim.P2MessageReceiveV1Data
	for event := range client.MessageEvent {
		fmt.Printf("event: %+v\n", event)
	}
	
	// larkim.P2ChatMemberBotAddedV1Data
	for event := range client.BotAddedEvent {
        fmt.Printf("event: %+v\n", event)
    }
	
	// larkim.P1P2PChatCreatedV1Data
	for event := range client.ChatCreatedEvent {
        fmt.Printf("event: %+v\n", event)
    }
}
Get Bot Meta

bot info is fetched when client is initialized

var client *larki.Client
botInfo := client.BotInfo

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CestSign added in v0.5.0

func CestSign(origin []byte) string

func CreateDriveFolder added in v0.7.1

func CreateDriveFolder(ctx context.Context, name, folderToken string) (string, error)

func GetDocFile added in v0.4.0

func GetDocFile(ctx context.Context, fileToken string) (io.Reader, string, error)

func GetDocMedia added in v0.4.0

func GetDocMedia(ctx context.Context, fileToken string) (io.Reader, string, error)

func GetImage

func GetImage(ctx context.Context, messageId, imageKey string) (io.Reader, error)

GetImage 下载图片

func GetImportDocStatus added in v0.4.0

func GetImportDocStatus(ctx context.Context, ticket string) (*larkdrive.ImportTask, error)

func GetJoinedGroups added in v0.11.0

func GetJoinedGroups(ctx context.Context) ([]*larkim.ListChat, error)

func GetMessage

func GetMessage(ctx context.Context, messageId string) (*larkim.Message, error)

GetMessage 获取指定消息

func GetMoveDocToWikiStatus added in v0.4.0

func GetMoveDocToWikiStatus(ctx context.Context, taskId string) ([]*larkwiki.MoveResult, error)

func GetRecord added in v0.4.0

func GetRecord(ctx context.Context, baseId, tableId, recordId string) (*larkbitable.AppTableRecord, error)

func GetRecords added in v0.4.0

func GetRecords(ctx context.Context, baseId, tableId, viewId string, limit int) ([]*larkbitable.AppTableRecord, error)

func ImportDoc added in v0.4.0

func ImportDoc(ctx context.Context, fileExt, fileToken, targetType, fileName string, mountType int, mountKey string) (string, error)

func ListBaseTables added in v0.4.0

func ListBaseTables(ctx context.Context, baseId string) ([]*larkbitable.AppTable, error)

func ListDriveFolder added in v0.7.1

func ListDriveFolder(ctx context.Context, folderToken string) ([]*larkdrive.File, error)

func MoveDocToWiki added in v0.4.0

func MoveDocToWiki(ctx context.Context, spaceId, objType, objToken, parentWikiToken string) (*larkwiki.MoveDocsToWikiSpaceNodeRespData, error)

func NewImageContent

func NewImageContent(imageKey string) string

NewImageContent 构造图片消息内容

func ParseImageKey

func ParseImageKey(context string) (string, bool)

ParseImageKey 解析图片消息imageKey

func ParseTextContent

func ParseTextContent(text string) (string, bool)

ParseTextContent 解析文本消息内容

func ReplyCard

func ReplyCard(ctx context.Context, inThread bool, messageId, card string) error

ReplyCard 使用卡片回复消息

func ReplyCardTemplate

func ReplyCardTemplate(ctx context.Context, inThread bool, messageId, templateId string, vars map[string]interface{}) error

ReplyCardTemplate 使用模板卡片回复消息

func ReplyImage

func ReplyImage(ctx context.Context, inThread bool, messageId, imageKey string) error

ReplyImage 使用图片回复消息

func ReplyMessage

func ReplyMessage(ctx context.Context, message, messageId, messageType string, inThread bool) error

ReplyMessage 回复消息

func ReplyText

func ReplyText(ctx context.Context, inThread bool, messageId, title string, text ...string) error

ReplyText 使用文本回复消息

func SendCardTemplateToGroup

func SendCardTemplateToGroup(ctx context.Context, groupId, templateId string, vars map[string]interface{}) (string, error)

SendCardTemplateToGroup 使用模板卡片发送消息到群组

func SendCardTemplateToUser

func SendCardTemplateToUser(ctx context.Context, openId, templateId string, vars map[string]interface{}) (string, error)

SendCardTemplateToUser 使用模板卡片发送消息到用户

func SendCardToGroup

func SendCardToGroup(ctx context.Context, groupId, card string) (string, error)

SendCardToGroup 使用卡片发送消息到群组

func SendCardToUser

func SendCardToUser(ctx context.Context, openId, card string) (string, error)

SendCardToUser 使用卡片发送消息到用户

func SendImageToGroup

func SendImageToGroup(ctx context.Context, groupId, imageKey string) (string, error)

SendImageToGroup 使用图片发送消息到群组

func SendImageToUser

func SendImageToUser(ctx context.Context, openId, imageKey string) (string, error)

SendImageToUser 使用图片发送消息到用户

func SendMessage

func SendMessage(ctx context.Context, receiverIdType, message, receiveId, messageType string) (string, error)

SendMessage 发送消息

func SendMessageToGroup

func SendMessageToGroup(ctx context.Context, groupId, message, messageType string) (string, error)

SendMessageToGroup 发送消息到群组

func SendMessageToUser

func SendMessageToUser(ctx context.Context, openId, message, messageType string) (string, error)

SendMessageToUser 发送消息到用户

func SendTextToGroup

func SendTextToGroup(ctx context.Context, groupId, title string, text ...string) (string, error)

SendTextToGroup 使用文本发送消息到群组

func SendTextToUser

func SendTextToUser(ctx context.Context, openId, title string, text ...string) (string, error)

SendTextToUser 使用文本发送消息到用户

func SetGlobalClient

func SetGlobalClient(client *Client)

func UpdateBaseRecord added in v0.4.0

func UpdateBaseRecord(ctx context.Context, baseId, tableId, recordId string, fields map[string]interface{}) error

func UpdateCardTemplate added in v0.4.0

func UpdateCardTemplate(ctx context.Context, messageId, templateId string, vars map[string]interface{}) error

func UpdateMessage added in v0.4.0

func UpdateMessage(ctx context.Context, messageId, message, messageType string) error

func UpdateTextMessage added in v0.4.0

func UpdateTextMessage(ctx context.Context, messageId, title string, text ...string) error

func UploadDocFile added in v0.4.0

func UploadDocFile(ctx context.Context, name, parentType, parentNode string, size int, reader io.Reader) (string, error)

func UploadDocFileMultiPart added in v0.7.0

func UploadDocFileMultiPart(ctx context.Context, name, parentNode string, size int, reader io.Reader) (string, error)

func UploadDocMedia added in v0.4.0

func UploadDocMedia(ctx context.Context, fileName, parentType, parentNode, extras string, size int, reader io.Reader) (string, error)

func UploadDocMediaMultiPart added in v0.9.0

func UploadDocMediaMultiPart(ctx context.Context, name, parentType, parentNode, extra string, size int, reader io.Reader) (string, error)

func UploadImage

func UploadImage(ctx context.Context, reader io.Reader) (string, error)

UploadImage 上传图片

func UploadToWiki added in v0.4.0

func UploadToWiki(ctx context.Context,
	name, ext, docType, spaceId, parentNode string,
	size int, reader io.Reader,
) ([]*larkwiki.MoveResult, error)

Types

type BotAddedEvent added in v0.0.3

type BotAddedEvent struct {
	*larkim.P2ChatMemberBotAddedV1Data
}

type BotInfo

type BotInfo struct {
	ActivateStatus int    `json:"activate_status"`
	AppName        string `json:"app_name"`
	AvatarUrl      string `json:"avatar_url"`
	OpenID         string `json:"open_id"`
}

type ChatCreatedEvent added in v0.0.3

type ChatCreatedEvent struct {
	*larkim.P1P2PChatCreatedV1Data
}

type Client

type Client struct {
	*lark.Client
	*Config
	*BotInfo
	EventDispatcher *dispatcher.EventDispatcher
	MessageClient
	ImageClient
}
var GlobalClient *Client

func NewClient

func NewClient(appId, appSecret, verifyToken, encryptKey string, options ...ClientOption) (*Client, error)

func NewClientFromEnv added in v0.2.0

func NewClientFromEnv() (*Client, error)

func NewClientWithConfig

func NewClientWithConfig(config *Config, options ...ClientOption) (*Client, error)

func (*Client) CreateDriveFolder added in v0.7.0

func (c *Client) CreateDriveFolder(ctx context.Context, name, folderToken string) (string, error)

func (*Client) FilterTextContent added in v0.0.8

func (c *Client) FilterTextContent(text string, mentions []*larkim.MentionEvent) (string, bool, bool)

FilterTextContent 返回过滤掉 @ 信息后的文本内容和是否需要忽略,若包含@全体成员,则忽略,否则返回去除@信息后的文本内容 @return text, atbot, atall

func (*Client) GetBotInfo

func (c *Client) GetBotInfo() (*BotInfo, error)

GetBotInfo 获取 BotInfo

func (*Client) GetDocFile added in v0.0.6

func (c *Client) GetDocFile(ctx context.Context, fileToken string) (io.Reader, string, error)

func (*Client) GetDocMedia added in v0.0.6

func (c *Client) GetDocMedia(ctx context.Context, fileToken string) (io.Reader, string, error)

func (*Client) GetImage

func (c *Client) GetImage(ctx context.Context, messageId, imageKey string) (io.Reader, error)

GetImage 下载图片

func (*Client) GetImportDocStatus added in v0.3.0

func (c *Client) GetImportDocStatus(ctx context.Context, ticket string) (*larkdrive.ImportTask, error)

func (*Client) GetJoinedGroups added in v0.11.0

func (c *Client) GetJoinedGroups(ctx context.Context) ([]*larkim.ListChat, error)

func (*Client) GetJsApiTicket added in v0.5.0

func (c *Client) GetJsApiTicket(ctx context.Context) (*JsApiTicket, error)

func (*Client) GetJsAuthResponse added in v0.5.0

func (c *Client) GetJsAuthResponse(ticket, url, nocestr string) *JsApiAuthResponse

func (*Client) GetMessage

func (c *Client) GetMessage(ctx context.Context, messageId string) (*larkim.Message, error)

GetMessage 获取指定消息

func (*Client) GetMiniProgramUserAccessToken added in v0.5.0

func (c *Client) GetMiniProgramUserAccessToken(ctx context.Context, code string) (*MiniProgramToken, error)

func (*Client) GetMoveDocToWikiStatus added in v0.3.1

func (c *Client) GetMoveDocToWikiStatus(ctx context.Context, taskId string) ([]*larkwiki.MoveResult, error)

func (*Client) GetRecord added in v0.0.4

func (c *Client) GetRecord(ctx context.Context, baseId, tableId, recordId string) (*larkbitable.AppTableRecord, error)

func (*Client) GetRecords added in v0.0.3

func (c *Client) GetRecords(ctx context.Context, baseId, tableId, viewId string, limit int) ([]*larkbitable.AppTableRecord, error)

func (*Client) GetUserInfo added in v0.5.0

func (c *Client) GetUserInfo(ctx context.Context, token string) (*larkauthen.GetUserInfoRespData, error)

func (*Client) GetWebAppUserAccessToken added in v0.5.0

func (c *Client) GetWebAppUserAccessToken(ctx context.Context, code string) (*larkauthen.CreateOidcAccessTokenRespData, error)

func (*Client) ImportDoc added in v0.3.0

func (c *Client) ImportDoc(ctx context.Context, fileExt, fileToken, targetType, fileName string, mountType int, mountKey string) (string, error)

func (*Client) ListBaseTables added in v0.1.0

func (c *Client) ListBaseTables(ctx context.Context, baseId string) ([]*larkbitable.AppTable, error)

func (*Client) ListDriveFolder added in v0.7.0

func (c *Client) ListDriveFolder(ctx context.Context, folderToken string) ([]*larkdrive.File, error)

func (*Client) MoveDocToWiki added in v0.3.0

func (c *Client) MoveDocToWiki(ctx context.Context, spaceId, objType, objToken, parentWikiToken string) (*larkwiki.MoveDocsToWikiSpaceNodeRespData, error)

func (*Client) ReplyCard

func (c *Client) ReplyCard(ctx context.Context, inThread bool, messageId, card string) error

ReplyCard 使用卡片回复消息

func (*Client) ReplyCardTemplate

func (c *Client) ReplyCardTemplate(ctx context.Context, inThread bool, messageId, templateId string, vars map[string]interface{}) error

ReplyCardTemplate 使用模板卡片回复消息

func (*Client) ReplyImage

func (c *Client) ReplyImage(ctx context.Context, inThread bool, messageId, imageKey string) error

ReplyImage 使用图片回复消息

func (*Client) ReplyMessage

func (c *Client) ReplyMessage(ctx context.Context, message, messageId, messageType string, inThread bool) error

ReplyMessage 回复消息

func (*Client) ReplyText

func (c *Client) ReplyText(ctx context.Context, inThread bool, messageId, title string, text ...string) error

ReplyText 使用文本回复消息

func (*Client) SendCardTemplateToGroup

func (c *Client) SendCardTemplateToGroup(ctx context.Context, groupId, templateId string, vars map[string]interface{}) (string, error)

SendCardTemplateToGroup 使用模板卡片发送消息到群组

func (*Client) SendCardTemplateToUser

func (c *Client) SendCardTemplateToUser(ctx context.Context, openId, templateId string, vars map[string]interface{}) (string, error)

SendCardTemplateToUser 使用模板卡片发送消息到用户

func (*Client) SendCardToGroup

func (c *Client) SendCardToGroup(ctx context.Context, groupId, card string) (string, error)

SendCardToGroup 使用卡片发送消息到群组

func (*Client) SendCardToUser

func (c *Client) SendCardToUser(ctx context.Context, openId, card string) (string, error)

SendCardToUser 使用卡片发送消息到用户

func (*Client) SendImageToGroup

func (c *Client) SendImageToGroup(ctx context.Context, groupId, imageKey string) (string, error)

SendImageToGroup 使用图片发送消息到群组

func (*Client) SendImageToUser

func (c *Client) SendImageToUser(ctx context.Context, openId, imageKey string) (string, error)

SendImageToUser 使用图片发送消息到用户

func (*Client) SendMessage added in v0.0.7

func (c *Client) SendMessage(ctx context.Context, receiverIdType, message, receiveId, messageType string) (string, error)

func (*Client) SendMessageToGroup

func (c *Client) SendMessageToGroup(ctx context.Context, groupId, message, messageType string) (string, error)

SendMessageToGroup 发送消息到群组

func (*Client) SendMessageToUser

func (c *Client) SendMessageToUser(ctx context.Context, openId, message, messageType string) (string, error)

SendMessageToUser 发送消息到用户

func (*Client) SendTextToGroup

func (c *Client) SendTextToGroup(ctx context.Context, groupId, title string, text ...string) (string, error)

SendTextToGroup 使用文本发送消息到群组

func (*Client) SendTextToUser

func (c *Client) SendTextToUser(ctx context.Context, openId, title string, text ...string) (string, error)

SendTextToUser 使用文本发送消息到用户

func (*Client) UpdateBaseRecord added in v0.0.3

func (c *Client) UpdateBaseRecord(ctx context.Context, baseId, tableId, recordId string, fields map[string]interface{}) error

func (*Client) UpdateCardTemplate added in v0.4.0

func (c *Client) UpdateCardTemplate(ctx context.Context, messageId, templateId string, vars map[string]interface{}) error

func (*Client) UpdateMessage added in v0.4.0

func (c *Client) UpdateMessage(ctx context.Context, messageId, message, messageType string) error

func (*Client) UpdateTextMessage added in v0.4.0

func (c *Client) UpdateTextMessage(ctx context.Context, messageId, title string, text ...string) error

func (*Client) UploadDocFile added in v0.3.0

func (c *Client) UploadDocFile(ctx context.Context, name, parentType, parentNode string, size int, reader io.Reader) (string, error)

func (*Client) UploadDocFileMultiPart added in v0.7.0

func (c *Client) UploadDocFileMultiPart(ctx context.Context, name, parentNode string, size int, reader io.Reader) (string, error)

func (*Client) UploadDocMedia added in v0.3.0

func (c *Client) UploadDocMedia(ctx context.Context, fileName, parentType, parentNode, extras string, size int, reader io.Reader) (string, error)

func (*Client) UploadDocMediaMultiPart added in v0.9.0

func (c *Client) UploadDocMediaMultiPart(ctx context.Context, name, parentType, parentNode, extra string, size int, reader io.Reader) (string, error)

func (*Client) UploadImage

func (c *Client) UploadImage(ctx context.Context, reader io.Reader) (string, error)

UploadImage 上传图片

func (*Client) UploadToWiki added in v0.3.0

func (c *Client) UploadToWiki(ctx context.Context,
	name, ext, docType, spaceId, parentNode string,
	size int, reader io.Reader,
) ([]*larkwiki.MoveResult, error)

UploadToWiki 上传文件到知识库

type ClientOption added in v0.0.9

type ClientOption func(*Client)

func WithBotAddedEventSubscribe added in v0.0.9

func WithBotAddedEventSubscribe(evtChan chan *BotAddedEvent) ClientOption

func WithChatCreatedEventSubscribe added in v0.0.9

func WithChatCreatedEventSubscribe(evtChan chan *ChatCreatedEvent) ClientOption

func WithCustomizedEventSubscribe added in v0.0.9

func WithCustomizedEventSubscribe(eventType string, evtChan chan *larkevent.EventReq) ClientOption

func WithMenuEventSubscribe added in v0.0.9

func WithMenuEventSubscribe(evtChan chan *MenuEvent) ClientOption

func WithMessageEventSubscribe added in v0.0.9

func WithMessageEventSubscribe(evtChan chan *MessageEvent) ClientOption

func WithTokenCache added in v0.5.0

func WithTokenCache(cache larkcore.Cache) ClientOption

type Config

type Config struct {
	AppID       string
	AppSecret   string
	VerifyToken string
	EncryptKey  string
}

type CustomizedEvent added in v0.0.9

type CustomizedEvent struct {
	*larkevent.EventReq
}

func (*CustomizedEvent) GetAsMenuEvent added in v0.0.9

func (e *CustomizedEvent) GetAsMenuEvent() (*MenuEventBody, error)

type DocumentClient added in v0.0.3

type DocumentClient interface{}

type ImageClient added in v0.0.3

type ImageClient interface {
	GetImage(ctx context.Context, messageId, imageKey string) (io.Reader, error)
	UploadImage(ctx context.Context, reader io.Reader) (string, error)
}

type JsApiAuthResponse added in v0.5.0

type JsApiAuthResponse struct {
	Appid     interface{} `json:"appid"`
	Signature interface{} `json:"signature"`
	Noncestr  interface{} `json:"noncestr"`
	Timestamp interface{} `json:"timestamp"`
}

type JsApiTicket added in v0.5.0

type JsApiTicket struct {
	Ticket   string `json:"ticket"`
	ExpireIn int    `json:"expire_in"`
}

type JsApiTicketResponse added in v0.5.0

type JsApiTicketResponse struct {
	Code    int         `json:"code"`
	Message string      `json:"msg"`
	Data    JsApiTicket `json:"data"`
}
type MenuEvent struct {
	*larkapplication.P2BotMenuV6Data
}
type MenuEventBody struct {
	Operator  Operator `json:"operator"`
	EventKey  string   `json:"event_key"`
	Timestamp int64    `json:"timestamp"`
}

type MessageClient added in v0.0.3

type MessageClient interface {
	GetMessage(ctx context.Context, messageId string) (*larkim.Message, error)
	ReplyMessage(ctx context.Context, message, messageId, messageType string) error
	ReplyText(ctx context.Context, messageId, title string, text ...string) error
	ReplyImage(ctx context.Context, messageId, imageKey string) error
	ReplyCard(ctx context.Context, messageId, card string) error
	ReplyCardTemplate(ctx context.Context, messageId, templateId string, vars map[string]interface{}) error
	SendMessage(ctx context.Context, receiverIdType, message, receiveId, messageType string) (string, error)
	SendMessageToGroup(ctx context.Context, groupId, message, messageType string) (string, error)
	SendTextToGroup(ctx context.Context, groupId, title string, text ...string) (string, error)
	SendImageToGroup(ctx context.Context, groupId, imageKey string) (string, error)
	SendCardToGroup(ctx context.Context, groupId, card string) (string, error)
	SendCardTemplateToGroup(ctx context.Context, groupId, templateId string, vars map[string]interface{}) (string, error)
	SendMessageToUser(ctx context.Context, openId, message, messageType string) (string, error)
	SendTextToUser(ctx context.Context, openId, title string, text ...string) (string, error)
	SendImageToUser(ctx context.Context, openId, imageKey string) (string, error)
	SendCardToUser(ctx context.Context, openId, card string) (string, error)
	SendCardTemplateToUser(ctx context.Context, openId, templateId string, vars map[string]interface{}) (string, error)
}

type MessageEvent

type MessageEvent struct {
	*larkim.P2MessageReceiveV1Data
}

type MiniProgramToken added in v0.5.0

type MiniProgramToken struct {
	OpenId       string `json:"open_id"`
	EmployeeId   string `json:"employee_id"`
	SessionKey   string `json:"session_key"`
	TenantKey    string `json:"tenant_key"`
	AccessToken  string `json:"access_token"`
	ExpiresIn    int    `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
}

type MiniProgramTokenResponse added in v0.5.0

type MiniProgramTokenResponse struct {
	Code    int              `json:"code"`
	Message string           `json:"msg"`
	Data    MiniProgramToken `json:"data"`
}

type Operator added in v0.0.9

type Operator struct {
	OperatorName string        `json:"operator_name"`
	OperatorId   larkim.UserId `json:"operator_id"`
}

Jump to

Keyboard shortcuts

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