-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_webhook_server.php
More file actions
97 lines (79 loc) · 2.79 KB
/
test_webhook_server.php
File metadata and controls
97 lines (79 loc) · 2.79 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
// Test script to send webhook events to our local server
echo "🧪 Testing webhook server with sample events...\n\n";
// Test payload based on your actual SMS campaign
$testPayload = [
'type' => 'message.sent',
'campaign' => [
'id' => 7545088, // Your actual campaign ID
'title' => 'Bulk Test Campaign',
'message' => 'Hello ${firstName} ${lastName}, this is a test message!',
'senderPhone' => '+15551234567',
'createdAt' => '2025-07-28T17:45:03.190725Z',
'runAt' => '2025-07-28T17:45:03.190725Z'
],
'from' => '+15551234567',
'to' => '+14156961732',
'message' => 'Hello Andreas Garcia, this is a test message!'
];
$data = json_encode($testPayload);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost:8080/webhook');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($data)
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
echo "📤 Sending MESSAGE_SENT webhook to localhost:8080/webhook...\n";
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_error($ch)) {
echo "❌ Error: " . curl_error($ch) . "\n";
echo "💡 Make sure the webhook server is running:\n";
echo " php webhook_server.php\n";
} else {
echo "✅ Response Code: $httpCode\n";
echo "📥 Response: $response\n";
}
curl_close($ch);
// Test a received message event
sleep(1);
$receivedPayload = [
'type' => 'message.received',
'campaign' => [
'id' => 7545088,
'title' => 'Bulk Test Campaign',
'message' => 'Hello ${firstName} ${lastName}, this is a test message!',
'senderPhone' => '+15551234567',
'createdAt' => '2025-07-28T17:45:03.190725Z',
'runAt' => '2025-07-28T17:45:03.190725Z'
],
'from' => '+14156961732',
'to' => '+15551234567',
'message' => 'Thanks for the message!'
];
$data = json_encode($receivedPayload);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost:8080/webhook');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($data)
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
echo "\n📤 Sending MESSAGE_RECEIVED webhook to localhost:8080/webhook...\n";
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_error($ch)) {
echo "❌ Error: " . curl_error($ch) . "\n";
} else {
echo "✅ Response Code: $httpCode\n";
echo "📥 Response: $response\n";
}
curl_close($ch);
echo "\n🎉 Webhook testing completed!\n";