#!/bin/bash # Script pour tester le webhook N8N depuis la VM # Utilise les outils disponibles: curl, wget, python3, node # Charger .env.local si présent if [ -f .env.local ]; then export $(grep -v '^#' .env.local | xargs) fi # Variables WEBHOOK_URL="https://brain.slm-lab.net/webhook-test/mission-created" MISSION_ID="${1:-3103ec1a-acde-4025-9ead-4e1a0ddc047c}" API_URL="${NEXT_PUBLIC_API_URL:-https://hub.slm-lab.net/api}" API_KEY="${N8N_API_KEY}" # Vérifier que l'API key est définie if [ -z "$API_KEY" ]; then echo "❌ Erreur: N8N_API_KEY n'est pas définie" echo " Vérifiez votre fichier .env.local ou exportez N8N_API_KEY" exit 1 fi echo "🧪 Test du webhook N8N depuis la VM" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "Webhook URL: $WEBHOOK_URL" echo "Mission ID: $MISSION_ID" echo "API URL: $API_URL" echo "" # Préparer le JSON JSON_DATA=$(cat < /dev/null; then echo "📤 Utilisation de curl..." echo "" curl -X POST "${WEBHOOK_URL}" \ -H "Content-Type: application/json" \ -d "$JSON_DATA" \ -v elif command -v wget &> /dev/null; then echo "📤 Utilisation de wget..." echo "" echo "$JSON_DATA" | wget --method=POST \ --header="Content-Type: application/json" \ --body-data=- \ --output-document=- \ --server-response \ "${WEBHOOK_URL}" 2>&1 elif command -v python3 &> /dev/null; then echo "📤 Utilisation de python3..." echo "" python3 < /dev/null; then echo "📤 Utilisation de node..." echo "" node < { console.log(\`Status: \${res.statusCode} \${res.statusMessage}\`); console.log(\`Headers:\`, res.headers); console.log(\`\nResponse Body:\`); let body = ''; res.on('data', (chunk) => { body += chunk; }); res.on('end', () => { try { console.log(JSON.stringify(JSON.parse(body), null, 2)); } catch (e) { console.log(body); } }); }); req.on('error', (e) => { console.error(\`Erreur: \${e.message}\`); process.exit(1); }); req.write(JSON.stringify(data)); req.end(); NODE_SCRIPT else echo "❌ Aucun outil disponible (curl, wget, python3, node)" exit 1 fi echo "" echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "✅ Test terminé" echo "" echo "💡 Vérifiez les logs N8N pour voir la structure de la réponse RocketChat"