-
Notifications
You must be signed in to change notification settings - Fork 52
/
TelegramAPI.js
57 lines (47 loc) · 1.17 KB
/
TelegramAPI.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
function debugTelegram(){
debug();
}
function postTelegram(payload) {
if (payload.text && payload.text.length > "4096") {
payload.text = payload.text.substr(0, 4096);
}
var data = {
'contentType': 'application/json',
"method": "post",
"muteHttpExceptions": true,
"payload": JSON.stringify(payload)
};
// mongo.insert(Const.toTelegram, payload);
var response;
var res;
try {
response = UrlFetchApp.fetch("https://api.telegram.org/bot" + Const.botToken + "/", data);
res = JSON.parse(response);
// mongo.insert("telegram-response", res);
return res;
} catch (e) {
var errorLog = {
error: e,
payload: payload,
};
mongo.insert(Const.logColl, errorLog);
return {error: errorLog};
}
}
function TestAPI(){
var payload;
var chatId = '539065210';
payload = {
"method": "sendMediaGroup",
"chat_id": chatId,
"media": [{
"type": "photo",
"media": "AgADBQADU6gxG4Hq0VSMR2yZkv7v5WQp1TIABIOh1Tq7OoMwlaYDAAEC"
},{
"type": "photo",
"media": "AgADBQADU6gxG4Hq0VSMR2yZkv7v5WQp1TIABFJCWxiLlftVlqYDAAEC"
}
]
};
postTelegram(payload);
}