-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-slack-webhook.js
More file actions
71 lines (60 loc) · 1.72 KB
/
test-slack-webhook.js
File metadata and controls
71 lines (60 loc) · 1.72 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
// Script to test the Slack webhook endpoint
import https from 'https';
// Replit URL
const replitUrl = 'cf3428df-04d6-468d-af24-1dd4a587b350-00-3tucxtywmyqog.janeway.replit.dev';
// Test data - simulate a Slack message event
const testEvent = {
token: 'test-token',
team_id: 'T12345',
api_app_id: 'A12345',
event: {
type: 'message',
channel: 'C12345',
user: 'U12345',
text: 'This is a test task for tomorrow',
ts: `test-${Date.now()}`,
},
type: 'event_callback',
event_id: `Ev${Date.now()}`,
event_time: Math.floor(Date.now() / 1000),
};
// URL verification challenge data
const urlVerification = {
type: 'url_verification',
challenge: 'test-challenge',
};
console.log('Sending test event to webhook endpoint...');
// Which test to run? Can be 'event' or 'verification'
const testType = process.argv[2] || 'event';
const testData = testType === 'verification' ? urlVerification : testEvent;
// POST request options
const options = {
hostname: replitUrl,
port: 443,
path: '/slack/events',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Slack-Request-Timestamp': Math.floor(Date.now() / 1000).toString(),
'X-Slack-Signature': 'v0=test-signature',
}
};
// Send the request
const req = https.request(options, (res) => {
console.log(`STATUS: ${res.statusCode}`);
console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
console.log('Response body:', data);
console.log('Test complete');
});
});
req.on('error', (e) => {
console.error(`Problem with request: ${e.message}`);
});
// Write data to request body
req.write(JSON.stringify(testData));
req.end();