mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 10:27:38 +00:00
fix(telegram): include forward_from_chat metadata in forwarded message context (#8133)
Extract missing metadata from forwarded Telegram messages: - Add fromChatType to TelegramForwardedContext, capturing the original chat type (channel/supergroup/group) from forward_from_chat.type and forward_origin.chat/sender_chat.type - Add fromMessageId to capture the original message ID from channel forwards - Read author_signature from forward_origin objects (modern API), preferring it over the deprecated forward_signature field - Pass ForwardedFromChatType and ForwardedFromMessageId through to the inbound context payload - Add test coverage for forward_origin channel/chat types, including author_signature extraction and fromChatType propagation
This commit is contained in:
@@ -261,6 +261,10 @@ export type TelegramForwardedContext = {
|
||||
fromUsername?: string;
|
||||
fromTitle?: string;
|
||||
fromSignature?: string;
|
||||
/** Original chat type from forward_from_chat (e.g. "channel", "supergroup", "group"). */
|
||||
fromChatType?: string;
|
||||
/** Original message ID in the source chat (channel forwards). */
|
||||
fromMessageId?: number;
|
||||
};
|
||||
|
||||
function normalizeForwardedUserLabel(user: User) {
|
||||
@@ -323,6 +327,7 @@ function buildForwardedContextFromChat(params: {
|
||||
date?: number;
|
||||
type: string;
|
||||
signature?: string;
|
||||
messageId?: number;
|
||||
}): TelegramForwardedContext | null {
|
||||
const fallbackKind = params.type === "channel" ? "channel" : "chat";
|
||||
const { display, title, username, id } = normalizeForwardedChatLabel(params.chat, fallbackKind);
|
||||
@@ -331,6 +336,7 @@ function buildForwardedContextFromChat(params: {
|
||||
}
|
||||
const signature = params.signature?.trim() || undefined;
|
||||
const from = signature ? `${display} (${signature})` : display;
|
||||
const chatType = params.chat.type?.trim() || undefined;
|
||||
return {
|
||||
from,
|
||||
date: params.date,
|
||||
@@ -339,6 +345,8 @@ function buildForwardedContextFromChat(params: {
|
||||
fromUsername: username,
|
||||
fromTitle: title,
|
||||
fromSignature: signature,
|
||||
fromChatType: chatType,
|
||||
fromMessageId: params.messageId,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -369,6 +377,7 @@ function resolveForwardOrigin(origin: MessageOrigin): TelegramForwardedContext |
|
||||
date: origin.date,
|
||||
type: "channel",
|
||||
signature: origin.author_signature,
|
||||
messageId: origin.message_id,
|
||||
});
|
||||
default:
|
||||
// Exhaustiveness guard: if Grammy adds a new MessageOrigin variant,
|
||||
|
||||
Reference in New Issue
Block a user