This commit is contained in:
Rafael Lopes Pini 2026-01-29 21:53:38 -05:00 committed by GitHub
commit 139f8fbb6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 1 deletions

View File

@ -14,7 +14,9 @@ function unwrapMessage(message: proto.IMessage | undefined): proto.IMessage | un
return normalized as proto.IMessage | undefined;
}
function extractContextInfo(message: proto.IMessage | undefined): proto.IContextInfo | undefined {
export function extractContextInfo(
message: proto.IMessage | undefined,
): proto.IContextInfo | undefined {
if (!message) return undefined;
const contentType = getContentType(message);
const candidate = contentType ? (message as Record<string, unknown>)[contentType] : undefined;
@ -46,6 +48,22 @@ function extractContextInfo(message: proto.IMessage | undefined): proto.IContext
return undefined;
}
export interface ForwardingInfo {
isForwarded: boolean;
forwardingScore?: number;
}
export function extractForwardingInfo(rawMessage: proto.IMessage | undefined): ForwardingInfo {
const message = unwrapMessage(rawMessage);
if (!message) return { isForwarded: false };
const contextInfo = extractContextInfo(message);
if (!contextInfo) return { isForwarded: false };
return {
isForwarded: contextInfo.isForwarded ?? false,
forwardingScore: contextInfo.forwardingScore ?? undefined,
};
}
export function extractMentionedJids(rawMessage: proto.IMessage | undefined): string[] | undefined {
const message = unwrapMessage(rawMessage);
if (!message) return undefined;

View File

@ -13,6 +13,7 @@ import { checkInboundAccessControl } from "./access-control.js";
import { isRecentInboundMessage } from "./dedupe.js";
import {
describeReplyContext,
extractForwardingInfo,
extractLocationData,
extractMediaPlaceholder,
extractMentionedJids,
@ -222,6 +223,16 @@ export async function monitorWebInbox(options: {
if (!body) continue;
}
const replyContext = describeReplyContext(msg.message as proto.IMessage | undefined);
const forwardingInfo = extractForwardingInfo(msg.message as proto.IMessage | undefined);
// Add forwarding tag to body if message is forwarded
if (forwardingInfo.isForwarded) {
const forwardTag =
forwardingInfo.forwardingScore && forwardingInfo.forwardingScore >= 5
? "[forwarded many times]"
: "[forwarded]";
body = `${forwardTag} ${body}`;
}
let mediaPath: string | undefined;
let mediaType: string | undefined;
@ -290,6 +301,8 @@ export async function monitorWebInbox(options: {
groupSubject,
groupParticipants,
mentionedJids: mentionedJids ?? undefined,
isForwarded: forwardingInfo.isForwarded,
forwardingScore: forwardingInfo.forwardingScore,
selfJid,
selfE164,
location: location ?? undefined,

View File

@ -29,6 +29,8 @@ export type WebInboundMessage = {
groupSubject?: string;
groupParticipants?: string[];
mentionedJids?: string[];
isForwarded?: boolean;
forwardingScore?: number;
selfJid?: string | null;
selfE164?: string | null;
location?: NormalizedLocation;