edtech / scripts /db-ops /test_wa_send.ts
CognxSafeTrack
refactor(worker): Sprint 2 β€” dead code removal and queue consolidation
37fb9ce
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);