-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsTelegramReply.html
More file actions
172 lines (152 loc) · 5.97 KB
/
JsTelegramReply.html
File metadata and controls
172 lines (152 loc) · 5.97 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Telegram | JsReply</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.0/css/bulma.min.css" />
<link href="https://fonts.googleapis.com/css2?family=Viga:wght@400;600&display=swap" rel="stylesheet" />
<script src="https://code.iconify.design/3/3.1.0/iconify.min.js"></script>
<style>
body {
font-family: 'Viga', sans-serif;
background-color: #f9f9f9;
-webkit-tap-highlight-color: transparent;
}
input:focus,
textarea:focus,
button:focus {
font-family: 'Viga', sans-serif !important;
outline: none !important;
box-shadow: none !important;
border-color: #ccc !important;
-webkit-tap-highlight-color: transparent;
}
.button {
font-family: 'Viga', sans-serif !important;
transition: all 0.3s ease;
-webkit-tap-highlight-color: transparent;
}
.button:hover {
transform: translateY(-1px);
}
.iconify {
vertical-align: middle;
margin-right: 6px;
}
#ReceivedMessages p {
padding: 0.5rem;
border-bottom: 1px solid #eee;
font-size: 0.95rem;
}
.Viga {
font-family: 'Viga', sans-serif;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', () => {
setDefaultValue()
})
function setDefaultValue() {
const urlParams = new URLSearchParams(window.location.search)
document.getElementById('bot_token').value = urlParams.get('bot_token') || ''
document.getElementById('bot_chat_id').value = urlParams.get('bot_chat_id') || ''
document.getElementById('bot_message').value = urlParams.get('bot_message') || ''
}
function send() {
let bot_token = document.getElementById('bot_token').value
let bot_chat_id = document.getElementById('bot_chat_id').value
let bot_message = document.getElementById('bot_message').value
bot_message = bot_message.replace(/ /g, "+")
let bot_request_url = `https://api.telegram.org/bot${bot_token}/sendMessage?chat_id=${bot_chat_id}&text=${bot_message}`
fetch(bot_request_url).then(r => r.json()).then(data => console.log(data))
}
function viewReceived() {
let bot_token = document.getElementById('bot_token').value
let bot_request_url = `https://api.telegram.org/bot${bot_token}/getUpdates`
fetch(bot_request_url)
.then(r => r.json())
.then(data => {
const container = document.getElementById("ReceivedMessages")
container.innerHTML = ""
if (!data.result.length) {
container.innerHTML = "<p>No messages found.</p>"
return
}
data.result.forEach(msg => {
const chat = msg.message
const p = document.createElement("p")
p.innerHTML = `<strong>Chat ID:</strong> ${chat.chat.id} <br>
<strong>Date:</strong> ${new Date(chat.date * 1000).toLocaleString()} <br>
<strong>Name:</strong> ${chat.chat.first_name || 'Unknown'} <br>
<strong>Message:</strong> ${chat.text}`
container.appendChild(p)
})
}).catch(() => {
const p = document.createElement("p")
p.innerHTML = "Error! Check your Token / Chat ID / Network."
document.getElementById("ReceivedMessages").appendChild(p)
})
}
</script>
</head>
<body>
<section class="hero is-white is-fullheight">
<div class="hero-body">
<div class="container">
<h1 class="title text-xl flex items-center gap-3">
<span class="bg-yellow-200 p-2 rounded-md">
<span class="iconify" data-icon="logos:javascript" data-width="32"></span>
</span>
JsReply
</h1>
<p class="subtitle is-size-6-mobile mb-5">Send messages via Telegram Bot</p>
<div class="columns is-variable is-6">
<div class="column is-one-third">
<div class="field">
<label class="label">Token</label>
<div class="control has-icons-left">
<input class="input Viga" type="text" id="bot_token" placeholder="Your bot token" />
<span class="icon is-left">
<span class="iconify" data-icon="mdi:key-variant"></span>
</span>
</div>
</div>
<div class="field">
<label class="label">Chat ID</label>
<div class="control has-icons-left">
<input class="input Viga" type="text" id="bot_chat_id" placeholder="Telegram chat ID" />
<span class="icon is-left">
<span class="iconify" data-icon="ic:baseline-chat"></span>
</span>
</div>
</div>
<div class="field">
<label class="label">Message</label>
<div class="control">
<textarea class="textarea Viga" id="bot_message" placeholder="Your message here..."></textarea>
</div>
</div>
<div class="buttons">
<button class="button is-success is-fullwidth" onclick="send();">
<span class="iconify" data-icon="mdi:telegram"></span> Send Message
</button>
<button class="button is-link is-fullwidth" onclick="viewReceived();">
<span class="iconify" data-icon="carbon:view"></span> View Received
</button>
</div>
</div>
<div class="column">
<label class="label">Received Messages</label>
<article class="message">
<div class="message-body" id="ReceivedMessages">
<p>Enter bot token and click "View Received" to load messages.</p>
</div>
</article>
</div>
</div>
</div>
</div>
</section>
</body>
</html>