Spaces:
test-sj-crm
/
Runtime error

DmitrMakeev commited on
Commit
6d79028
1 Parent(s): 54b68ae

Create se_mes_im2.html

Browse files
Files changed (1) hide show
  1. se_mes_im2.html +164 -0
se_mes_im2.html ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 {
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
+ <textarea id="messageInput" placeholder="Введите текст сообщения с картинкой."></textarea>
77
+ <div id="progressBarContainer">
78
+ <div id="progressBar">
79
+ <div id="progress">0%</div>
80
+ </div>
81
+ </div>
82
+ <input type="file" id="fileInput" accept=".txt">
83
+ <button id="sendButton">Запустить рассылку</button>
84
+
85
+ <script>
86
+ document.getElementById('sendButton').addEventListener('click', function() {
87
+ const apiKey = document.getElementById('apiKeyInput').value;
88
+ const urlFile = localStorage.getItem('fileUrl');
89
+ const fileName = localStorage.getItem('filename');
90
+ const message = document.getElementById('messageInput').value;
91
+ const minDelay = parseInt(document.getElementById('minDelayInput').value) || 500;
92
+ const maxDelay = parseInt(document.getElementById('maxDelayInput').value) || 10000;
93
+ if (!apiKey) {
94
+ alert('Please enter your API key.');
95
+ return;
96
+ }
97
+ if (!urlFile) {
98
+ alert('URL of the file is not found in local storage.');
99
+ return;
100
+ }
101
+ if (!fileName) {
102
+ alert('File name is not found in local storage.');
103
+ return;
104
+ }
105
+ if (!message) {
106
+ alert('Please enter a message.');
107
+ return;
108
+ }
109
+ if (minDelay >= maxDelay) {
110
+ alert('Min delay must be less than max delay.');
111
+ return;
112
+ }
113
+ const fileInput = document.getElementById('fileInput');
114
+ const file = fileInput.files[0];
115
+ if (!file) {
116
+ alert('Please select a file.');
117
+ return;
118
+ }
119
+ const reader = new FileReader();
120
+ reader.onload = function(event) {
121
+ const text = event.target.result;
122
+ const phones = text.split('\n').map(phone => phone.trim()).filter(phone => phone);
123
+ sendMessages(phones, apiKey, urlFile, fileName, message, minDelay, maxDelay);
124
+ };
125
+ reader.readAsText(file);
126
+ });
127
+ async function sendMessages(phones, apiKey, urlFile, fileName, message, minDelay, maxDelay) {
128
+ const totalPhones = phones.length;
129
+ const progressBar = document.getElementById('progress');
130
+ for (let i = 0; i < totalPhones; i++) {
131
+ const phone = phones[i];
132
+ try {
133
+ const response = await fetch(`https://api.green-api.com/waInstance1101952913/sendFileByUrl/${apiKey}`, {
134
+ method: 'POST',
135
+ headers: {
136
+ 'Content-Type': 'application/json'
137
+ },
138
+ body: JSON.stringify({
139
+ chatId: `${phone}@c.us`,
140
+ urlFile: urlFile,
141
+ fileName: fileName,
142
+ caption: message
143
+ })
144
+ });
145
+ if (!response.ok) {
146
+ throw new Error(`HTTP error! status: ${response.status}`);
147
+ }
148
+ const data = await response.json();
149
+ console.log(`Message sent to ${phone}:`, data);
150
+ } catch (error) {
151
+ console.error(`Error sending message to ${phone}:`, error);
152
+ }
153
+ const progress = ((i + 1) / totalPhones) * 100;
154
+ progressBar.style.width = `${progress}%`;
155
+ progressBar.textContent = `${progress.toFixed(2)}%`;
156
+ if (i < totalPhones - 1) {
157
+ const randomDelay = Math.floor(Math.random() * (maxDelay - minDelay + 1)) + minDelay;
158
+ await new Promise(resolve => setTimeout(resolve, randomDelay));
159
+ }
160
+ }
161
+ }
162
+ </script>
163
+ </body>
164
+ </html>