
const { createClient } = require('@supabase/supabase-js');
const dotenv = require('dotenv');
const path = require('path');
const fs = require('fs');

const envPaths = [path.join(__dirname, '.env'), path.join(__dirname, '..', '.env')];
for (const p of envPaths) { if (fs.existsSync(p)) dotenv.config({ path: p }); }

const supabaseUrl = process.env.SUPABASE_URL || 'https://dtaegtkfdwgdbyolcxht.supabase.co';
const supabaseKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
const supabase = createClient(supabaseUrl, supabaseKey);

async function checkMessage() {
    const messageId = '06518aa1-fa7a-432d-8c04-c497ef7fc542';
    const { data, error } = await supabase
        .from('messages')
        .select('*')
        .eq('id', messageId)
        .single();

    if (error) {
        console.error('Error fetching message:', error);
        return;
    }

    console.log('--- DB Data ---');
    console.log('Message ID:', data.id);
    console.log('Status:', data.status);
    console.log('Content length:', data.content.length);
    console.log('Content preview:', data.content.substring(0, 100).replace(/\n/g, ' ') + '...');
    console.log('Content last 100 chars:', '...' + data.content.substring(data.content.length - 100).replace(/\n/g, ' '));
    console.log('--- End ---');

    fs.writeFileSync('/tmp/full_content_new.txt', data.content);
}

checkMessage();
