Update app.py
Browse files
app.py
CHANGED
@@ -11,8 +11,7 @@ import globs
|
|
11 |
from api_logic import api
|
12 |
import requests
|
13 |
|
14 |
-
|
15 |
-
from teleflask.messages import TextMessage
|
16 |
|
17 |
load_dotenv()
|
18 |
|
@@ -96,43 +95,37 @@ app.config['DEBUG'] = True
|
|
96 |
|
97 |
|
98 |
|
99 |
-
# Токен бота
|
100 |
-
TOKEN = "7766407698:AAGZHEbUuiOri4_YzZ7hDPSD6U8MGMXXSnA"
|
101 |
|
102 |
-
# Инициализация Teleflask
|
103 |
-
app = Teleflask(TOKEN)
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
return TextMessage("Welcome!")
|
133 |
-
# end if
|
134 |
-
# end def
|
135 |
|
|
|
136 |
|
137 |
|
138 |
|
|
|
11 |
from api_logic import api
|
12 |
import requests
|
13 |
|
14 |
+
|
|
|
15 |
|
16 |
load_dotenv()
|
17 |
|
|
|
95 |
|
96 |
|
97 |
|
|
|
|
|
98 |
|
|
|
|
|
99 |
|
100 |
+
# Получаем токен Telegram-бота
|
101 |
+
TELEGRAM_BOT_TOKEN = os.getenv("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('/', methods=["POST"])
|
112 |
+
def process():
|
113 |
+
"""Обрабатывает входящие сообщения от Telegram."""
|
114 |
+
try:
|
115 |
+
data = request.json
|
116 |
+
chat_id = data["message"]["chat"]["id"]
|
117 |
+
text = data["message"]["text"]
|
118 |
+
|
119 |
+
# Ответ на команду /start
|
120 |
+
if text == "/start":
|
121 |
+
send_message(chat_id, "Привет! Я твой бот. Чем могу помочь?")
|
122 |
+
else:
|
123 |
+
send_message(chat_id, f"Вы отправили: {text}")
|
124 |
+
|
125 |
+
except Exception as e:
|
126 |
+
print(f"Ошибка: {e}")
|
|
|
|
|
|
|
127 |
|
128 |
+
return {"ok": True}
|
129 |
|
130 |
|
131 |
|