Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	Create se_mes_ran.html
Browse files- se_mes_ran.html +168 -0
    	
        se_mes_ran.html
    ADDED
    
    | @@ -0,0 +1,168 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 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 Randomization</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 | 
            +
                        min-height: 100px;
         | 
| 38 | 
            +
                    }
         | 
| 39 | 
            +
                    #progressBarContainer {
         | 
| 40 | 
            +
                        width: 80%;
         | 
| 41 | 
            +
                        margin: 20px auto;
         | 
| 42 | 
            +
                    }
         | 
| 43 | 
            +
                    #progressBar {
         | 
| 44 | 
            +
                        width: 100%;
         | 
| 45 | 
            +
                        background-color: #ddd;
         | 
| 46 | 
            +
                    }
         | 
| 47 | 
            +
                    #progress {
         | 
| 48 | 
            +
                        width: 0%;
         | 
| 49 | 
            +
                        height: 30px;
         | 
| 50 | 
            +
                        background-color: #4CAF50;
         | 
| 51 | 
            +
                        text-align: center;
         | 
| 52 | 
            +
                        line-height: 30px;
         | 
| 53 | 
            +
                        color: white;
         | 
| 54 | 
            +
                    }
         | 
| 55 | 
            +
                    #sendButton {
         | 
| 56 | 
            +
                        color: white;
         | 
| 57 | 
            +
                        background-color: #4CAF50;
         | 
| 58 | 
            +
                        border: none;
         | 
| 59 | 
            +
                        cursor: pointer;
         | 
| 60 | 
            +
                        padding: 10px 20px;
         | 
| 61 | 
            +
                        font-size: 16px;
         | 
| 62 | 
            +
                        border-radius: 5px;
         | 
| 63 | 
            +
                        margin-top: 20px;
         | 
| 64 | 
            +
                    }
         | 
| 65 | 
            +
                    #sendButton:hover {
         | 
| 66 | 
            +
                        background-color: #388E3C;
         | 
| 67 | 
            +
                    }
         | 
| 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">
         | 
| 75 | 
            +
                    <input type="number" id="maxDelayInput" placeholder="Max Delay (ms)" value="1000">
         | 
| 76 | 
            +
                    <label>
         | 
| 77 | 
            +
                        Показывать превью:
         | 
| 78 | 
            +
                        <input type="checkbox" id="linkPreviewCheckbox" checked>
         | 
| 79 | 
            +
                    </label>
         | 
| 80 | 
            +
                </div>
         | 
| 81 | 
            +
                <textarea id="messageInput" placeholder="Введите текст сообщения с вариантами в фигурных скобках, например: {Привет|Hello|Hola}!"></textarea>
         | 
| 82 | 
            +
                <div id="progressBarContainer">
         | 
| 83 | 
            +
                    <div id="progressBar">
         | 
| 84 | 
            +
                        <div id="progress">0%</div>
         | 
| 85 | 
            +
                    </div>
         | 
| 86 | 
            +
                </div>
         | 
| 87 | 
            +
                <input type="file" id="fileInput" accept=".txt">
         | 
| 88 | 
            +
                <button id="sendButton">Запустить рассылку</button>
         | 
| 89 | 
            +
             | 
| 90 | 
            +
                <script>
         | 
| 91 | 
            +
                    document.getElementById('sendButton').addEventListener('click', function() {
         | 
| 92 | 
            +
                        const apiKey = document.getElementById('apiKeyInput').value;
         | 
| 93 | 
            +
                        const messageTemplate = document.getElementById('messageInput').value;
         | 
| 94 | 
            +
                        const minDelay = parseInt(document.getElementById('minDelayInput').value) || 500;
         | 
| 95 | 
            +
                        const maxDelay = parseInt(document.getElementById('maxDelayInput').value) || 10000;
         | 
| 96 | 
            +
                        const linkPreview = document.getElementById('linkPreviewCheckbox').checked;
         | 
| 97 | 
            +
                        if (!apiKey) {
         | 
| 98 | 
            +
                            alert('Please enter your API key.');
         | 
| 99 | 
            +
                            return;
         | 
| 100 | 
            +
                        }
         | 
| 101 | 
            +
                        if (!messageTemplate) {
         | 
| 102 | 
            +
                            alert('Please enter a message template.');
         | 
| 103 | 
            +
                            return;
         | 
| 104 | 
            +
                        }
         | 
| 105 | 
            +
                        if (minDelay >= maxDelay) {
         | 
| 106 | 
            +
                            alert('Min delay must be less than max delay.');
         | 
| 107 | 
            +
                            return;
         | 
| 108 | 
            +
                        }
         | 
| 109 | 
            +
                        const fileInput = document.getElementById('fileInput');
         | 
| 110 | 
            +
                        const file = fileInput.files[0];
         | 
| 111 | 
            +
                        if (!file) {
         | 
| 112 | 
            +
                            alert('Please select a file.');
         | 
| 113 | 
            +
                            return;
         | 
| 114 | 
            +
                        }
         | 
| 115 | 
            +
                        const reader = new FileReader();
         | 
| 116 | 
            +
                        reader.onload = function(event) {
         | 
| 117 | 
            +
                            const text = event.target.result;
         | 
| 118 | 
            +
                            const phones = text.split('\n').map(phone => phone.trim()).filter(phone => phone);
         | 
| 119 | 
            +
                            sendMessages(phones, apiKey, messageTemplate, minDelay, maxDelay, linkPreview);
         | 
| 120 | 
            +
                        };
         | 
| 121 | 
            +
                        reader.readAsText(file);
         | 
| 122 | 
            +
                    });
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                    function randomizeMessage(template) {
         | 
| 125 | 
            +
                        return template.replace(/\{([^}]+)\}/g, (match, p1) => {
         | 
| 126 | 
            +
                            const choices = p1.split('|');
         | 
| 127 | 
            +
                            return choices[Math.floor(Math.random() * choices.length)];
         | 
| 128 | 
            +
                        });
         | 
| 129 | 
            +
                    }
         | 
| 130 | 
            +
             | 
| 131 | 
            +
                    async function sendMessages(phones, apiKey, messageTemplate, minDelay, maxDelay, linkPreview) {
         | 
| 132 | 
            +
                        const totalPhones = phones.length;
         | 
| 133 | 
            +
                        const progressBar = document.getElementById('progress');
         | 
| 134 | 
            +
                        for (let i = 0; i < totalPhones; i++) {
         | 
| 135 | 
            +
                            const phone = phones[i];
         | 
| 136 | 
            +
                            const message = randomizeMessage(messageTemplate);
         | 
| 137 | 
            +
                            try {
         | 
| 138 | 
            +
                                const response = await fetch(`https://api.green-api.com/waInstance1101952913/sendMessage/${apiKey}`, {
         | 
| 139 | 
            +
                                    method: 'POST',
         | 
| 140 | 
            +
                                    headers: {
         | 
| 141 | 
            +
                                        'Content-Type': 'application/json'
         | 
| 142 | 
            +
                                    },
         | 
| 143 | 
            +
                                    body: JSON.stringify({
         | 
| 144 | 
            +
                                        chatId: `${phone}@c.us`,
         | 
| 145 | 
            +
                                        message: message,
         | 
| 146 | 
            +
                                        linkPreview: linkPreview
         | 
| 147 | 
            +
                                    })
         | 
| 148 | 
            +
                                });
         | 
| 149 | 
            +
                                if (!response.ok) {
         | 
| 150 | 
            +
                                    throw new Error(`HTTP error! status: ${response.status}`);
         | 
| 151 | 
            +
                                }
         | 
| 152 | 
            +
                                const data = await response.json();
         | 
| 153 | 
            +
                                console.log(`Message sent to ${phone}:`, data);
         | 
| 154 | 
            +
                            } catch (error) {
         | 
| 155 | 
            +
                                console.error(`Error sending message to ${phone}:`, error);
         | 
| 156 | 
            +
                            }
         | 
| 157 | 
            +
                            const progress = ((i + 1) / totalPhones) * 100;
         | 
| 158 | 
            +
                            progressBar.style.width = `${progress}%`;
         | 
| 159 | 
            +
                            progressBar.textContent = `${progress.toFixed(2)}%`;
         | 
| 160 | 
            +
                            if (i < totalPhones - 1) {
         | 
| 161 | 
            +
                                const randomDelay = Math.floor(Math.random() * (maxDelay - minDelay + 1)) + minDelay;
         | 
| 162 | 
            +
                                await new Promise(resolve => setTimeout(resolve, randomDelay));
         | 
| 163 | 
            +
                            }
         | 
| 164 | 
            +
                        }
         | 
| 165 | 
            +
                    }
         | 
| 166 | 
            +
                </script>
         | 
| 167 | 
            +
            </body>
         | 
| 168 | 
            +
            </html>
         |