| | <!DOCTYPE html> |
| | <html lang="en"> |
| | <head> |
| | <meta charset="UTF-8"> |
| | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| | <title>Send Poll to Group</title> |
| | <style> |
| | body { |
| | font-family: Arial, sans-serif; |
| | text-align: center; |
| | background-color: #f0f0f0; |
| | margin: 0; |
| | padding: 0; |
| | } |
| | h1 { |
| | background-color: #4CAF50; |
| | color: white; |
| | padding: 20px; |
| | margin: 0; |
| | border-bottom: 2px solid #388E3C; |
| | } |
| | .input-row { |
| | display: flex; |
| | justify-content: center; |
| | gap: 10px; |
| | margin-top: 20px; |
| | } |
| | .input-row input, .input-row textarea { |
| | padding: 10px; |
| | font-size: 16px; |
| | border: 1px solid #ccc; |
| | border-radius: 5px; |
| | } |
| | #messageInput { |
| | width: 80%; |
| | margin-top: 20px; |
| | min-height: 100px; |
| | } |
| | #sendButton { |
| | color: white; |
| | background-color: #4CAF50; |
| | border: none; |
| | cursor: pointer; |
| | padding: 10px 20px; |
| | font-size: 16px; |
| | border-radius: 5px; |
| | margin-top: 20px; |
| | } |
| | #sendButton:hover { |
| | background-color: #388E3C; |
| | } |
| | </style> |
| | </head> |
| | <body> |
| | <h1>Отправка опроса в закрытую группу</h1> |
| | <div class="input-row"> |
| | <input type="text" id="apiKeyInput" placeholder="Введите API ключ"> |
| | <input type="text" id="groupIdInput" placeholder="Введите ID группы"> |
| | </div> |
| | <textarea id="messageInput" placeholder="Введите текст вопроса"></textarea> |
| | <div class="input-row"> |
| | <input type="text" id="option1Input" placeholder="Вариант ответа 1"> |
| | <input type="text" id="option2Input" placeholder="Вариант ответа 2"> |
| | <input type="text" id="option3Input" placeholder="Вариант ответа 3"> |
| | <input type="text" id="option4Input" placeholder="Вариант ответа 4"> |
| | </div> |
| | <button id="sendButton">Отправить опрос</button> |
| |
|
| | <script> |
| | document.getElementById('sendButton').addEventListener('click', function() { |
| | const apiKey = document.getElementById('apiKeyInput').value; |
| | const groupId = document.getElementById('groupIdInput').value; |
| | const message = document.getElementById('messageInput').value; |
| | const option1 = document.getElementById('option1Input').value; |
| | const option2 = document.getElementById('option2Input').value; |
| | const option3 = document.getElementById('option3Input').value; |
| | const option4 = document.getElementById('option4Input').value; |
| | if (!apiKey) { |
| | alert('Please enter your API key.'); |
| | return; |
| | } |
| | if (!groupId) { |
| | alert('Please enter the group ID.'); |
| | return; |
| | } |
| | if (!message) { |
| | alert('Please enter a message.'); |
| | return; |
| | } |
| | if (!option1 || !option2 || !option3 || !option4) { |
| | alert('Please fill all options.'); |
| | return; |
| | } |
| | sendPoll(apiKey, groupId, message, [option1, option2, option3, option4]); |
| | }); |
| | async function sendPoll(apiKey, groupId, message, options) { |
| | try { |
| | const response = await fetch(`https://api.green-api.com/waInstance1101952913/sendPoll/${apiKey}`, { |
| | method: 'POST', |
| | headers: { |
| | 'Content-Type': 'application/json' |
| | }, |
| | body: JSON.stringify({ |
| | chatId: `${groupId}`, |
| | message: message, |
| | options: options.map(option => ({ optionName: option })) |
| | }) |
| | }); |
| | if (!response.ok) { |
| | throw new Error(`HTTP error! status: ${response.status}`); |
| | } |
| | const data = await response.json(); |
| | console.log('Poll sent successfully:', data); |
| | alert('Опрос успешно добавлен в группу!'); |
| | } catch (error) { |
| | console.error('Error sending poll:', error); |
| | alert('Ошибка при отправке опроса. Пожалуйста, проверьте консоль для деталей.'); |
| | } |
| | } |
| | </script> |
| | </body> |
| | </html> |