-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-webhook-multiple.js
More file actions
165 lines (151 loc) · 4.52 KB
/
test-webhook-multiple.js
File metadata and controls
165 lines (151 loc) · 4.52 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
const crypto = require("crypto");
const http = require("http");
const fs = require("fs");
const path = require("path");
// Load .env file
function loadEnvFile() {
const envFiles = [".env.local", ".env"];
for (const envFile of envFiles) {
const envPath = path.join(process.cwd(), envFile);
if (fs.existsSync(envPath)) {
const content = fs.readFileSync(envPath, "utf8");
content.split("\n").forEach((line) => {
const match = line.match(/^([^=:#]+)=(.*)$/);
if (match) {
const key = match[1].trim();
const value = match[2].trim().replace(/^["']|["']$/g, "");
if (!process.env[key]) {
process.env[key] = value;
}
}
});
break;
}
}
}
loadEnvFile();
const webhookSecret = process.env.ZOOM_WEBHOOK_SECRET;
if (!webhookSecret) {
console.error("❌ Error: ZOOM_WEBHOOK_SECRET not found in .env files");
process.exit(1);
}
// Test multiple events
const testEvents = [
{
name: "Participant Joined",
payload: {
event: "meeting.participant_joined",
payload: {
account_id: "test_account_123",
account_email: "test@example.com",
object: {
id: "60c987a4-a979-4764-9181-3b3ee748d3f4",
uuid: "60c987a4-a979-4764-9181-3b3ee748d3f4",
host_id: "test_host_123",
topic: "Test Meeting",
meeting_number: "123456789",
participant: {
user_id: "a1b2c3d4-e5f6-4789-a012-345678901234",
user_name: "Test Participant",
email: "participant@example.com",
join_time: new Date().toISOString(),
},
},
},
},
},
{
name: "Participant Left",
payload: {
event: "meeting.participant_left",
payload: {
account_id: "test_account_123",
account_email: "test@example.com",
object: {
id: "60c987a4-a979-4764-9181-3b3ee748d3f4",
uuid: "60c987a4-a979-4764-9181-3b3ee748d3f4",
host_id: "test_host_123",
topic: "Test Meeting",
meeting_number: "123456789",
participant: {
user_id: "a1b2c3d4-e5f6-4789-a012-345678901234",
user_name: "Test Participant",
email: "participant@example.com",
leave_time: new Date().toISOString(),
leave_reason: "Left the meeting",
},
},
},
},
},
{
name: "Meeting Started",
payload: {
event: "meeting.started",
payload: {
account_id: "test_account_123",
object: {
id: "60c987a4-a979-4764-9181-3b3ee748d3f4",
uuid: "60c987a4-a979-4764-9181-3b3ee748d3f4",
host_id: "test_host_123",
topic: "Test Meeting",
meeting_number: "123456789",
start_time: new Date().toISOString(),
},
},
},
},
];
function sendRequest(payload, eventName) {
return new Promise((resolve, reject) => {
const timestamp = Date.now().toString();
const bodyString = JSON.stringify(payload);
const message = `v0:${timestamp}:${bodyString}`;
const signature = `v0=${crypto
.createHmac("sha256", webhookSecret)
.update(message)
.digest("hex")}`;
const options = {
hostname: "localhost",
port: 3000,
path: "/api/zoom/webhooks",
method: "POST",
headers: {
"Content-Type": "application/json",
"x-zm-signature": signature,
"x-zm-request-timestamp": timestamp,
Authorization: `Bearer ${webhookSecret}`,
},
};
const req = http.request(options, (res) => {
let data = "";
res.on("data", (chunk) => {
data += chunk;
});
res.on("end", () => {
resolve({ status: res.statusCode, data });
});
});
req.on("error", reject);
req.write(JSON.stringify(payload));
req.end();
});
}
async function runTests() {
console.log("🧪 Testing Zoom Webhook with Multiple Events\n");
for (const testEvent of testEvents) {
console.log(`📤 Sending: ${testEvent.name}...`);
try {
const result = await sendRequest(testEvent.payload, testEvent.name);
const response = JSON.parse(result.data);
console.log(` ✅ Status: ${result.status}`);
console.log(` Response: ${JSON.stringify(response)}\n`);
// Small delay between requests
await new Promise((resolve) => setTimeout(resolve, 500));
} catch (error) {
console.log(` ❌ Error: ${error.message}\n`);
}
}
console.log("✅ All tests completed! Check PostHog for logged events.");
}
runTests();