-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathTelegramAPI_sample.js
More file actions
25 lines (21 loc) · 1006 Bytes
/
Copy pathTelegramAPI_sample.js
File metadata and controls
25 lines (21 loc) · 1006 Bytes
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
function main() {
var CONFIG = {
// Токен надо получить у BotFather, создав нового бота
TOKEN: '0987654321:QQQWWWEEERRRTTTYYYUUUIIIOOOPPP111222333',
// Напишите что-нибудь в чат вашему боту, после чего перейдите по ссылке https://api.telegram.org/bot<ТОКЕН>/getUpdates
// в ответном тексте найдите строку ..."chat":{"id":123456789,"first_name"... Нужно значение id.
CHAT_ID: '123456789'
};
var message = 'Юстас, я Алекс, приём!';
sendTelegramMessage(message);
function sendTelegramMessage(text) {
var telegramUrl = 'https://api.telegram.org/bot' + CONFIG.TOKEN + '/sendMessage?chat_id=' + CONFIG.CHAT_ID + '&text=';
var message = encodeURIComponent(text);
var sendMessageUrl = telegramUrl + message;
var options = {
method: 'POST',
contentType: 'application/json'
};
UrlFetchApp.fetch(sendMessageUrl, options);
}
}