event_hooks.py 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. import json
  2. import db
  3. import config
  4. def on_order_created(order_id: int):
  5. """
  6. Hook triggered asynchronously when a new order is placed.
  7. Users can add any notification logic here (e.g. email or telegram).
  8. """
  9. print(f"EVENT: Order {order_id} created.")
  10. # Fetch order data if needed
  11. order = db.execute_query("SELECT * FROM orders WHERE id = %s", (order_id,))
  12. if order:
  13. order_data = order[0]
  14. # TODO: Add your notification logic here
  15. pass
  16. def on_order_status_changed(order_id: int, status: str, order_data: dict, send_notification: bool):
  17. """
  18. Hook triggered asynchronously when the admin changes the order status.
  19. Uses the send_notification flag explicitly.
  20. """
  21. print(f"EVENT: Order {order_id} status changed to {status}. Notify user: {send_notification}")
  22. if send_notification:
  23. # TODO: Add your notification logic here (Email, Telegram, SMS, etc.)
  24. # The order_data dictionary contains all the details of the order.
  25. user_email = order_data.get('email')
  26. first_name = order_data.get('first_name')
  27. print(f"--> Sending notification to {user_email} (User: {first_name})...")
  28. pass