import json import db import config def on_order_created(order_id: int): """ Hook triggered asynchronously when a new order is placed. Users can add any notification logic here (e.g. email or telegram). """ print(f"EVENT: Order {order_id} created.") # Fetch order data if needed order = db.execute_query("SELECT * FROM orders WHERE id = %s", (order_id,)) if order: order_data = order[0] # TODO: Add your notification logic here pass def on_order_status_changed(order_id: int, status: str, order_data: dict, send_notification: bool): """ Hook triggered asynchronously when the admin changes the order status. Uses the send_notification flag explicitly. """ print(f"EVENT: Order {order_id} status changed to {status}. Notify user: {send_notification}") if send_notification: # TODO: Add your notification logic here (Email, Telegram, SMS, etc.) # The order_data dictionary contains all the details of the order. user_email = order_data.get('email') first_name = order_data.get('first_name') user_id = order_data.get('user_id') lang = "en" if user_id: user_info = db.execute_query("SELECT preferred_language FROM users WHERE id = %s", (user_id,)) if user_info and user_info[0].get('preferred_language'): lang = user_info[0]['preferred_language'] print(f"--> Preparing notification to {user_email} (User: {first_name}, Lang: {lang})...") import notifications notifications.notify_status_change(user_email, order_id, status, first_name, lang) def on_message_received(order_id: int, user_id: int, message: str): """ Hook triggered when a client sends a message to an order chat. Useful for alerting admins via external systems. """ print(f"EVENT: New message for Order {order_id} from User {user_id}: {message[:20]}...") # TODO: Integration logic (Telegram, Slack, Email to shop owner, etc.) pass