Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -97,26 +97,31 @@ app.config['DEBUG'] = True
|
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
-
#
|
| 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 |
-
requests.post(url, data=data)
|
|
|
|
| 109 |
|
| 110 |
|
| 111 |
-
@app.route(
|
| 112 |
def process():
|
| 113 |
"""Обрабатывает входящие сообщения от Telegram."""
|
| 114 |
try:
|
| 115 |
-
data = request.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
chat_id = data["message"]["chat"]["id"]
|
| 117 |
-
text = data["message"]
|
| 118 |
|
| 119 |
-
# Ответ на команду /start
|
| 120 |
if text == "/start":
|
| 121 |
send_message(chat_id, "Привет! Я твой бот. Чем могу помочь?")
|
| 122 |
else:
|
|
|
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
+
# 🔹 Вставь сюда свой реальный токен бота
|
| 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():
|
| 114 |
"""Обрабатывает входящие сообщения от Telegram."""
|
| 115 |
try:
|
| 116 |
+
data = request.get_json()
|
| 117 |
+
print(f"Получены данные: {data}") # Лог входящих данных
|
| 118 |
+
|
| 119 |
+
if "message" not in data:
|
| 120 |
+
return {"ok": False, "error": "Нет данных message"}, 400
|
| 121 |
+
|
| 122 |
chat_id = data["message"]["chat"]["id"]
|
| 123 |
+
text = data["message"].get("text", "")
|
| 124 |
|
|
|
|
| 125 |
if text == "/start":
|
| 126 |
send_message(chat_id, "Привет! Я твой бот. Чем могу помочь?")
|
| 127 |
else:
|