-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
37 lines (33 loc) · 1.04 KB
/
main.js
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
const https = require('https');
exports.handler = async (event) => {
const token = '803****9020:**************CJEydCJyMu3jzJ_w';
const message = {
chat_id: event.body.message.chat.id,
text: 'سلام.'
};
const options = {
hostname: 'api.telegram.org',
path: `/bot${token}/sendMessage`,
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
};
return new Promise((resolve, reject) => {
const req = https.request(options, (res) => {
res.setEncoding('utf8');
res.on('data', (chunk) => {
console.log(`BODY: ${chunk}`);
});
res.on('end', () => {
resolve({ statusCode: 200, body: 'Message sent' });
});
});
req.on('error', (e) => {
console.error(`problem with request: ${e.message}`);
reject({ statusCode: 500, body: `Error: ${e.message}` });
});
req.write(JSON.stringify(message));
req.end();
});
};