-
Notifications
You must be signed in to change notification settings - Fork 227
feat: 合并转发外显信息 #678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: 合并转发外显信息 #678
Conversation
Reviewer's Guide为合并/转发消息添加可自定义展示元数据(标题/来源、预览/新闻、摘要、提示文案),覆盖 Milky APIs 和 OneBot11 go-cqhttp actions,在整个 transform/encoding 管线中传递这些选项,并在最终消息元素中使用计算得到的提示文案(prompt),而不是固定占位符。 可自定义转发消息元数据流程序列图sequenceDiagram
actor BotDeveloper
participant OB11Client as SendForwardMsg
participant Encoder as MessageEncoder
participant PMHQ as PMHQService
participant App as AppService
BotDeveloper->>OB11Client: SendForwardMsg(payload with source, news, summary, prompt)
OB11Client->>Encoder: generate(nodes, options)
Note over Encoder: options.source, options.news,
Note over Encoder: options.summary, options.prompt
Encoder-->>OB11Client: raw { multiMsgItems, tsum, source, summary, news, prompt }
OB11Client->>PMHQ: uploadForward(peer, raw.multiMsgItems)
PMHQ-->>OB11Client: resid
OB11Client->>OB11Client: prompt = options.prompt or "[聊天记录]"
OB11Client->>App: sendMessage(ctx, peer, forward_element with desc=prompt, prompt=prompt)
App-->>BotDeveloper: Response with message id
Milky API 转发消息元数据传递时序图sequenceDiagram
participant API as SendPrivateMessage
participant Transform as transformOutgoingForwardMessages
participant FEncoder as ForwardMessageEncoder
participant PMHQ as PMHQService
participant App as AppService
API->>Transform: transformOutgoingForwardMessages(ctx, messages, peer, options)
Transform->>FEncoder: generate(messages, options)
FEncoder-->>Transform: raw { multiMsgItems, tsum, source, summary, news, prompt }
Transform-->>API: raw
API->>PMHQ: uploadForward(peer, raw.multiMsgItems)
PMHQ-->>API: resid
API->>API: prompt = raw.prompt
API->>App: sendMessage(ctx, peer, forward_element with desc=prompt, prompt=prompt)
App-->>API: RawMessage result
更新后的转发消息编码器与 action 类图classDiagram
class SendForwardMsg {
+execute(payload: Payload) Promise~Response~
-handleFakeForwardNode(peer: Peer, nodes: OB11MessageNode[], options: ForwardOptions) Promise~Response~
-handleForwardNode(peer: Peer, nodes: OB11MessageNode[], msgInfos: MsgInfo[]) Promise~Response~
}
class Payload {
+messages: OB11MessageNode[]
+message: OB11MessageNode[]
+message_type: string
+source: string
+news: NewsItem[]
+summary: string
+prompt: string
}
class ForwardOptions {
+source: string
+news: NewsItem[]
+summary: string
+prompt: string
}
class NewsItem {
+text: string
}
class MessageEncoder {
-ctx: Context
-peer: Peer
-tsum: number
-isGroup: boolean
-news: NewsItem[]
+render(content: OB11MessageData[]) Promise~void~
+generate(content: OB11MessageData[], options: EncoderOptions) Promise~EncodedForward~
}
class EncoderOptions {
+source: string
+news: NewsItem[]
+summary: string
+prompt: string
}
class ForwardMessageEncoder {
-ctx: Context
-peer: Peer
-tsum: number
-isGroup: boolean
-news: NewsItem[]
+render(content: OutgoingForwardedMessage[]) Promise~void~
+generate(content: OutgoingForwardedMessage[], options: ForwardMetaOptions) Promise~EncodedForward~
}
class ForwardMetaOptions {
+title: string
+preview: NewsItem[]
+summary: string
+prompt: string
}
class EncodedForward {
+multiMsgItems: any[]
+tsum: number
+source: string
+summary: string
+news: NewsItem[]
+prompt: string
}
class transformOutgoingForwardMessages {
+transformOutgoingForwardMessages(ctx: Context, messages: OutgoingForwardedMessage[], peer: Peer, options: ForwardMetaOptions) Promise~EncodedForward~
}
SendForwardMsg --> MessageEncoder : uses
SendForwardMsg --> ForwardOptions : passes
MessageEncoder --> EncoderOptions : uses
ForwardMessageEncoder --> ForwardMetaOptions : uses
transformOutgoingForwardMessages --> ForwardMessageEncoder : uses
MessageEncoder --> EncodedForward : returns
ForwardMessageEncoder --> EncodedForward : returns
文件级变更
Tips and commandsInteracting with Sourcery
Customizing Your Experience访问你的 dashboard 以:
Getting HelpOriginal review guide in EnglishReviewer's GuideAdds support for customizable display metadata (title/source, preview/news, summary, prompt) for merged/forwarded messages across Milky APIs and OneBot11 go-cqhttp actions, threading these options through the transform/encoding pipeline and using the computed prompt in the final message elements instead of a fixed placeholder. Sequence diagram for customizable forward message metadata flowsequenceDiagram
actor BotDeveloper
participant OB11Client as SendForwardMsg
participant Encoder as MessageEncoder
participant PMHQ as PMHQService
participant App as AppService
BotDeveloper->>OB11Client: SendForwardMsg(payload with source, news, summary, prompt)
OB11Client->>Encoder: generate(nodes, options)
Note over Encoder: options.source, options.news,
Note over Encoder: options.summary, options.prompt
Encoder-->>OB11Client: raw { multiMsgItems, tsum, source, summary, news, prompt }
OB11Client->>PMHQ: uploadForward(peer, raw.multiMsgItems)
PMHQ-->>OB11Client: resid
OB11Client->>OB11Client: prompt = options.prompt or "[聊天记录]"
OB11Client->>App: sendMessage(ctx, peer, forward_element with desc=prompt, prompt=prompt)
App-->>BotDeveloper: Response with message id
Sequence diagram for Milky API forward message metadata propagationsequenceDiagram
participant API as SendPrivateMessage
participant Transform as transformOutgoingForwardMessages
participant FEncoder as ForwardMessageEncoder
participant PMHQ as PMHQService
participant App as AppService
API->>Transform: transformOutgoingForwardMessages(ctx, messages, peer, options)
Transform->>FEncoder: generate(messages, options)
FEncoder-->>Transform: raw { multiMsgItems, tsum, source, summary, news, prompt }
Transform-->>API: raw
API->>PMHQ: uploadForward(peer, raw.multiMsgItems)
PMHQ-->>API: resid
API->>API: prompt = raw.prompt
API->>App: sendMessage(ctx, peer, forward_element with desc=prompt, prompt=prompt)
App-->>API: RawMessage result
Class diagram for updated forward message encoders and actionclassDiagram
class SendForwardMsg {
+execute(payload: Payload) Promise~Response~
-handleFakeForwardNode(peer: Peer, nodes: OB11MessageNode[], options: ForwardOptions) Promise~Response~
-handleForwardNode(peer: Peer, nodes: OB11MessageNode[], msgInfos: MsgInfo[]) Promise~Response~
}
class Payload {
+messages: OB11MessageNode[]
+message: OB11MessageNode[]
+message_type: string
+source: string
+news: NewsItem[]
+summary: string
+prompt: string
}
class ForwardOptions {
+source: string
+news: NewsItem[]
+summary: string
+prompt: string
}
class NewsItem {
+text: string
}
class MessageEncoder {
-ctx: Context
-peer: Peer
-tsum: number
-isGroup: boolean
-news: NewsItem[]
+render(content: OB11MessageData[]) Promise~void~
+generate(content: OB11MessageData[], options: EncoderOptions) Promise~EncodedForward~
}
class EncoderOptions {
+source: string
+news: NewsItem[]
+summary: string
+prompt: string
}
class ForwardMessageEncoder {
-ctx: Context
-peer: Peer
-tsum: number
-isGroup: boolean
-news: NewsItem[]
+render(content: OutgoingForwardedMessage[]) Promise~void~
+generate(content: OutgoingForwardedMessage[], options: ForwardMetaOptions) Promise~EncodedForward~
}
class ForwardMetaOptions {
+title: string
+preview: NewsItem[]
+summary: string
+prompt: string
}
class EncodedForward {
+multiMsgItems: any[]
+tsum: number
+source: string
+summary: string
+news: NewsItem[]
+prompt: string
}
class transformOutgoingForwardMessages {
+transformOutgoingForwardMessages(ctx: Context, messages: OutgoingForwardedMessage[], peer: Peer, options: ForwardMetaOptions) Promise~EncodedForward~
}
SendForwardMsg --> MessageEncoder : uses
SendForwardMsg --> ForwardOptions : passes
MessageEncoder --> EncoderOptions : uses
ForwardMessageEncoder --> ForwardMetaOptions : uses
transformOutgoingForwardMessages --> ForwardMessageEncoder : uses
MessageEncoder --> EncodedForward : returns
ForwardMessageEncoder --> EncodedForward : returns
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - 我提供了一些整体性的反馈:
- 用于转发元数据(title/source、preview/news、summary、prompt)的内联选项类型在多个位置重复出现;建议抽取为共享的 interface/type,这样可以保持结构一致并更易于维护。
- 默认的 prompt 字符串“[聊天记录]”在多个实现中重复使用(ForwardMessageEncoder、MessageEncoder、handleFakeForwardNode);将其集中到一个共享常量中可以降低不同实现之间不一致的风险。
给 AI Agents 的提示词
Please address the comments from this code review:
## Overall Comments
- The inline option types for forward metadata (title/source, preview/news, summary, prompt) are duplicated in several places; consider extracting shared interfaces/types so the shape stays consistent and easier to maintain.
- The default prompt string '[聊天记录]' is repeated in multiple implementations (ForwardMessageEncoder, MessageEncoder, handleFakeForwardNode); centralizing this into a shared constant would reduce the risk of divergence.帮我变得更有用!请对每条评论点 👍 或 👎,我会根据你的反馈改进后续的代码评审。
Original comment in English
Hey - I've left some high level feedback:
- The inline option types for forward metadata (title/source, preview/news, summary, prompt) are duplicated in several places; consider extracting shared interfaces/types so the shape stays consistent and easier to maintain.
- The default prompt string '[聊天记录]' is repeated in multiple implementations (ForwardMessageEncoder, MessageEncoder, handleFakeForwardNode); centralizing this into a shared constant would reduce the risk of divergence.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The inline option types for forward metadata (title/source, preview/news, summary, prompt) are duplicated in several places; consider extracting shared interfaces/types so the shape stays consistent and easier to maintain.
- The default prompt string '[聊天记录]' is repeated in multiple implementations (ForwardMessageEncoder, MessageEncoder, handleFakeForwardNode); centralizing this into a shared constant would reduce the risk of divergence.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
已增加对嵌套合并转发的支持,API 调用方法和 napcat 大致相同,只是 node 的发送者字段在这里是 name 和 uin,而不是 username 和 user_id。这是 LuckyLilliaBot 本来就这样的,onebot 方言,没办法 |
|
能否拆成两个 PR,由于 Milky 那边可能需要标准定下来才能 merge,OneBot 这个可以先 merge |
|
好的 |
Summary by Sourcery
为私聊、群聊以及 go-cqhttp OneBot 发送流程中的合并转发消息提供可自定义的展示元数据支持。
新功能:
增强改进:
Original summary in English
Summary by Sourcery
Support customizable display metadata for merged forward messages across private, group, and go-cqhttp OneBot send flows.
New Features:
Enhancements: