-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendTelegramv2.xml
57 lines (42 loc) · 1.56 KB
/
sendTelegramv2.xml
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
untuk cek id group
https://api.telegram.org/bot/getUpdates
id group selalu diawali -10xxxxxxx
https://api.telegram.org/bot<token>/getUpdates
.
kode ini perlu file jadi harus ada input file, hapus aja kalau gak perlu file, ubah bootleannya
<input type="file" id="fileInput"/>
<label for="fileInput">Upload bukti transfer (ss/pdf):</label>
======
run function
runPesan()
======
function runPesan() {
var tgbtoken = "xxxxxx:xxxxxxx"; // Ganti dengan token bot kamu
var tbGroup = "-10xxxxxxxxx"; // Id Group telegram
var xhr = new XMLHttpRequest();
var formData = new FormData();
formData.append("chat_id", tbGroup);
var pesan = "Yahooo min ada bug nih"; // Pesan form
var tanpaFile = true;//bootlean wajib file atau tidak
if (!tanpaFile) {
var file = document.getElementById("fileInput").files[0];
if (file) {
formData.append("document", file);
} else {
console.log("Silakan masukan ss/file bukti Bug terlebih dahulu!");
return;
}
formData.append("caption", pesan);// menggunakan caption, jika ada filenya maka pesan dikirim sebagai caption file.
} else {
formData.append("text", pesan); // Menggunakan "text" biasa untuk mengirim pesan teks tanpa file
}
console.log("Mengirim pesan");
var url = `https://api.telegram.org/bot${tgbtoken}/sendMessage`; // url api telegram
xhr.open("POST", url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
console.log("Pesan berhasil dikirim ke grup Telegram!");
}
};
xhr.send(formData);
}