notif_report #3

Merged
jonas merged 18 commits from notif_report into main 2025-10-06 12:50:41 +00:00
Showing only changes of commit 87668e6dc0 - Show all commits

View File

@@ -71,26 +71,31 @@ event_dispatcher = EventDispatcher()
# Load config at startup # Load config at startup
async def push_listener(customer, reservation, hotel, push): async def push_listener(customer: DBCustomer, reservation: DBReservation, hotel):
push_endpoint = hotel.get("push_endpoint")
server: AlpineBitsServer = app.state.alpine_bits_server server: AlpineBitsServer = app.state.alpine_bits_server
hotel_id = hotel['hotel_id'] hotel_id = hotel['hotel_id']
reservation_hotel_id = reservation.hotel_code
headers = {"Authorization": f"Bearer {push.get('token','')}"} if push.get('token') else {}
action = "OTA_HotelResNotifRQ"
# request = server.handle_request(
# action,)
headers = {"Authorization": f"Bearer {push_endpoint.get('token','')}"} if push_endpoint.get('token') else {}
try: try:
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
resp = await client.post(push["url"], json=payload, headers=headers, timeout=10) resp = await client.post(push_endpoint["url"], json=payload, headers=headers, timeout=10)
_LOGGER.info(f"Push event fired to {push['url']} for hotel {hotel['hotel_id']}, status: {resp.status_code}") _LOGGER.info(f"Push event fired to {push_endpoint['url']} for hotel {hotel['hotel_id']}, status: {resp.status_code}")
except Exception as e: except Exception as e:
_LOGGER.error(f"Push event failed for hotel {hotel['hotel_id']}: {e}") _LOGGER.error(f"Push event failed for hotel {hotel['hotel_id']}: {e}")
@@ -114,12 +119,13 @@ async def lifespan(app: FastAPI):
app.state.alpine_bits_server = AlpineBitsServer(config) app.state.alpine_bits_server = AlpineBitsServer(config)
app.state.event_dispatcher = event_dispatcher app.state.event_dispatcher = event_dispatcher
# Register push listeners for hotels with push_endpoint # Register push listeners for hotels with push_endpoint
for hotel in config.get("alpine_bits_auth", []): for hotel in config.get("alpine_bits_auth", []):
push = hotel.get("push_endpoint") push_endpoint = hotel.get("push_endpoint")
if push: if push_endpoint:
event_dispatcher.register("form_processed", partial(push_listener, hotel=hotel, push=push)) event_dispatcher.register("form_processed", partial(push_listener, hotel=hotel))
# Create tables # Create tables
async with engine.begin() as conn: async with engine.begin() as conn: