Download apps/api/src/scripts/simulate-webhook.ts from safetrack/edtech: direct link, hf CLI and curl.
- Browser
- Download file 2.78 kB
-
https://huggingface.co/spaces/safetrack/edtech/resolve/main/apps/api/src/scripts/simulate-webhook.ts
- Command line
-
hf download hf://spaces/safetrack/edtech/apps/api/src/scripts/simulate-webhook.ts
-
curl -L -o simulate-webhook.ts https://huggingface.co/spaces/safetrack/edtech/resolve/main/apps/api/src/scripts/simulate-webhook.ts
2.78 kB
| /** | |
| * WhatsApp Webhook Simulator | |
| * | |
| * Usage: npx tsx apps/api/src/scripts/simulate-webhook.ts [phoneNumberId] [fromPhone] [text] | |
| */ | |
| const targetUrl = 'http://localhost:8080/v1/whatsapp/webhook'; | |
| const phoneNumberId = process.argv[2] || '1029384756'; | |
| const fromPhone = process.argv[3] || '33612345678'; | |
| const text = process.argv[4] || 'Hello from simulation!'; | |
| async function runSimulation() { | |
| console.log(`π Simulating message to ${targetUrl}...`); | |
| console.log(`π± Phone ID: ${phoneNumberId}`); | |
| console.log(`π€ From: ${fromPhone}`); | |
| console.log(`π¬ Text: "${text}"`); | |
| const payload = { | |
| object: 'whatsapp_business_account', | |
| entry: [ | |
| { | |
| id: 'WHATSAPP_BUSINESS_ACCOUNT_ID', | |
| changes: [ | |
| { | |
| value: { | |
| messaging_product: 'whatsapp', | |
| metadata: { | |
| display_phone_number: '123456789', | |
| phone_number_id: phoneNumberId | |
| }, | |
| contacts: [{ profile: { name: 'Test User' }, wa_id: fromPhone }], | |
| messages: [ | |
| { | |
| from: fromPhone, | |
| id: `wamid.HBgLMzM2MzA0Nzg0MDYVAgARGBI1NjI5RkZCMEY3OUM2ODRDOTQA`, | |
| timestamp: Math.floor(Date.now() / 1000).toString(), | |
| type: 'text', | |
| text: { body: text } | |
| } | |
| ] | |
| }, | |
| field: 'messages' | |
| } | |
| ] | |
| } | |
| ] | |
| }; | |
| try { | |
| const response = await fetch(targetUrl, { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| // We simulate the Meta HMAC signature if needed, or disable it in dev | |
| 'x-hub-signature-256': 'sha256=fake-signature-for-local-test' | |
| }, | |
| body: JSON.stringify(payload) | |
| }); | |
| const data = await response.json() as any; | |
| console.log(`\nβ Response (${response.status}):`, JSON.stringify(data, null, 2)); | |
| if (data.status === 'forwarded') { | |
| console.log("\nπ‘ The message was successfully FORWARDED to the internal worker."); | |
| } else if (data.status === 'received') { | |
| console.log("\nπ₯ The message was successfully QUEUED for local processing."); | |
| } | |
| } catch (err: any) { | |
| console.error("\nβ Simulation failed:", err.message); | |
| } | |
| } | |
| runSimulation(); | |