Spaces:
Sleeping
Sleeping
DmitrMakeev
commited on
Commit
•
50dcb33
1
Parent(s):
74164ff
Create se_mes_ran.html
Browse files- se_mes_ran.html +175 -0
se_mes_ran.html
ADDED
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Send Messages with Image</title>
|
7 |
+
<style>
|
8 |
+
body {
|
9 |
+
font-family: Arial, sans-serif;
|
10 |
+
text-align: center;
|
11 |
+
background-color: #f0f0f0;
|
12 |
+
margin: 0;
|
13 |
+
padding: 0;
|
14 |
+
}
|
15 |
+
h1 {
|
16 |
+
background-color: #4CAF50;
|
17 |
+
color: white;
|
18 |
+
padding: 20px;
|
19 |
+
margin: 0;
|
20 |
+
border-bottom: 2px solid #388E3C;
|
21 |
+
}
|
22 |
+
.input-row {
|
23 |
+
display: flex;
|
24 |
+
justify-content: center;
|
25 |
+
gap: 10px;
|
26 |
+
margin-top: 20px;
|
27 |
+
}
|
28 |
+
.input-row input, .input-row textarea {
|
29 |
+
padding: 10px;
|
30 |
+
font-size: 16px;
|
31 |
+
border: 1px solid #ccc;
|
32 |
+
border-radius: 5px;
|
33 |
+
}
|
34 |
+
#messageInput, #urlFileInput, #fileNameInput {
|
35 |
+
width: 80%;
|
36 |
+
margin-top: 20px;
|
37 |
+
}
|
38 |
+
#progressBarContainer {
|
39 |
+
width: 80%;
|
40 |
+
margin: 20px auto;
|
41 |
+
}
|
42 |
+
#progressBar {
|
43 |
+
width: 100%;
|
44 |
+
background-color: #ddd;
|
45 |
+
}
|
46 |
+
#progress {
|
47 |
+
width: 0%;
|
48 |
+
height: 30px;
|
49 |
+
background-color: #4CAF50;
|
50 |
+
text-align: center;
|
51 |
+
line-height: 30px;
|
52 |
+
color: white;
|
53 |
+
}
|
54 |
+
#sendButton {
|
55 |
+
color: white;
|
56 |
+
background-color: #4CAF50;
|
57 |
+
border: none;
|
58 |
+
cursor: pointer;
|
59 |
+
padding: 10px 20px;
|
60 |
+
font-size: 16px;
|
61 |
+
border-radius: 5px;
|
62 |
+
margin-top: 20px;
|
63 |
+
}
|
64 |
+
#sendButton:hover {
|
65 |
+
background-color: #388E3C;
|
66 |
+
}
|
67 |
+
</style>
|
68 |
+
</head>
|
69 |
+
<body>
|
70 |
+
<h1>Отправка сообщения с картинкой</h1>
|
71 |
+
<div class="input-row">
|
72 |
+
<input type="text" id="apiKeyInput" placeholder="Введите API ключ">
|
73 |
+
<input type="number" id="minDelayInput" placeholder="Min Delay (ms)" value="500">
|
74 |
+
<input type="number" id="maxDelayInput" placeholder="Max Delay (ms)" value="1000">
|
75 |
+
</div>
|
76 |
+
<input type="text" id="urlFileInput" placeholder="Введите URL файла">
|
77 |
+
<input type="text" id="fileNameInput" placeholder="Введите название файла">
|
78 |
+
<textarea id="messageInput" placeholder="Введите текст сообщения с картинкой."></textarea>
|
79 |
+
<div id="progressBarContainer">
|
80 |
+
<div id="progressBar">
|
81 |
+
<div id="progress">0%</div>
|
82 |
+
</div>
|
83 |
+
</div>
|
84 |
+
<input type="file" id="fileInput" accept=".txt">
|
85 |
+
<button id="sendButton">Запустить рассылку</button>
|
86 |
+
|
87 |
+
<script>
|
88 |
+
document.getElementById('sendButton').addEventListener('click', function() {
|
89 |
+
const apiKey = document.getElementById('apiKeyInput').value;
|
90 |
+
const urlFile = document.getElementById('urlFileInput').value;
|
91 |
+
const fileName = document.getElementById('fileNameInput').value;
|
92 |
+
const messageTemplate = document.getElementById('messageInput').value;
|
93 |
+
const minDelay = parseInt(document.getElementById('minDelayInput').value) || 500;
|
94 |
+
const maxDelay = parseInt(document.getElementById('maxDelayInput').value) || 10000;
|
95 |
+
if (!apiKey) {
|
96 |
+
alert('Please enter your API key.');
|
97 |
+
return;
|
98 |
+
}
|
99 |
+
if (!urlFile) {
|
100 |
+
alert('Please enter the URL of the file.');
|
101 |
+
return;
|
102 |
+
}
|
103 |
+
if (!fileName) {
|
104 |
+
alert('Please enter the file name.');
|
105 |
+
return;
|
106 |
+
}
|
107 |
+
if (!messageTemplate) {
|
108 |
+
alert('Please enter a message template.');
|
109 |
+
return;
|
110 |
+
}
|
111 |
+
if (minDelay >= maxDelay) {
|
112 |
+
alert('Min delay must be less than max delay.');
|
113 |
+
return;
|
114 |
+
}
|
115 |
+
const fileInput = document.getElementById('fileInput');
|
116 |
+
const file = fileInput.files[0];
|
117 |
+
if (!file) {
|
118 |
+
alert('Please select a file.');
|
119 |
+
return;
|
120 |
+
}
|
121 |
+
const reader = new FileReader();
|
122 |
+
reader.onload = function(event) {
|
123 |
+
const text = event.target.result;
|
124 |
+
const phones = text.split('\n').map(phone => phone.trim()).filter(phone => phone);
|
125 |
+
sendMessages(phones, apiKey, urlFile, fileName, messageTemplate, minDelay, maxDelay);
|
126 |
+
};
|
127 |
+
reader.readAsText(file);
|
128 |
+
});
|
129 |
+
|
130 |
+
function randomizeMessage(template) {
|
131 |
+
return template.replace(/\{([^}]+)\}/g, (match, p1) => {
|
132 |
+
const choices = p1.split('|');
|
133 |
+
return choices[Math.floor(Math.random() * choices.length)];
|
134 |
+
});
|
135 |
+
}
|
136 |
+
|
137 |
+
async function sendMessages(phones, apiKey, urlFile, fileName, messageTemplate, minDelay, maxDelay) {
|
138 |
+
const totalPhones = phones.length;
|
139 |
+
const progressBar = document.getElementById('progress');
|
140 |
+
for (let i = 0; i < totalPhones; i++) {
|
141 |
+
const phone = phones[i];
|
142 |
+
const message = randomizeMessage(messageTemplate);
|
143 |
+
try {
|
144 |
+
const response = await fetch(`https://api.green-api.com/waInstance1101952913/sendFileByUrl/${apiKey}`, {
|
145 |
+
method: 'POST',
|
146 |
+
headers: {
|
147 |
+
'Content-Type': 'application/json'
|
148 |
+
},
|
149 |
+
body: JSON.stringify({
|
150 |
+
chatId: `${phone}@c.us`,
|
151 |
+
urlFile: urlFile,
|
152 |
+
fileName: fileName,
|
153 |
+
caption: message
|
154 |
+
})
|
155 |
+
});
|
156 |
+
if (!response.ok) {
|
157 |
+
throw new Error(`HTTP error! status: ${response.status}`);
|
158 |
+
}
|
159 |
+
const data = await response.json();
|
160 |
+
console.log(`Message sent to ${phone}:`, data);
|
161 |
+
} catch (error) {
|
162 |
+
console.error(`Error sending message to ${phone}:`, error);
|
163 |
+
}
|
164 |
+
const progress = ((i + 1) / totalPhones) * 100;
|
165 |
+
progressBar.style.width = `${progress}%`;
|
166 |
+
progressBar.textContent = `${progress.toFixed(2)}%`;
|
167 |
+
if (i < totalPhones - 1) {
|
168 |
+
const randomDelay = Math.floor(Math.random() * (maxDelay - minDelay + 1)) + minDelay;
|
169 |
+
await new Promise(resolve => setTimeout(resolve, randomDelay));
|
170 |
+
}
|
171 |
+
}
|
172 |
+
}
|
173 |
+
</script>
|
174 |
+
</body>
|
175 |
+
</html>
|