Documentation
¶
Index ¶
- func ExtractUserMessage(msg *CallbackMessage) string
- func GetHelpMessage() string
- func IsValidTimestamp(timestamp string) bool
- type AccessTokenResponse
- type ActionCardMsg
- type AtUser
- type Btn
- type CallbackCrypto
- type CallbackMessage
- type CallbackRequest
- type CallbackResponse
- type Client
- func (c *Client) GetAccessToken(ctx context.Context) (string, error)
- func (c *Client) GetUserInfo(ctx context.Context, userID string) (map[string]any, error)
- func (c *Client) SendInteractiveCardMessage(ctx context.Context, conversationID string, card any) error
- func (c *Client) SendMarkdownMessage(ctx context.Context, conversationID, title, text string) error
- func (c *Client) SendStreamMessage(ctx context.Context, conversationID, streamID, content string, finished bool) error
- func (c *Client) SendTextMessage(ctx context.Context, conversationID, content string) error
- func (c *Client) UpdateAIStreamCard(trackID, content string, isFinalize bool) error
- func (c *Client) UpdateAIStreamCardWithError(trackID, errorMsg string) error
- type CreateAndDeliverCardRequest
- type Intent
- type IntentParser
- type MarkdownMsg
- type MessageHandler
- type StreamCardClient
- type StreamManager
- func (s *StreamManager) Send(ctx context.Context, conversationID, streamID, content string, finished bool) error
- func (s *StreamManager) SendError(ctx context.Context, conversationID, streamID string, err error) error
- func (s *StreamManager) SendInChunks(ctx context.Context, conversationID, streamID, content string) error
- func (s *StreamManager) SendList(ctx context.Context, conversationID, streamID string, items []string) error
- func (s *StreamManager) SendProgress(ctx context.Context, conversationID, streamID string, progress int, total int, ...) error
- func (s *StreamManager) SendSuccess(ctx context.Context, conversationID, streamID, message string) error
- func (s *StreamManager) SendTable(ctx context.Context, conversationID, streamID string, headers []string, ...) error
- type StreamingUpdateRequest
- type TextContent
- type TextMsg
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractUserMessage ¶
func ExtractUserMessage(msg *CallbackMessage) string
ExtractUserMessage 提取用户消息内容(去除@机器人部分)
func IsValidTimestamp ¶
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 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 (*Client) GetAccessToken ¶
GetAccessToken 获取访问令牌
func (*Client) GetUserInfo ¶
GetUserInfo 获取用户信息
func (*Client) SendInteractiveCardMessage ¶
func (c *Client) SendInteractiveCardMessage(ctx context.Context, conversationID string, card any) error
SendInteractiveCardMessage 发送交互式卡片消息
func (*Client) SendMarkdownMessage ¶
SendMarkdownMessage 发送 Markdown 消息
func (*Client) SendStreamMessage ¶
func (c *Client) SendStreamMessage(ctx context.Context, conversationID, streamID, content string, finished bool) error
SendStreamMessage 发送流式消息
func (*Client) SendTextMessage ¶
SendTextMessage 发送文本消息
func (*Client) UpdateAIStreamCard ¶
UpdateAIStreamCard 更新AI流式卡片 (简化版本)
func (*Client) UpdateAIStreamCardWithError ¶
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 意图解析器
type MarkdownMsg ¶
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 发送成功消息