File size: 1,840 Bytes
37fb9ce | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | import 'dotenv/config';
import path from 'path';
import dotenv from 'dotenv';
dotenv.config({ path: path.join(__dirname, '../../../../.env') });
import { PrismaClient } from '@prisma/client';
import { decrypt } from '../../../packages/shared-types/src/crypto';
import axios from 'axios';
const prisma = new PrismaClient();
async function testSend() {
const orgId = 'default-org-id';
const org = await prisma.organization.findUnique({
where: { id: orgId },
include: { phoneNumbers: true }
});
if (!org || !org.systemUserToken || !org.phoneNumbers[0]) {
console.log('❌ Org or token or phone missing');
return;
}
const encryptionSecret = process.env.ENCRYPTION_SECRET || '';
const decryptedToken = decrypt(org.systemUserToken, encryptionSecret);
const phoneNumberId = org.phoneNumbers[0].id;
console.log(`Testing send for Org: ${org.name}`);
console.log(`Token starts with EAA: ${decryptedToken.startsWith('EAA')}`);
console.log(`Phone Number ID: ${phoneNumberId}`);
const url = `https://graph.facebook.com/v18.0/${phoneNumberId}/messages`;
const payload = {
messaging_product: 'whatsapp',
recipient_type: 'individual',
to: '221771234567', // Dummy number, just testing auth
type: 'text',
text: { body: 'Test Audit' }
};
try {
await axios.post(url, payload, {
headers: {
'Authorization': `Bearer ${decryptedToken}`,
'Content-Type': 'application/json'
}
});
console.log('✅ Auth successful (Meta accepted the token, even if phone is dummy)');
} catch (err: any) {
console.error('❌ Auth FAILED:', err.response?.data || err.message);
}
await prisma.$disconnect();
}
testSend().catch(console.error);
|