import os, requests, time
HS = os.environ["HUBSPOT_ACCESS_TOKEN"]
MV = os.environ["MAVERA_API_KEY"]
# 1. Pull recent meetings
r = requests.post("https://api.hubapi.com/crm/v3/objects/meetings/search",
headers={"Authorization": f"Bearer {HS}"},
json={
"filterGroups": [{"filters": [{"propertyName": "hs_meeting_outcome", "operator": "HAS_PROPERTY"}]}],
"properties": ["hs_meeting_title", "hs_meeting_body", "hs_internal_meeting_notes", "hs_meeting_outcome"],
"sorts": [{"propertyName": "hs_meeting_start_time", "direction": "DESCENDING"}],
"limit": 25,
})
if r.status_code == 429: time.sleep(1)
r.raise_for_status()
meetings = r.json().get("results", [])
# 2. Aggregate notes
notes = []
for m in meetings:
p = m.get("properties", {})
body = p.get("hs_internal_meeting_notes") or p.get("hs_meeting_body") or ""
if body.strip():
notes.append(f"Meeting: {p.get('hs_meeting_title','Untitled')}\nOutcome: {p.get('hs_meeting_outcome','')}\n{body[:500]}")
block = "\n\n---\n\n".join(notes[:20])
# 3. Mave synthesis
mave = requests.post("https://app.mavera.io/api/v1/mave/chat",
headers={"Authorization": f"Bearer {MV}", "Content-Type": "application/json"},
json={"message": f"""Synthesize key themes, objections, competitive mentions, and feature requests
from these {len(notes)} prospect meetings.
For each theme: frequency, representative quotes, strategic recommendation.
Top 3 objections with suggested responses. Competitive products mentioned.
{block}"""}).json()
print("--- Meeting Intelligence ---")
print(mave.get("content", "")[:2000])