#!/usr/bin/env tsx /** * Test script to verify Zammad group webhook integration * * This tests the group_created event webhook that is sent from bridge-worker * to Zammad when a Signal group is created. */ // Using native fetch which is available in Node.js 18+ const ZAMMAD_URL = process.env.ZAMMAD_URL || 'http://localhost:8001'; const CHANNEL_TOKEN = process.env.CHANNEL_TOKEN || 'test-token'; async function testGroupWebhook() { console.log('Testing Zammad Signal group webhook...\n'); const webhookUrl = `${ZAMMAD_URL}/api/v1/channels_cdr_signal_webhook/${CHANNEL_TOKEN}`; const payload = { event: 'group_created', conversation_id: '12345', // This would be a real ticket number original_recipient: '+1234567890', group_id: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', timestamp: new Date().toISOString() }; console.log('Webhook URL:', webhookUrl); console.log('Payload:', JSON.stringify(payload, null, 2)); console.log('\nSending request...\n'); try { const response = await fetch(webhookUrl, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(payload), }); const responseText = await response.text(); console.log('Response Status:', response.status); console.log('Response Headers:', [...response.headers.entries()]); console.log('Response Body:', responseText); if (response.ok) { console.log('\n✅ Webhook test successful!'); try { const data = JSON.parse(responseText); console.log('Parsed response:', data); } catch (e) { // Response might not be JSON } } else { console.log('\n❌ Webhook test failed!'); } } catch (error) { console.error('\n❌ Error testing webhook:', error); } } // Run the test testGroupWebhook();