-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathworkers.js
57 lines (48 loc) · 1.34 KB
/
workers.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
49
50
51
52
53
54
55
56
57
const OPT = {
BotToken: '', // Telegram Bot Token
ChatID:'', // User ChatID
ParseMode: 'markdownv2' //keep blank, html, markdown or markdownv2
}
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
let url = new URL(request.url);
let title = url.searchParams.get('title');
let msg = url.searchParams.get('msg');
if (title == null || title == "") {
return new Response("No Title provided.", {
status: 200
})
}
if (msg == null || msg == "") {
return new Response("No Message provided.", {
status: 200
})
}
if(msg.errcode){
return new Response(JSON.stringify(msg), {
status: 200,
headers:{
'content-type':'application/json; charset=UTF-8'
}
})
}
return await sendMessage(title, msg);
}
async function sendMessage(title, msg){
let url = "https://api.telegram.org/";
url += "bot" + OPT.BotToken + "/sendMessage?";
url += "chat_id=" + OPT.ChatID + "&";
url += "parse_mode=" + OPT.ParseMode + "&";
url += "text=*" + title + "*%0A%0A";
url += msg;
return fetch(url ,{
method:'get',
headers: {
'Accept': 'text/html,application/xhtml+xml,application/xml;',
'Accept-Encoding': 'gzip, deflate, br',
'User-Agent': 'Mozilla/5.0 Chrome/90.0.4430.72'
}
});
}