dingtalk

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractUserMessage

func ExtractUserMessage(msg *CallbackMessage) string

ExtractUserMessage 提取用户消息内容(去除@机器人部分)

func GetHelpMessage

func GetHelpMessage() string

GetHelpMessage 获取帮助消息

func IsValidTimestamp

func IsValidTimestamp(timestamp string) bool

IsValidTimestamp 检查时间戳是否有效(���重放攻击)

Types

type AccessTokenResponse

type AccessTokenResponse struct {
	ErrCode     int    `json:"errcode"`
	ErrMsg      string `json:"errmsg"`
	AccessToken string `json:"access_token"`
	ExpiresIn   int    `json:"expires_in"`
}

AccessTokenResponse 获取 AccessToken 的响应

type ActionCardMsg

type ActionCardMsg struct {
	Title          string `json:"title"`
	Text           string `json:"text"`
	SingleTitle    string `json:"singleTitle,omitempty"`
	SingleURL      string `json:"singleURL,omitempty"`
	BtnOrientation string `json:"btnOrientation,omitempty"`
	Btns           []Btn  `json:"btns,omitempty"`
}

ActionCardMsg 卡片消息

type AtUser

type AtUser struct {
	DingtalkID string `json:"dingtalkId"`
	StaffID    string `json:"staffId"`
}

AtUser @的用户

type Btn

type Btn struct {
	Title     string `json:"title"`
	ActionURL string `json:"actionURL"`
}

Btn 卡片按钮

type CallbackCrypto

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

CallbackCrypto 回调加解密工具

func NewCallbackCrypto

func NewCallbackCrypto(token, encodingAESKey, suiteKey string) (*CallbackCrypto, error)

NewCallbackCrypto 创建回调加解密工具

func (*CallbackCrypto) DecryptMessage

func (c *CallbackCrypto) DecryptMessage(encryptedMsg string) (*CallbackMessage, error)

DecryptMessage 解密消息

func (*CallbackCrypto) EncryptMessage

func (c *CallbackCrypto) EncryptMessage(msg string) (string, error)

EncryptMessage 加密消息(用于响应)

func (*CallbackCrypto) VerifySignature

func (c *CallbackCrypto) VerifySignature(timestamp, nonce, body, signature string) bool

VerifySignature 验证签名

type CallbackMessage

type CallbackMessage struct {
	MsgID            string       `json:"msgId"`
	MsgType          string       `json:"msgtype"`
	CreateAt         int64        `json:"createAt"`
	ConversationID   string       `json:"conversationId"`
	ConversationType string       `json:"conversationType"` // "1" 单聊, "2" 群聊
	SenderID         string       `json:"senderId"`
	SenderNick       string       `json:"senderNick"`
	SenderStaffID    string       `json:"senderStaffId"`
	ChatbotUserID    string       `json:"chatbotUserId"`
	RobotCode        string       `json:"robotCode"`
	IsAdmin          bool         `json:"isAdmin"`
	SessionWebhook   string       `json:"sessionWebhook"`
	Text             *TextContent `json:"text,omitempty"`
	AtUsers          []AtUser     `json:"atUsers,omitempty"`
}

CallbackMessage 回调消息结构

type CallbackRequest

type CallbackRequest struct {
	Encrypt string `json:"encrypt"`
}

CallbackRequest 回调请求

type CallbackResponse

type CallbackResponse struct {
	MsgType    string         `json:"msgtype"`
	Text       *TextMsg       `json:"text,omitempty"`
	Markdown   *MarkdownMsg   `json:"markdown,omitempty"`
	ActionCard *ActionCardMsg `json:"actionCard,omitempty"`
}

CallbackResponse 回调响应

func CreateActionCardResponse

func CreateActionCardResponse(title, text, singleTitle, singleURL string) *CallbackResponse

CreateActionCardResponse 创建卡片响应

func CreateMarkdownResponse

func CreateMarkdownResponse(title, text string) *CallbackResponse

CreateMarkdownResponse 创建 Markdown 响应

func CreateTextResponse

func CreateTextResponse(content string) *CallbackResponse

CreateResponse 创建响应消息

type Client

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

Client 钉钉客户端

func NewClient

func NewClient(appKey, appSecret, agentID string) *Client

NewClient 创建钉钉客户端

func (*Client) GetAccessToken

func (c *Client) GetAccessToken(ctx context.Context) (string, error)

GetAccessToken 获取访问令牌

func (*Client) GetUserInfo

func (c *Client) GetUserInfo(ctx context.Context, userID string) (map[string]any, error)

GetUserInfo 获取用户信息

func (*Client) SendInteractiveCardMessage

func (c *Client) SendInteractiveCardMessage(ctx context.Context, conversationID string, card any) error

SendInteractiveCardMessage 发送交互式卡片消息

func (*Client) SendMarkdownMessage

func (c *Client) SendMarkdownMessage(ctx context.Context, conversationID, title, text string) error

SendMarkdownMessage 发送 Markdown 消息

func (*Client) SendStreamMessage

func (c *Client) SendStreamMessage(ctx context.Context, conversationID, streamID, content string, finished bool) error

SendStreamMessage 发送流式消息

func (*Client) SendTextMessage

func (c *Client) SendTextMessage(ctx context.Context, conversationID, content string) error

SendTextMessage 发送文本消息

func (*Client) UpdateAIStreamCard

func (c *Client) UpdateAIStreamCard(trackID, content string, isFinalize bool) error

UpdateAIStreamCard 更新AI流式卡片 (简化版本)

func (*Client) UpdateAIStreamCardWithError

func (c *Client) UpdateAIStreamCardWithError(trackID, errorMsg string) error

UpdateAIStreamCardWithError 更新AI流式卡片并标记错误

type CreateAndDeliverCardRequest

type CreateAndDeliverCardRequest struct {
	CardTemplateID   string
	OutTrackID       string
	ConversationID   string
	SenderStaffID    string
	RobotCode        string
	OpenSpaceID      string
	ConversationType string // "1" for private chat, "2" for group chat
	CardData         map[string]string
}

CreateAndDeliverCardRequest 创建并投放卡片请求

type Intent

type Intent struct {
	Action   string            // list, get, search
	Provider string            // aliyun, tencent, jenkins
	Resource string            // ecs, cvm, rds, cdb, job, build
	Params   map[string]string // 参数
	MCPTool  string            // 对应的 MCP 工具名称
}

Intent 用户意图

type IntentParser

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

IntentParser 意图解析器

func NewIntentParser

func NewIntentParser() *IntentParser

NewIntentParser 创建意图解析器

func (*IntentParser) Parse

func (p *IntentParser) Parse(message string) (*Intent, error)

Parse 解析用户消息

type MarkdownMsg

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

MarkdownMsg Markdown 消息

type MessageHandler

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

MessageHandler 消息处理器

func (*MessageHandler) HandleMessage

func (h *MessageHandler) HandleMessage(ctx context.Context, msg *CallbackMessage) (*CallbackResponse, error)

HandleMessage 处理消息

type StreamCardClient

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

StreamCardClient 流式卡片客户端

func NewStreamCardClient

func NewStreamCardClient() (*StreamCardClient, error)

NewStreamCardClient 创建流式卡片客户端

func (*StreamCardClient) CreateAndDeliverCard

func (s *StreamCardClient) CreateAndDeliverCard(accessToken string, req *CreateAndDeliverCardRequest) error

CreateAndDeliverCard 创建并投放流式卡片

func (*StreamCardClient) StreamingUpdate

func (s *StreamCardClient) StreamingUpdate(accessToken string, req *StreamingUpdateRequest) error

StreamingUpdate 流式更新卡片内容

type StreamManager

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

StreamManager 流式消息管理器

func NewStreamManager

func NewStreamManager(client *Client) *StreamManager

NewStreamManager 创建流式消息管理器

func (*StreamManager) Send

func (s *StreamManager) Send(ctx context.Context, conversationID, streamID, content string, finished bool) error

Send 发送流式消息

func (*StreamManager) SendError

func (s *StreamManager) SendError(ctx context.Context, conversationID, streamID string, err error) error

SendError 发送错误消息

func (*StreamManager) SendInChunks

func (s *StreamManager) SendInChunks(ctx context.Context, conversationID, streamID, content string) error

SendInChunks 分块发送长消息

func (*StreamManager) SendList

func (s *StreamManager) SendList(ctx context.Context, conversationID, streamID string, items []string) error

SendList 发送列表数据

func (*StreamManager) SendProgress

func (s *StreamManager) SendProgress(ctx context.Context, conversationID, streamID string, progress int, total int, message string) error

SendProgress 发送进度消息

func (*StreamManager) SendSuccess

func (s *StreamManager) SendSuccess(ctx context.Context, conversationID, streamID, message string) error

SendSuccess 发送成功消息

func (*StreamManager) SendTable

func (s *StreamManager) SendTable(ctx context.Context, conversationID, streamID string, headers []string, rows [][]string) error

SendTable 发送表格数据

type StreamingUpdateRequest

type StreamingUpdateRequest struct {
	OutTrackID string
	Key        string
	Content    string
	IsFull     bool
	IsFinalize bool
	IsError    bool
}

StreamingUpdateRequest 流式更新请求

type TextContent

type TextContent struct {
	Content string `json:"content"`
}

TextContent 文本消息内容

type TextMsg

type TextMsg struct {
	Content string `json:"content"`
}

TextMsg 文本消息

Jump to

Keyboard shortcuts

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