from flask import Flask, request
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///orders.db'
db = SQLAlchemy(app)
class Order(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80), nullable=False)
phone = db.Column(db.String(20), nullable=False)
address = db.Column(db.String(120), nullable=False)
items = db.Column(db.String(200), nullable=False)
comment = db.Column(db.String(200))
status = db.Column(db.String(20), nullable=False, default='Новый')
@app.route('/order', methods=['POST'])
def create_order():
name = request.form['name']
phone = request.form['phone']
address = request.form['address']
items = request.form['items']
comment = request.form.get('comment', '')
order = Order(name=name, phone=phone, address=address, items=items, comment=comment)
db.session.add(order)
db.session.commit()
return 'Order successfully created!'
import telegram
bot = telegram.Bot('YOUR_API_KEY')
def send_message(chat_id, text):
bot.send_message(chat_id=chat_id, text=text)
# Отправка сообщения о статусе заказа
send_message('YOUR_CHAT_ID', 'Ваш заказ готовится к доставке')
import telegram
bot = telegram.Bot('YOUR_API_KEY')
def send_message(chat_id, text):
bot.send_message(chat_id=chat_id, text=text)
def update_order_status(order_id, status):
order = Order.query.filter_by(id=order_id).first()
order.status = status
db.session.commit()
send_message(order.chat_id, f'Статус вашего заказа: {status}')
# Обработка изменения статуса заказа
update_order_status(1, 'В доставке')
import telegram
bot = telegram.Bot('YOUR_API_KEY')
def get_chat_id():
updates = bot.getUpdates()
chat_ids = set()
for update in updates:
chat_ids.add(update.message.chat_id)
return chat_ids
import telegram
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
bot = telegram.Bot('YOUR_API_KEY')
def send_message_with_buttons(chat_id, text, buttons):
keyboard = [[InlineKeyboardButton(button_label, callback_data=button_callback)] for button_label, button_callback in buttons]
reply_markup = InlineKeyboardMarkup(keyboard)
bot.send_message(chat_id=chat_id, text=text, reply_markup=reply_markup)
# Отправка сообщения с кнопками
send_message_with_buttons('YOUR_CHAT_ID', 'Выберите статус заказа:', [('Заказ подтвержден', 'confirmed'), ('Заказ отправлен на доставку', 'shipped'), ('Заказ доставлен', 'delivered')])
import telegram
from telegram.ext import CallbackQueryHandler
bot = telegram.Bot('YOUR_API_KEY')
def update_order_status_and_send_message(chat_id, order_id, status):
order = Order.query.filter_by(id=order_id).first()
order.status = status
db.session.commit()
bot.answer_callback_query(callback_query_id=chat_id)
bot.send_message(chat_id=chat_id, text=f'Статус вашего заказа: {status}')
# Обработка нажатия на кнопки
def button_click_handler(update, context):
chat_id = update.callback_query.message.chat_id
order_id = ...
status = ...
update_order_status_and_send_message(chat_id, order_id, status)
dispatcher.add_handler(CallbackQueryHandler(button_click_handler))