From b5f02668e04408c52a1569476ff19be932c4f51e Mon Sep 17 00:00:00 2001 From: MaxNadeev Date: Tue, 26 Mar 2024 21:53:56 +0300 Subject: [PATCH] function sendTelegram added 1 function sendTelegram added file_get_contents 14 file_get_contents 13 file_get_contents 12 file_get_contents 11 file_get_contents 11 file_get_contents 10 file_get_contents 9 file_get_contents 8 file_get_contents 7 file_get_contents 6 file_get_contents 5 file_get_contents 4 file_get_contents 3 file_get_contents 2 file_get_contents 1 file_get_contents string concatination function send to telegram new token message in function 1 message in function added consts tests 454647 45 consts file init consts file init ver stable 1.0 telegram bot api strings telegram bot in php test with argv cgi use init disabled email send for tests line 57 forgottenn comma bot.py bot connected curl global url curl result curl error show relative link in curl function sending with cURL python script listens post message --- .gitignore | 5 +-- index.html | 19 +---------- scripts/script.js | 32 +++--------------- mail.php => sender - Copy.php | 19 +++++++++++ sender.php | 62 +++++++++++++++++++++++++++++++++++ 5 files changed, 87 insertions(+), 50 deletions(-) rename mail.php => sender - Copy.php (69%) create mode 100644 sender.php diff --git a/.gitignore b/.gitignore index 30b6453..e06fe89 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ sochisto.zip -.env -/node_modules /.vscode -package-lock.json -package.json \ No newline at end of file +consts.txt \ No newline at end of file diff --git a/index.html b/index.html index e91bb27..80cd8b2 100644 --- a/index.html +++ b/index.html @@ -6,7 +6,7 @@ - + Сочисто! | Уборка квартир в Сочи @@ -87,22 +87,7 @@

Оставьте заявку

Вы сможете узнать всю необходимую информацию и забронировать время уборки.

- - - -
- - - - - - - -
@@ -112,8 +97,6 @@

Оставьте заявку

- -
diff --git a/scripts/script.js b/scripts/script.js index 1e85cce..2e9ac23 100644 --- a/scripts/script.js +++ b/scripts/script.js @@ -53,31 +53,24 @@ document.querySelectorAll('.clientForm').forEach( (e) => { const phone = document.getElementById('phone').value; if (name.trim() === '') { - //Please fill out NAME! document.getElementById('name').style.border = '2px solid red' return; } if (phone.trim() === '') { - //Please fill out PHONE! document.getElementById('phone').style.border = '2px solid red' return; } else { - const dataToSend = { name: name, phone: phone } - sendEmail(dataToSend) - // sendDataToNode(dataToSend); - - + send(dataToSend) }; }) }) document.getElementById('again').addEventListener('click', function() { - console.log('again click'); document.getElementById('name').disabled = false; document.getElementById('phone').disabled = false; document.getElementById('hide-after-success').style.display = 'block'; @@ -95,8 +88,8 @@ function showSuccess(){ document.getElementById('success').style.display = 'block'; } -function sendEmail(dataToSend){ - const mailPath = '../mail.php' +function send(dataToSend){ + const mailPath = '../sender.php' let request = new XMLHttpRequest(); var params = JSON.stringify(dataToSend); @@ -108,21 +101,4 @@ function sendEmail(dataToSend){ showSuccess(); } } -} - -// function sendDataToNode(data) { -// // fetch('https://sochisto-bot-lizatravel.amvera.io:80/sendData', { -// fetch('95.26.169.129:80/sendData', { -// method: 'POST', -// headers: { -// 'Content-Type': 'application/json' -// }, -// body: JSON.stringify(data) -// }) -// .then(response => { -// console.log('Data sent to Node.js'); -// }) -// .catch(error => { -// console.error('Error sending data:', error); -// }); -// }; +} \ No newline at end of file diff --git a/mail.php b/sender - Copy.php similarity index 69% rename from mail.php rename to sender - Copy.php index f5d569d..43031ad 100644 --- a/mail.php +++ b/sender - Copy.php @@ -39,4 +39,23 @@ } else { echo "Что-то пошло не так при отправке письма 🙁"; } + +$consts = file('consts.txt'); + +$apiToken = $consts[0]; +$owner = $consts[1]; +$dev = $consts[2]; + +function sendToTelegram($apiToken, $chat_id, $message){ + $data = [ + 'chat_id' => $chat_id, + 'text' => $message, + 'parse_mode' => 'HTML' + ]; + $response = file_get_contents("https://api.telegram.org/bot$apiToken/sendMessage?".http_build_query($data)); +}; + +sendToTelegram($apiToken, $owner, $message); +sendToTelegram($apiToken, $dev, $message); + ?> \ No newline at end of file diff --git a/sender.php b/sender.php new file mode 100644 index 0000000..76c1d7c --- /dev/null +++ b/sender.php @@ -0,0 +1,62 @@ + $chat_id, + 'text' => $message, + 'parse_mode' => 'HTML' + ]; + $response = file_get_contents("https://api.telegram.org/bot$apiToken/sendMessage?".http_build_query($data)); +}; + +sendTelegram($owner, $message, $apiToken); +sendTelegram($dev, $message, $apiToken); + +?> \ No newline at end of file