Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -113,50 +113,23 @@ app.config['DEBUG'] = True
|
|
| 113 |
API_TOKEN = '7766407698:AAGZHEbUuiOri4_YzZ7hDPSD6U8MGMXXSnA'
|
| 114 |
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
async def start(message: types.Message):
|
| 134 |
-
await message.answer("Welcome to the bot!")
|
| 135 |
-
|
| 136 |
-
# Регистрируем обработчик команд
|
| 137 |
-
dp.message.register(start, commands=['start'])
|
| 138 |
-
|
| 139 |
-
# Обработчик входящих сообщений через вебхук
|
| 140 |
-
async def on_start(request):
|
| 141 |
-
update = await request.json()
|
| 142 |
-
await dp.process_update(types.Update.to_object(update))
|
| 143 |
-
return web.Response()
|
| 144 |
-
|
| 145 |
-
# Устанавливаем вебхук через aiogram
|
| 146 |
-
async def on_startup(app):
|
| 147 |
-
await bot.set_webhook(WEBHOOK_URL)
|
| 148 |
-
|
| 149 |
-
async def on_shutdown(app):
|
| 150 |
-
await bot.delete_webhook()
|
| 151 |
-
|
| 152 |
-
# Настройка вебхуков и запуск Flask-сервера
|
| 153 |
-
@app.route('/webhook', methods=['POST'])
|
| 154 |
-
def webhook():
|
| 155 |
-
loop = asyncio.new_event_loop()
|
| 156 |
-
asyncio.set_event_loop(loop)
|
| 157 |
-
loop.run_until_complete(on_start(request))
|
| 158 |
-
return jsonify({"status": "Webhook received!"})
|
| 159 |
-
|
| 160 |
|
| 161 |
|
| 162 |
|
|
|
|
| 113 |
API_TOKEN = '7766407698:AAGZHEbUuiOri4_YzZ7hDPSD6U8MGMXXSnA'
|
| 114 |
|
| 115 |
|
| 116 |
+
@app.route('/bt_test', methods=['GET', 'POST'])
|
| 117 |
+
def bt_test():
|
| 118 |
+
if request.method == 'POST':
|
| 119 |
+
if 'product_name' in request.form:
|
| 120 |
+
product_name = request.form['product_name']
|
| 121 |
+
send_to_telegram(product_name)
|
| 122 |
+
return redirect(url_for('bt_test'))
|
| 123 |
+
|
| 124 |
+
else:
|
| 125 |
+
return 'No product name provided'
|
| 126 |
+
return render_template('index.html')
|
| 127 |
+
|
| 128 |
+
def send_to_telegram(product_name):
|
| 129 |
+
bot_token = '7766407698:AAGZHEbUuiOri4_YzZ7hDPSD6U8MGMXXSnA'
|
| 130 |
+
chat_id = '1343658673'
|
| 131 |
+
message = f'Новый продукт добавлен: {product_name}'
|
| 132 |
+
requests.get(f'https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={chat_id}&text={message}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
|
| 135 |
|