import os, requests
SF = os.environ["SALESFORCE_INSTANCE"]
SF_T = os.environ["SALESFORCE_ACCESS_TOKEN"]
MV_K = os.environ["MAVERA_API_KEY"]
SF_H = {"Authorization": f"Bearer {SF_T}"}
MV_H = {"Authorization": f"Bearer {MV_K}", "Content-Type": "application/json"}
TIERS = {"hot": "Rating = 'Hot'", "warm": "Rating = 'Warm'", "cold": "Rating = 'Cold'"}
EMAIL_TEMPLATE = (
"Subject: Quick call this week?\n\n"
"Hi {{Name}}, given your team's growth, I'd love 15 minutes to show "
"how we've helped similar companies cut onboarding time by 40%."
)
persona_ids = []
for tier, where in TIERS.items():
leads = requests.get(
f"https://{SF}/services/data/v66.0/query", headers=SF_H,
params={"q": f"SELECT Name, Title, Company, Industry FROM Lead WHERE {where} LIMIT 20"},
).json()["records"]
titles = [l.get("Title", "Manager") for l in leads]
top = max(set(titles), key=titles.count) if titles else "Manager"
p = requests.post(
"https://app.mavera.io/api/v1/personas", headers=MV_H,
json={
"name": f"{tier.title()} Lead — {top}",
"description": f"'{tier}' scored leads. Typical role: {top}. Based on {len(leads)} leads.",
},
).json()
persona_ids.append(p["id"])
fg = requests.post(
"https://app.mavera.io/api/v1/focus-groups", headers=MV_H,
json={
"persona_ids": persona_ids,
"questions": [
{"type": "nps", "text": "You receive this email. How likely are you to respond (0-10)?"},
{"type": "open_ended", "text": f"Here is the outreach email:\n\n{EMAIL_TEMPLATE}\n\nWould you open, reply, or ignore? Why?"},
{"type": "open_ended", "text": "What would make you more likely to engage with cold outreach?"},
{"type": "open_ended", "text": "Describe the last vendor email you actually replied to. What stood out?"},
],
},
).json()
print(f"Focus Group: {fg['id']}")
for r in fg.get("responses", []):
print(f"\n[{r['persona_name']}] Q: {r['question'][:60]}...")
print(f" A: {r['response']}")