|
|
@@ -11,7 +11,7 @@ from urllib.parse import parse_qs, urlparse
|
|
|
|
|
|
import httpx
|
|
|
|
|
|
-from ._scripts import refresh_booking_cookies
|
|
|
+from ._scripts import refresh_booking_cookies, trigger_booking_chat_auth
|
|
|
from room_cal._utils import data_home, get_config, read_env
|
|
|
from ._utils import month_bounds, months_in_range
|
|
|
from .credentials import is_stale, mark_stale, set_credentials
|
|
|
@@ -601,20 +601,28 @@ class _BookingClient:
|
|
|
if is_stale('booking'):
|
|
|
raise BookingAuthError(f'Booking.com credentials are stale — run: {_AUTH_HINT}')
|
|
|
idempotency = f'{reservation_id}-{int(time.time() * 1000)}'
|
|
|
- await self._msg_gql(
|
|
|
- 'postFreeTextMessage', _POST_FREE_TEXT_MUTATION,
|
|
|
- {'input': {
|
|
|
- 'actor': self._actor(),
|
|
|
- 'conversationReference': {
|
|
|
- 'productId': reservation_id,
|
|
|
- 'productType': 'POST_BOOKING',
|
|
|
- 'verticalType': 'ACCOMMODATION',
|
|
|
- },
|
|
|
- 'idempotency': idempotency,
|
|
|
- 'content': body,
|
|
|
- 'attachmentIds': [],
|
|
|
- }},
|
|
|
- )
|
|
|
+ payload = {'input': {
|
|
|
+ 'actor': self._actor(),
|
|
|
+ 'conversationReference': {
|
|
|
+ 'productId': reservation_id,
|
|
|
+ 'productType': 'POST_BOOKING',
|
|
|
+ 'verticalType': 'ACCOMMODATION',
|
|
|
+ },
|
|
|
+ 'idempotency': idempotency,
|
|
|
+ 'content': body,
|
|
|
+ 'attachmentIds': [],
|
|
|
+ }}
|
|
|
+ try:
|
|
|
+ await self._msg_gql('postFreeTextMessage', _POST_FREE_TEXT_MUTATION, payload)
|
|
|
+ except RuntimeError as e:
|
|
|
+ if 'Internal Server Error' not in str(e):
|
|
|
+ raise
|
|
|
+ # GraphQL ISE on send typically means the messaging 2FA session has expired.
|
|
|
+ # Re-trigger the SMS challenge and retry once.
|
|
|
+ _log.warning('Booking.com send_message failed with ISE — re-triggering 2FA')
|
|
|
+ trigger_booking_chat_auth()
|
|
|
+ self._reload_from_env()
|
|
|
+ await self._msg_gql('postFreeTextMessage', _POST_FREE_TEXT_MUTATION, payload)
|
|
|
|
|
|
async def set_price(self, d: str, price: int, occupancy: int = 2) -> None:
|
|
|
if is_stale('booking'):
|