-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendToTelegramBot.gs
60 lines (43 loc) · 1.66 KB
/
sendToTelegramBot.gs
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
58
59
60
// อ้างถึง คลิป
// https://www.youtube.com/watch?v=k1I1XbxjDcA
// ประกาศตัวแปร Global
let botToken = "YOUR_TOKEN";
// Chat ID เป็น Array เพื่อส่ง ไปได้หลายปลายทาง (หากต้องการ)
// หากต้องการ Chat ID 1 เดียว ก็สามารถแก้ไขได้
let botChatID = ["YOUR_CHAT_ID"]
// ทดสอบ / ตัวอย่างการเรียกใช้งาน
// ----------------------------------------------------
function testSendMessageText() {
sendMessageText(botChatID[0],'สวัสดีจาก GoogleSheet');
}
// ส่งข้อความ ไป Telegram Bot
// ----------------------------------------------------
function sendMessageText(chat_id, text) {
let payload = {
method: "sendMessage",
chat_id: String(chat_id),
text: text,
parse_mode: "HTML"
}
let options = {
method: "post",
payload: payload
};
UrlFetchApp.fetch('https://api.telegram.org/bot' + botToken + '/', options);
}
// ส่งรูปภาพและข้อความ ไป Telegram Bot
// ----------------------------------------------------
function sendMessagePhoto(chat_id,photoCaption, photoUrl) {
let payload = {
method: "sendPhoto",
chat_id: String(chat_id),
photo: photoUrl,
caption: photoCaption,
parse_mode: "HTML"
}
let options = {
method: "post",
payload: payload
};
UrlFetchApp.fetch('https://api.telegram.org/bot' + botToken + '/', options);
}