-
Notifications
You must be signed in to change notification settings - Fork 0
/
step4.js
48 lines (40 loc) · 1.11 KB
/
step4.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
38
39
40
41
42
43
44
45
46
47
48
const
request = require('request'),
geturl = 'https://api.telegram.org/bot',
token = '417941177:AAH9Iq_vGCE4Z1if53wGg3ZFKmYHL_kywLU',
endurl = '/sendMessage',
date = new Date(),
reqOptions = {
method: 'POST',
url: `${geturl}${token}${endurl}`,
body: {
chat_id: 222515697,
text: 'Hi time is : ' + date,
},
json: true,
},
startRequest = (text) => {
return new Promise((resolve, reject) => {
console.log(text);
reqOptions.body.text = text;
request(reqOptions, (error, res, body) => {
if (!error && body && body.ok) {
resolve(body);
} else {
reject(error, body)
}
});
})
}
;
const startmsg = async function () {
try {
for (let i = 0; i < 5; i++) {
await startRequest('Hi' + i);
}
} catch (error) {
console.log(error)
}
}
startmsg();
// یه تمرین جالب که بالاخره باهاش حال کردم همین بود