function keyPart(value) {
    if (typeof value === "string")
        return value;
    if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
        return String(value);
    }
    return "";
}
function firstKeyPart(...values) {
    for (const value of values) {
        const part = keyPart(value);
        if (part)
            return part;
    }
    return "unknown";
}
export function getMessageDedupKey(msg) {
    const channel = msg.channel;
    const meta = msg.meta ?? {};
    if (channel === "telegram") {
        const chatId = firstKeyPart(meta.chatId, meta.chat_id, msg.sender);
        const messageId = firstKeyPart(meta.messageId, meta.message_id, msg.id);
        return `${channel}:${chatId}:${messageId}`;
    }
    if (channel === "weixin") {
        const conversationId = firstKeyPart(meta.conversationId, meta.chatId, msg.sender);
        const messageId = firstKeyPart(meta.messageId, meta.msgId, msg.id);
        return `${channel}:${conversationId}:${messageId}`;
    }
    if (channel === "gmail") {
        const threadId = firstKeyPart(meta.threadId, msg.sender);
        const messageId = firstKeyPart(meta.messageId, msg.id);
        return `${channel}:${threadId}:${messageId}`;
    }
    const conversationId = firstKeyPart(meta.chatId, meta.conversationId, msg.sender);
    const providerMessageId = firstKeyPart(meta.messageId, meta.message_id, meta.id, msg.id);
    return `${channel}:${conversationId}:${providerMessageId}`;
}
//# sourceMappingURL=message-dedup.js.map