|
@@ -29,6 +29,7 @@ class AirbnbMessage:
|
|
|
body: str | None # None for non-text messages (photos, system events, etc.)
|
|
body: str | None # None for non-text messages (photos, system events, etc.)
|
|
|
body_translated: str | None # Airbnb AI translation; None when not provided
|
|
body_translated: str | None # Airbnb AI translation; None when not provided
|
|
|
sender_account_id: str
|
|
sender_account_id: str
|
|
|
|
|
+ sender_name: str | None = None # resolved from thread participants; None only if resolution failed
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
@dataclass
|
|
@@ -439,20 +440,25 @@ class _AirbnbClient:
|
|
|
},
|
|
},
|
|
|
f'https://www.airbnb.com/messages/{thread_id}',
|
|
f'https://www.airbnb.com/messages/{thread_id}',
|
|
|
)
|
|
)
|
|
|
- raw_messages = (
|
|
|
|
|
- resp.get('data', {}).get('threadData', {})
|
|
|
|
|
- .get('messageData', {}).get('messages', [])
|
|
|
|
|
- )
|
|
|
|
|
- messages = [
|
|
|
|
|
- AirbnbMessage(
|
|
|
|
|
|
|
+ thread_data = resp.get('data', {}).get('threadData', {})
|
|
|
|
|
+ participants: dict[str, str] = {}
|
|
|
|
|
+ for edge in thread_data.get('participants', {}).get('edges', []):
|
|
|
|
|
+ node = edge.get('node', {})
|
|
|
|
|
+ account_id = node.get('accountId', '')
|
|
|
|
|
+ name = (node.get('enrichedParticipantInfo') or {}).get('name', '')
|
|
|
|
|
+ if account_id and name:
|
|
|
|
|
+ participants[account_id] = name
|
|
|
|
|
+ messages = []
|
|
|
|
|
+ for m in thread_data.get('messageData', {}).get('messages', []):
|
|
|
|
|
+ aid = (m.get('account') or {}).get('accountId', '')
|
|
|
|
|
+ messages.append(AirbnbMessage(
|
|
|
id=m['id'],
|
|
id=m['id'],
|
|
|
created_at_ms=m['createdAtMs'],
|
|
created_at_ms=m['createdAtMs'],
|
|
|
body=(((m.get('hydratedContent') or {}).get('content') or {}).get('body')),
|
|
body=(((m.get('hydratedContent') or {}).get('content') or {}).get('body')),
|
|
|
body_translated=(((m.get('hydratedContent') or {}).get('content') or {}).get('bodyTranslated')),
|
|
body_translated=(((m.get('hydratedContent') or {}).get('content') or {}).get('bodyTranslated')),
|
|
|
- sender_account_id=(m.get('account') or {}).get('accountId', ''),
|
|
|
|
|
- )
|
|
|
|
|
- for m in raw_messages
|
|
|
|
|
- ]
|
|
|
|
|
|
|
+ sender_account_id=aid,
|
|
|
|
|
+ sender_name=participants.get(aid, 'Airbnb'),
|
|
|
|
|
+ ))
|
|
|
return AirbnbThread(thread_id=thread_id, messages=messages)
|
|
return AirbnbThread(thread_id=thread_id, messages=messages)
|
|
|
|
|
|
|
|
async def send_message(self, thread_id: str, body: str) -> None:
|
|
async def send_message(self, thread_id: str, body: str) -> None:
|