Update app.py
Browse files
app.py
CHANGED
@@ -12,6 +12,7 @@ from api_logic import api
|
|
12 |
import requests
|
13 |
|
14 |
|
|
|
15 |
|
16 |
load_dotenv()
|
17 |
|
@@ -101,13 +102,20 @@ app.config['DEBUG'] = True
|
|
101 |
TELEGRAM_BOT_TOKEN = "7766407698:AAGZHEbUuiOri4_YzZ7hDPSD6U8MGMXXSnA"
|
102 |
|
103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
def send_message(chat_id, text):
|
105 |
"""Отправка текстового сообщения в Telegram."""
|
106 |
url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
|
107 |
data = {"chat_id": chat_id, "text": text}
|
108 |
response = requests.post(url, data=data)
|
109 |
-
print(f"Ответ Telegram: {response.json()}") #
|
110 |
-
|
111 |
|
112 |
@app.route("/", methods=["POST"])
|
113 |
def process():
|
@@ -134,7 +142,6 @@ def process():
|
|
134 |
|
135 |
|
136 |
|
137 |
-
|
138 |
# Функция сохранения в базу пользователей TG
|
139 |
def save_user(chat_id, db_name="your_database.db"):
|
140 |
conn = sqlite3.connect(db_name)
|
|
|
12 |
import requests
|
13 |
|
14 |
|
15 |
+
from pyngrok import ngrok
|
16 |
|
17 |
load_dotenv()
|
18 |
|
|
|
102 |
TELEGRAM_BOT_TOKEN = "7766407698:AAGZHEbUuiOri4_YzZ7hDPSD6U8MGMXXSnA"
|
103 |
|
104 |
|
105 |
+
# Запускаем ngrok для порта 7860
|
106 |
+
public_url = ngrok.connect(7860).public_url
|
107 |
+
print(f"Webhook URL: {public_url}")
|
108 |
+
|
109 |
+
# Устанавливаем вебхук
|
110 |
+
webhook_url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/setWebhook"
|
111 |
+
requests.post(webhook_url, data={"url": public_url})
|
112 |
+
|
113 |
def send_message(chat_id, text):
|
114 |
"""Отправка текстового сообщения в Telegram."""
|
115 |
url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
|
116 |
data = {"chat_id": chat_id, "text": text}
|
117 |
response = requests.post(url, data=data)
|
118 |
+
print(f"Ответ Telegram: {response.json()}") # Лог
|
|
|
119 |
|
120 |
@app.route("/", methods=["POST"])
|
121 |
def process():
|
|
|
142 |
|
143 |
|
144 |
|
|
|
145 |
# Функция сохранения в базу пользователей TG
|
146 |
def save_user(chat_id, db_name="your_database.db"):
|
147 |
conn = sqlite3.connect(db_name)
|