Spaces:
Sleeping
Sleeping
DmitrMakeev
commited on
Commit
•
4b4b235
1
Parent(s):
cadf11c
Update se_mes.html
Browse files- se_mes.html +11 -4
se_mes.html
CHANGED
@@ -34,7 +34,7 @@
|
|
34 |
#messageInput {
|
35 |
width: 80%;
|
36 |
margin-top: 20px;
|
37 |
-
min-height: 100px;
|
38 |
}
|
39 |
#progressBarContainer {
|
40 |
width: 80%;
|
@@ -68,7 +68,7 @@
|
|
68 |
</style>
|
69 |
</head>
|
70 |
<body>
|
71 |
-
<h1>Отправка сообщения(текст)</h1>
|
72 |
<div class="input-row">
|
73 |
<input type="text" id="apiKeyInput" placeholder="Введите API ключ">
|
74 |
<input type="number" id="minDelayInput" placeholder="Min Delay (ms)" value="500">
|
@@ -110,27 +110,31 @@
|
|
110 |
|
111 |
const fileInput = document.getElementById('fileInput');
|
112 |
const file = fileInput.files[0];
|
|
|
113 |
if (!file) {
|
114 |
alert('Please select a file.');
|
115 |
return;
|
116 |
}
|
117 |
|
118 |
const reader = new FileReader();
|
|
|
119 |
reader.onload = function(event) {
|
120 |
const text = event.target.result;
|
121 |
const phones = text.split('\n').map(phone => phone.trim()).filter(phone => phone);
|
|
|
122 |
sendMessages(phones, apiKey, message, minDelay, maxDelay, linkPreview);
|
123 |
};
|
|
|
124 |
reader.readAsText(file);
|
125 |
});
|
126 |
|
127 |
async function sendMessages(phones, apiKey, message, minDelay, maxDelay, linkPreview) {
|
128 |
const totalPhones = phones.length;
|
129 |
const progressBar = document.getElementById('progress');
|
130 |
-
const progressText = document.getElementById('progress').textContent;
|
131 |
|
132 |
for (let i = 0; i < totalPhones; i++) {
|
133 |
const phone = phones[i];
|
|
|
134 |
try {
|
135 |
const response = await fetch(`https://api.green-api.com/waInstance1101952913/sendMessage/${apiKey}`, {
|
136 |
method: 'POST',
|
@@ -143,11 +147,14 @@
|
|
143 |
linkPreview: linkPreview
|
144 |
})
|
145 |
});
|
|
|
146 |
if (!response.ok) {
|
147 |
throw new Error(`HTTP error! status: ${response.status}`);
|
148 |
}
|
|
|
149 |
const data = await response.json();
|
150 |
console.log(`Message sent to ${phone}:`, data);
|
|
|
151 |
} catch (error) {
|
152 |
console.error(`Error sending message to ${phone}:`, error);
|
153 |
}
|
@@ -164,4 +171,4 @@
|
|
164 |
}
|
165 |
</script>
|
166 |
</body>
|
167 |
-
</html>
|
|
|
34 |
#messageInput {
|
35 |
width: 80%;
|
36 |
margin-top: 20px;
|
37 |
+
min-height: 100px;
|
38 |
}
|
39 |
#progressBarContainer {
|
40 |
width: 80%;
|
|
|
68 |
</style>
|
69 |
</head>
|
70 |
<body>
|
71 |
+
<h1>Отправка сообщения (текст)</h1>
|
72 |
<div class="input-row">
|
73 |
<input type="text" id="apiKeyInput" placeholder="Введите API ключ">
|
74 |
<input type="number" id="minDelayInput" placeholder="Min Delay (ms)" value="500">
|
|
|
110 |
|
111 |
const fileInput = document.getElementById('fileInput');
|
112 |
const file = fileInput.files[0];
|
113 |
+
|
114 |
if (!file) {
|
115 |
alert('Please select a file.');
|
116 |
return;
|
117 |
}
|
118 |
|
119 |
const reader = new FileReader();
|
120 |
+
|
121 |
reader.onload = function(event) {
|
122 |
const text = event.target.result;
|
123 |
const phones = text.split('\n').map(phone => phone.trim()).filter(phone => phone);
|
124 |
+
|
125 |
sendMessages(phones, apiKey, message, minDelay, maxDelay, linkPreview);
|
126 |
};
|
127 |
+
|
128 |
reader.readAsText(file);
|
129 |
});
|
130 |
|
131 |
async function sendMessages(phones, apiKey, message, minDelay, maxDelay, linkPreview) {
|
132 |
const totalPhones = phones.length;
|
133 |
const progressBar = document.getElementById('progress');
|
|
|
134 |
|
135 |
for (let i = 0; i < totalPhones; i++) {
|
136 |
const phone = phones[i];
|
137 |
+
|
138 |
try {
|
139 |
const response = await fetch(`https://api.green-api.com/waInstance1101952913/sendMessage/${apiKey}`, {
|
140 |
method: 'POST',
|
|
|
147 |
linkPreview: linkPreview
|
148 |
})
|
149 |
});
|
150 |
+
|
151 |
if (!response.ok) {
|
152 |
throw new Error(`HTTP error! status: ${response.status}`);
|
153 |
}
|
154 |
+
|
155 |
const data = await response.json();
|
156 |
console.log(`Message sent to ${phone}:`, data);
|
157 |
+
|
158 |
} catch (error) {
|
159 |
console.error(`Error sending message to ${phone}:`, error);
|
160 |
}
|
|
|
171 |
}
|
172 |
</script>
|
173 |
</body>
|
174 |
+
</html>
|