diff --git a/.gitignore b/.gitignore index 30b6453..3add536 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ sochisto.zip /node_modules /.vscode package-lock.json -package.json \ No newline at end of file +package.json +bot.js \ No newline at end of file diff --git a/mail.php b/mail.php index f5d569d..e202aa2 100644 --- a/mail.php +++ b/mail.php @@ -39,4 +39,35 @@ } else { echo "Что-то пошло не так при отправке письма 🙁"; } + + +function sendInTelegramBot($data, $url) { + $options = array( + 'http' => array( + 'header' => "Content-type: application/json\r\n", + 'method' => 'POST', + 'content' => json_encode($data) + ) + ); + + $context = stream_context_create($options); + $result = file_get_contents($url, false, $context); + + if ($result === FALSE) { + return "Ошибка отправки запроса"; + } else { + return $result; + } +} + +$data = array( + 'name' => $name, + 'phone' => $phone +); + +$url = '/bot.py'; + +$response = sendInTelegramBot($data, $url); +echo $response; + ?> \ No newline at end of file diff --git a/scripts/bot.py b/scripts/bot.py new file mode 100644 index 0000000..2ac554d --- /dev/null +++ b/scripts/bot.py @@ -0,0 +1,43 @@ +# import os +# import telebot +# from telebot import types +from flask import Flask, request, jsonify + +# API_KEY = os.getenv('TG_TOKEN') +# u = os.getenv("USER_ID") +# bot = telebot.TeleBot(API_KEY, parse_mode=None) +# response = urllib.request.urlopen(url).read() + +# @bot.message_handler(commands=['start']) +# def start(message): +# chatID = message.from_user +# first_name = message.first_name + +# if chatID == u: +# mess = f'Добро пожаловать, {first_name}' +# bot.send_message(u.id, mess, parse_mode='html') + + + +app = Flask(__name__) + +@app.route('/process_json', methods=['POST']) +def process_json(): + data = request.get_json() + name = data.get('name') + phone = data.get('phone') + + # Делаем что-то с полученными данными + # Например, выводим их + print(f'Received data - Name: {name}, Phone: {phone}') + + return jsonify({'message': 'Data received successfully'}) + +if __name__ == '__main__': + app.run(debug=True) + +# while True: +# try: +# bot.polling() +# except Exception: +# time.sleep(9) \ No newline at end of file