wecom

package
v0.0.0-...-8419d72 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidSignature 在签名校验失败时返回。
	ErrInvalidSignature = errors.New("invalid signature")
	// ErrInvalidAESKey 当 AESKey 长度不符合规范时返回。
	ErrInvalidAESKey = errors.New("invalid aes key length")
)
View Source
var (
	// ErrNoResponse 表示业务层请求不进行任何被动回复(HTTP 200 OK 空包)。
	ErrNoResponse = errors.New("no response")
)

Functions

This section is empty.

Types

type ActionItem

type ActionItem struct {
	Text string `json:"text"` // 操作的描述文案
	Key  string `json:"key"`  // 操作key值
}

ActionItem 操作列表项

type ActionMenu

type ActionMenu struct {
	Desc       string       `json:"desc"`        // 更多操作界面的描述
	ActionList []ActionItem `json:"action_list"` // 操作列表 [1, 3]
}

ActionMenu 卡片右上角更多操作按钮

type AttachmentPayload

type AttachmentPayload struct {
	CallbackID string `json:"callback_id"`
	Actions    []struct {
		Name  string `json:"name"`
		Value string `json:"value"`
		Type  string `json:"type"`
	} `json:"actions"`
}

AttachmentPayload 智能应用回调附件

type Bot

type Bot struct {
	Sessions *SessionManager
	Crypto   *Crypt
	Pipeline botcore.PipelineInvoker
	Adapter  botcore.Adapter
	Emitter  botcore.Emitter
	Timeout  time.Duration
	// contains filtered or unexported fields
}

Bot 集成企业微信回调处理与流式响应逻辑。 Fields:

  • Sessions: 管理流式会话生命周期的 SessionManager
  • Crypto: 负责签名校验与加解密的 Crypt
  • Pipeline: 首包触发的业务流水线实现,可为空
  • Timeout: 刷新请求等待流水线片段的最大时长

func NewBot

func NewBot(crypto *Crypt, sessionTTL, timeout time.Duration, pipeline botcore.PipelineInvoker, opts ...BotOption) (*Bot, error)

NewBot 根据给定参数创建 Bot。 Parameters:

  • crypto: 企业微信加解密上下文,不能为空
  • sessionTTL: 会话最大存活时间(<=0 时使用 SessionManager 默认值)
  • timeout: 刷新请求等待流水线片段的最大时长(<=0 时在 Refresh 内回退默认值)
  • pipeline: 首包触发的业务流水线实现,可为 nil

Returns:

  • *Bot: 成功初始化的 Bot 实例
  • error: 当 crypto 为空时返回错误

func (*Bot) Cleanup

func (b *Bot) Cleanup()

Cleanup 清理过期会话,防止 Session 过度累积。

func (*Bot) Initial

func (b *Bot) Initial(msg *Message, timestamp, nonce string) (EncryptedResponse, error)

Initial 处理首次回调,创建流式会话并触发业务流水线。 Parameters:

  • msg: 企业微信解密后的消息
  • timestamp: 调用方传入的时间戳字符串
  • nonce: 请求参数中的随机串

Returns:

  • EncryptedResponse: 首包响应
  • error: 加密失败时返回

流程图:

[创建/复用会话] -> [触发流水线] -> [等待首帧] -> [有数据?] --是--> [Payload?] -> [直接回复]
                                         |          \
                                         |           -> [Stream?] -> [首包携带内容] -> [后台消费剩余]
                                         |
                                         -> [超时/无数据] -> [返回空StreamStart] -> [后台消费]

func (*Bot) PushStreamChunk

func (b *Bot) PushStreamChunk(msgID, content string, isFinal bool) bool

PushStreamChunk 兼容旧接口,便于在流水线外部直接推送片段。

func (*Bot) Refresh

func (b *Bot) Refresh(msg *Message, timestamp, nonce string) (EncryptedResponse, error)

Refresh 处理企业微信的流式刷新请求。 Parameters:

  • msg: 企业微信回调中的流式刷新消息
  • timestamp: 调用方传入的时间戳字符串
  • nonce: 随机串

Returns:

  • EncryptedResponse: 最新片段的加密响应
  • error: 会话加密失败时返回

流程图:

[提取streamID]
     |
streamID为空?
   /    \
 是      否
 |        |

[返回空终止] [从Session消费片段]

|

取到片段? —否→ [fallback命中?] —否→ [返回空Refresh]

 |                        |
是                        是
 |                        |

[标记完成(若final)] [使用fallback片段]

|
v

[加密并返回]

func (*Bot) ServeHTTP

func (b *Bot) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP 实现 http.Handler 接口,根据请求方法转发至不同处理逻辑。 Parameters:

  • w: http.ResponseWriter,用于写回响应
  • r: *http.Request,请求上下文

func (*Bot) SetFinalMessage

func (b *Bot) SetFinalMessage(msgID, content string)

SetFinalMessage 在非流式场景下缓存最终结果以备刷新,找不到会话时写入 fallback。 Parameters:

  • msgID: 企业微信消息 ID
  • content: 业务最终结果

type BotOption

type BotOption func(*Bot)

BotOption 用于定制 Bot 行为。

func WithAdapter

func WithAdapter(adapter botcore.Adapter) BotOption

WithAdapter 自定义消息标准化适配器。

func WithEmitter

func WithEmitter(emitter botcore.Emitter) BotOption

WithEmitter 覆盖默认的流式响应构造器。

type Button

type Button struct {
	Text  string `json:"text"`            // 按钮文案
	Style int    `json:"style,omitempty"` // 按钮样式 1~4
	Key   string `json:"key"`             // 按钮key
}

Button 按钮列表

type CardAction

type CardAction struct {
	Type     int    `json:"type"`               // 跳转类型: 1url, 2小程序
	URL      string `json:"url,omitempty"`      // 跳转url
	AppID    string `json:"appid,omitempty"`    // 小程序appid
	PagePath string `json:"pagepath,omitempty"` // 小程序pagepath
}

CardAction 整体卡片的点击跳转事件

type CardImage

type CardImage struct {
	URL         string  `json:"url"`                    // 图片url
	AspectRatio float64 `json:"aspect_ratio,omitempty"` // 宽高比 1.3 ~ 2.25
}

CardImage 图片样式

type Checkbox

type Checkbox struct {
	QuestionKey string           `json:"question_key"`      // 题目key
	Disable     bool             `json:"disable,omitempty"` // 是否不可选 (更新时有效)
	Mode        int              `json:"mode,omitempty"`    // 模式: 0单选, 1多选
	OptionList  []CheckboxOption `json:"option_list"`       // 选项列表
}

Checkbox 选择题样式

type CheckboxOption

type CheckboxOption struct {
	ID        string `json:"id"`         // 选项id
	Text      string `json:"text"`       // 选项文案
	IsChecked bool   `json:"is_checked"` // 是否默认选中
}

CheckboxOption 选择题选项

type Client

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

Client 封装企业微信主动回复功能。

func NewClient

func NewClient() *Client

NewClient 创建一个新的 Client。

func (*Client) Send

func (c *Client) Send(responseURL string, msg interface{}) error

Send 向指定的 response_url 发送主动回复消息。 对应文档:7_加解密说明.md - 如何主动回复消息 注意:response_url 有效期为 1 小时,且每个 url 仅可调用一次。

func (*Client) SendMarkdown

func (c *Client) SendMarkdown(responseURL, content string) error

SendMarkdown 发送 Markdown 消息

func (*Client) SendTemplateCard

func (c *Client) SendTemplateCard(responseURL string, card interface{}) error

SendTemplateCard 发送模板卡片消息

type Crypt

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

Crypt 封装企业微信的加解密逻辑。

func NewCrypt

func NewCrypt(token, encodingAESKey, corpID string) (*Crypt, error)

NewCrypt 创建一个新的 Crypt 实例,使用企业微信提供的 token、加密密钥与 corpID 作为上下文。 Parameters:

  • token: 企业微信配置的消息校验 Token
  • encodingAESKey: 企业微信后台生成的 43 字节 Base64 编码字符串
  • corpID: 企业 ID,用于校验消息归属

Returns:

  • *Crypt: 成功时的加解密器实例
  • error: 当 EncodingAESKey 无法解码或长度不合法时返回错误

func (*Crypt) DecryptMessage

func (c *Crypt) DecryptMessage(msgSignature, timestamp, nonce string, req EncryptedRequest) (*Message, error)

DecryptMessage 解密 POST 回调中的加密消息,并返回结构化后的 Message。 Parameters:

  • msgSignature: 企业微信用于签名的字段
  • timestamp: 时间戳
  • nonce: 随机串
  • req: 包含 encrypt 字段的回调体

Returns:

  • *Message: 成功解密并解析后的业务消息
  • error: 签名校验失败、解密失败或 JSON 解析失败时返回

流程图:

[收到加密请求]
     |
     v
[校验签名] --否--> [返回ErrInvalidSignature]
     |
    是
     |
     v
[Base64解密+AES-CBC解密]
     |
     v
[JSON解析为Message]
     |
     v
[返回Message]

func (*Crypt) EncryptResponse

func (c *Crypt) EncryptResponse(payload interface{}, timestamp, nonce string) (EncryptedResponse, error)

EncryptResponse 对回复明文进行加密封装。 Parameters:

  • payload: 待发送的明文结构体(如 StreamReply, TextMessage, TemplateCardMessage 等)
  • timestamp: 调用方生成的时间戳字符串
  • nonce: 回调参数中的随机串

Returns:

  • EncryptedResponse: 包含密文、签名等字段的响应包
  • error: 序列化或加密失败时返回

流程图:

[响应明文] -> [JSON序列化] -> [AES组包加密] -> [生成签名] -> [封装响应]

func (*Crypt) VerifyURL

func (c *Crypt) VerifyURL(msgSignature, timestamp, nonce, echoStr string) (string, error)

type EmphasisContent

type EmphasisContent struct {
	Title string `json:"title,omitempty"` // 关键数据内容
	Desc  string `json:"desc,omitempty"`  // 关键数据描述
}

EmphasisContent 关键数据样式

type EncryptedRequest

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

EncryptedRequest 对应企业微信 POST 回调中的加密请求格式。

type EncryptedResponse

type EncryptedResponse struct {
	Encrypt      string `json:"encrypt"`
	MsgSignature string `json:"msgsignature"`
	Timestamp    string `json:"timestamp"`
	Nonce        string `json:"nonce"`
}

EncryptedResponse 表示向企业微信回复的加密数据包。

type EventPayload

type EventPayload struct {
	EventType         string             `json:"eventtype"`
	EnterChat         *struct{}          `json:"enter_chat,omitempty"`
	TemplateCardEvent *TemplateCardEvent `json:"template_card_event,omitempty"`
	FeedbackEvent     *FeedbackEvent     `json:"feedback_event,omitempty"`
}

EventPayload 事件结构体

type FeedbackEvent

type FeedbackEvent struct {
	ID                   string `json:"id"`                               // 反馈ID
	Type                 int    `json:"type"`                             // 1:准确, 2:不准确, 3:取消
	Content              string `json:"content,omitempty"`                // 反馈内容
	InaccurateReasonList []int  `json:"inaccurate_reason_list,omitempty"` // 负反馈原因
}

FeedbackEvent 用户反馈事件

type FeedbackInfo

type FeedbackInfo struct {
	ID string `json:"id,omitempty"` // 反馈ID
}

FeedbackInfo 反馈信息 (用于主动回复)

type FilePayload

type FilePayload struct {
	URL string `json:"url"` // 文件下载地址
}

FilePayload 为文件消息内容。

type HorizontalContent

type HorizontalContent struct {
	Type    int    `json:"type,omitempty"`   // 链接类型: 0普通文本, 1跳转url, 3点击跳转成员详情
	KeyName string `json:"keyname"`          // 二级标题
	Value   string `json:"value,omitempty"`  // 二级文本
	URL     string `json:"url,omitempty"`    // 跳转url
	UserID  string `json:"userid,omitempty"` // 成员详情userid
}

HorizontalContent 二级标题+文本列表

type ImagePayload

type ImagePayload struct {
	URL    string `json:"url,omitempty"`    // 图片访问地址
	Base64 string `json:"base64,omitempty"` // 流式回复时使用
	MD5    string `json:"md5,omitempty"`    // 流式回复时使用
}

ImagePayload 为图片消息内容。

type ImageTextArea

type ImageTextArea struct {
	Type     int    `json:"type,omitempty"`     // 点击事件: 0无, 1url, 2小程序
	URL      string `json:"url,omitempty"`      // 跳转url
	AppID    string `json:"appid,omitempty"`    // 小程序appid
	PagePath string `json:"pagepath,omitempty"` // 小程序pagepath
	Title    string `json:"title,omitempty"`    // 标题
	Desc     string `json:"desc,omitempty"`     // 描述
	ImageURL string `json:"image_url"`          // 图片url
}

ImageTextArea 左图右文样式

type JumpAction

type JumpAction struct {
	Type     int    `json:"type,omitempty"`     // 跳转类型: 0无, 1url, 2小程序, 3触发消息智能回复
	Question string `json:"question,omitempty"` // 智能问答问题 (type=3)
	Title    string `json:"title"`              // 文案内容
	URL      string `json:"url,omitempty"`      // 跳转url
	AppID    string `json:"appid,omitempty"`    // 小程序appid
	PagePath string `json:"pagepath,omitempty"` // 小程序pagepath
}

JumpAction 跳转指引样式的列表

type MainTitle

type MainTitle struct {
	Title string `json:"title,omitempty"` // 一级标题
	Desc  string `json:"desc,omitempty"`  // 标题辅助信息
}

MainTitle 模版卡片的主要内容

type MarkdownMessage

type MarkdownMessage struct {
	MsgType  string          `json:"msgtype"` // markdown
	Markdown MarkdownPayload `json:"markdown"`
}

MarkdownMessage 主动回复 Markdown 消息结构

type MarkdownPayload

type MarkdownPayload struct {
	Content  string        `json:"content"`
	Feedback *FeedbackInfo `json:"feedback,omitempty"`
}

type Message

type Message struct {
	MsgID       string             `json:"msgid"`                 // 企业微信消息唯一标识
	CreateTime  int64              `json:"create_time,omitempty"` // 消息创建时间
	AIBotID     string             `json:"aibotid"`               // 机器人 ID
	ChatID      string             `json:"chatid"`                // 群或私聊会话 ID
	ChatType    string             `json:"chattype"`              // chat 类型(single/chatroom)
	From        MessageSender      `json:"from"`                  // 触发者信息
	ResponseURL string             `json:"response_url"`          // 异步回复 URL (部分事件有)
	MsgType     string             `json:"msgtype"`               // 消息类型: text, image, voice, file, mixed, stream, event
	Text        *TextPayload       `json:"text,omitempty"`
	Image       *ImagePayload      `json:"image,omitempty"`
	Voice       *VoicePayload      `json:"voice,omitempty"`
	File        *FilePayload       `json:"file,omitempty"`
	Mixed       *MixedPayload      `json:"mixed,omitempty"`
	Stream      *StreamPayload     `json:"stream,omitempty"`
	Quote       *QuotePayload      `json:"quote,omitempty"`
	Event       *EventPayload      `json:"event,omitempty"`
	Attachment  *AttachmentPayload `json:"attachment,omitempty"` // 某些事件可能带附件
}

Message 表示企业微信回调的通用消息结构。

func ParseMessage

func ParseMessage(data []byte) (*Message, error)

ParseMessage 将明文 JSON 数据解析为 Message。

type MessageAdapter

type MessageAdapter struct{}

MessageAdapter 将企业微信 Message 映射为通用 Update。

func (MessageAdapter) Normalize

func (MessageAdapter) Normalize(raw interface{}) (botcore.Update, error)

Normalize 实现 botcore.Adapter。

type MessageSender

type MessageSender struct {
	UserID string `json:"userid"`           // 用户 ID
	CorpID string `json:"corpid,omitempty"` // 企业 ID (事件中可能返回)
}

MessageSender 描述消息的触发者。

type MixedItem

type MixedItem struct {
	MsgType string        `json:"msgtype"`
	Text    *TextPayload  `json:"text,omitempty"`
	Image   *ImagePayload `json:"image,omitempty"`
}

MixedItem 为图文混排中的单个子消息。

type MixedPayload

type MixedPayload struct {
	Items []MixedItem `json:"msg_item"`
}

MixedPayload 表示图文混排消息。

type OptionIDs

type OptionIDs struct {
	OptionID []string `json:"option_id"`
}

OptionIDs 选项ID列表

type QuoteArea

type QuoteArea struct {
	Type      int    `json:"type,omitempty"`       // 点击事件: 0无, 1跳转url, 2跳转小程序
	URL       string `json:"url,omitempty"`        // 跳转url
	AppID     string `json:"appid,omitempty"`      // 小程序appid
	PagePath  string `json:"pagepath,omitempty"`   // 小程序pagepath
	Title     string `json:"title,omitempty"`      // 标题
	QuoteText string `json:"quote_text,omitempty"` // 引用文案
}

QuoteArea 引用文献样式

type QuotePayload

type QuotePayload struct {
	MsgType string        `json:"msgtype"`
	Text    *TextPayload  `json:"text,omitempty"`
	Image   *ImagePayload `json:"image,omitempty"`
	Mixed   *MixedPayload `json:"mixed,omitempty"`
	Voice   *VoicePayload `json:"voice,omitempty"`
	File    *FilePayload  `json:"file,omitempty"`
}

QuotePayload 引用消息内容。

type SelectOption

type SelectOption struct {
	ID   string `json:"id"`   // 选项id
	Text string `json:"text"` // 选项文案
}

SelectOption 选择器选项

type SelectedItem

type SelectedItem struct {
	QuestionKey string     `json:"question_key"`
	OptionIDs   *OptionIDs `json:"option_ids,omitempty"`
}

SelectedItem 单个选择项结果

type SelectedItems

type SelectedItems struct {
	SelectedItem []SelectedItem `json:"selected_item"`
}

SelectedItems 模板卡片选择结果容器

type SelectionItem

type SelectionItem struct {
	QuestionKey string         `json:"question_key"`          // 题目key
	Title       string         `json:"title,omitempty"`       // 标题
	Disable     bool           `json:"disable,omitempty"`     // 是否不可选 (更新时有效)
	SelectedID  string         `json:"selected_id,omitempty"` // 默认选中id
	OptionList  []SelectOption `json:"option_list"`           // 选项列表
}

SelectionItem 下拉式的选择器

type Session

type Session struct {
	StreamID   string         // 流式会话唯一标识
	MsgID      string         // 对应企业微信消息 ID
	ChatID     string         // 会话所属聊天 ID
	UserID     string         // 发起用户 ID
	Update     botcore.Update // 标准化事件上下文
	CreatedAt  time.Time      // 创建时间
	LastAccess time.Time      // 最近访问时间

	Finished    bool                 // 会话是否已完成
	LastChunk   *botcore.StreamChunk // 最近一次发送的片段,用于超时兜底
	Accumulated string               // 已累积的完整内容,用于满足企业微信“最新完整内容”语义
	// contains filtered or unexported fields
}

Session 表示一次流式会话的上下文。

type SessionManager

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

SessionManager 管理流式会话的生命周期。

func NewSessionManager

func NewSessionManager(ttl time.Duration) *SessionManager

NewSessionManager 创建 SessionManager。 Parameters:

  • ttl: 会话最长存活时间,非正值时回退为 1 分钟

Returns:

  • *SessionManager: 管理会话的实例

func (*SessionManager) Accumulate

func (m *SessionManager) Accumulate(streamID, content string) bool

Accumulate 仅累积内容到会话状态,不发布到队列。 适用于 Initial 阶段已经直接返回了内容,但需要同步会话状态的场景。

func (*SessionManager) Cleanup

func (m *SessionManager) Cleanup()

Cleanup 清理过期的会话。 流程图:

[遍历sessions]
     |
[检查LastAccess超时?] --否--> [跳过]
     |
    是
     |
[删除session及msgIndex映射]

func (*SessionManager) Consume

func (m *SessionManager) Consume(streamID string, timeout time.Duration) *botcore.StreamChunk

Consume 从会话队列中读取一个片段,超时返回 nil。 为了满足企业微信“content 为最新完整内容”的语义,会排干队列并返回最新的全量快照。

func (*SessionManager) CreateOrGet

func (m *SessionManager) CreateOrGet(msg *Message) (*Session, bool)

CreateOrGet 根据消息创建或返回既有会话。 Parameters:

  • msg: 企业微信消息体

Returns:

  • *Session: 匹配或新建的会话
  • bool: 是否创建了新会话

流程图:

[收到Message]
     |
有msgID?
   /   \
 是     否
 |      |

[查msgIndex]

  |
找到?
 / \
是  否
|    |

[返回旧会话] [生成新streamID]

       |
[初始化Session并索引]
       |
[返回新会话+isNew]

func (*SessionManager) GetStreamIDByMsg

func (m *SessionManager) GetStreamIDByMsg(msgID string) (string, bool)

GetStreamIDByMsg 根据 msgid 获取 streamID,用于消息与会话绑定。 Parameters:

  • msgID: 企业微信消息 ID

Returns:

  • string: 匹配的 streamID
  • bool: 是否存在对应会话

func (*SessionManager) GetUpdate

func (m *SessionManager) GetUpdate(streamID string) botcore.Update

GetUpdate 返回指定会话的标准化事件副本。

func (*SessionManager) MarkFinished

func (m *SessionManager) MarkFinished(streamID string)

MarkFinished 标记会话完成。 Parameters:

  • streamID: 会话标识

func (*SessionManager) Publish

func (m *SessionManager) Publish(streamID string, chunk botcore.StreamChunk) bool

Publish 向指定会话写入流式片段,队列满时会覆盖最新片段。 Parameters:

  • streamID: 会话标识
  • chunk: 待推送的流式数据

Returns:

  • bool: 成功写入返回 true

func (*SessionManager) SetUpdate

func (m *SessionManager) SetUpdate(streamID string, update botcore.Update)

SetUpdate 绑定标准化事件到会话。

type Source

type Source struct {
	IconURL   string `json:"icon_url,omitempty"`   // 来源图片的url
	Desc      string `json:"desc,omitempty"`       // 来源图片的描述
	DescColor int    `json:"desc_color,omitempty"` // 来源文字的颜色: 0(默认)灰色, 1黑色, 2红色, 3绿色
}

Source 卡片来源样式信息

type StreamEmitter

type StreamEmitter struct{}

StreamEmitter 将 StreamChunk 转换为企业微信 StreamReply。

func (StreamEmitter) Encode

func (StreamEmitter) Encode(update botcore.Update, streamID string, chunk botcore.StreamChunk) (interface{}, error)

Encode 将 chunk 降级为 StreamReply 结构体。

type StreamPayload

type StreamPayload struct {
	ID      string      `json:"id"`
	Finish  bool        `json:"finish,omitempty"`
	Content string      `json:"content,omitempty"`
	MsgItem []MixedItem `json:"msg_item,omitempty"` // 流式结束时支持图文
}

StreamPayload 表达流式消息的会话信息。

type StreamReply

type StreamReply struct {
	MsgType string          `json:"msgtype"`
	Stream  StreamReplyBody `json:"stream"`
}

StreamReply 用于构造流式消息回复的明文结构。

func BuildStreamReply

func BuildStreamReply(streamID, content string, finish bool) StreamReply

BuildStreamReply 根据 streamID 组装流式回复明文。

type StreamReplyBody

type StreamReplyBody struct {
	ID      string      `json:"id"`
	Finish  bool        `json:"finish"`
	Content string      `json:"content"`
	MsgItem []MixedItem `json:"msg_item,omitempty"`
}

StreamReplyBody 为流式回复中的具体内容。

type StreamWithTemplateCardMessage

type StreamWithTemplateCardMessage struct {
	MsgType      string          `json:"msgtype"`
	Stream       StreamReplyBody `json:"stream"`
	TemplateCard *TemplateCard   `json:"template_card"`
}

StreamWithTemplateCardMessage 被动回复流式+模版卡片

type SubmitButton

type SubmitButton struct {
	Text string `json:"text"` // 按钮文案
	Key  string `json:"key"`  // 按钮key
}

SubmitButton 提交按钮样式

type TemplateCard

type TemplateCard struct {
	CardType              string              `json:"card_type"`                         // 模版类型: text_notice, news_notice, button_interaction, vote_interaction, multiple_interaction
	Source                *Source             `json:"source,omitempty"`                  // 卡片来源样式信息
	ActionMenu            *ActionMenu         `json:"action_menu,omitempty"`             // 卡片右上角更多操作按钮
	MainTitle             *MainTitle          `json:"main_title,omitempty"`              // 一级标题
	EmphasisContent       *EmphasisContent    `json:"emphasis_content,omitempty"`        // 关键数据样式
	QuoteArea             *QuoteArea          `json:"quote_area,omitempty"`              // 引用文献样式
	SubTitleText          string              `json:"sub_title_text,omitempty"`          // 二级普通文本
	VerticalContentList   []VerticalContent   `json:"vertical_content_list,omitempty"`   // 二级垂直内容列表
	HorizontalContentList []HorizontalContent `json:"horizontal_content_list,omitempty"` // 二级标题+文本列表
	JumpList              []JumpAction        `json:"jump_list,omitempty"`               // 跳转指引样式列表
	CardAction            *CardAction         `json:"card_action,omitempty"`             // 整体卡片点击跳转
	TaskID                string              `json:"task_id,omitempty"`                 // 任务id
	CardImage             *CardImage          `json:"card_image,omitempty"`              // 图片样式 (news_notice)
	ImageTextArea         *ImageTextArea      `json:"image_text_area,omitempty"`         // 左图右文样式 (news_notice)
	ButtonSelection       *SelectionItem      `json:"button_selection,omitempty"`        // 下拉式选择器 (button_interaction)
	ButtonList            []Button            `json:"button_list,omitempty"`             // 按钮列表 (button_interaction)
	Checkbox              *Checkbox           `json:"checkbox,omitempty"`                // 选择题样式 (vote_interaction)
	SubmitButton          *SubmitButton       `json:"submit_button,omitempty"`           // 提交按钮 (vote_interaction, multiple_interaction)
	SelectList            []SelectionItem     `json:"select_list,omitempty"`             // 下拉式选择器列表 (multiple_interaction)
	Feedback              *FeedbackInfo       `json:"feedback,omitempty"`                // 反馈信息 (主动回复时使用)
}

TemplateCard 模版卡片结构体,涵盖多种卡片类型。 对应文档:5_模版卡片类型.md

type TemplateCardEvent

type TemplateCardEvent struct {
	CardType      string         `json:"card_type"`                // 模版类型
	EventKey      string         `json:"event_key"`                // 按钮Key
	TaskID        string         `json:"task_id"`                  // 任务ID
	SelectedItems *SelectedItems `json:"selected_items,omitempty"` // 选择结果
}

TemplateCardEvent 模板卡片事件

type TemplateCardMessage

type TemplateCardMessage struct {
	MsgType      string        `json:"msgtype"`
	TemplateCard *TemplateCard `json:"template_card"`
}

TemplateCardMessage 被动回复模版卡片消息

type TextMessage

type TextMessage struct {
	MsgType string       `json:"msgtype"`
	Text    *TextPayload `json:"text"`
}

TextMessage 被动回复文本消息

type TextPayload

type TextPayload struct {
	Content string `json:"content"` // 文本内容
}

TextPayload 为文本消息内容。

type UpdateTemplateCardMessage

type UpdateTemplateCardMessage struct {
	ResponseType string        `json:"response_type"` // update_template_card
	UserIDs      []string      `json:"userids,omitempty"`
	TemplateCard *TemplateCard `json:"template_card"`
}

UpdateTemplateCardMessage 更新模版卡片消息

type VerticalContent

type VerticalContent struct {
	Title string `json:"title"`          // 二级标题
	Desc  string `json:"desc,omitempty"` // 二级普通文本
}

VerticalContent 卡片二级垂直内容

type VoicePayload

type VoicePayload struct {
	Content string `json:"content"` // 语音转文本内容
}

VoicePayload 为语音消息内容。

Jump to

Keyboard shortcuts

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