-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.py
More file actions
317 lines (260 loc) · 12.5 KB
/
Copy pathdemo.py
File metadata and controls
317 lines (260 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/usr/bin/env python3
"""
Conversion Engine Demo Script
Demonstrates the full lead conversion pipeline from enrichment to booking.
"""
import asyncio
import json
import time
from datetime import datetime
import httpx
# Your deployed Render URL
BASE_URL = "https://conversion-engine-2nti.onrender.com"
class ConversionEngineDemo:
def __init__(self):
self.client = httpx.AsyncClient(timeout=30.0)
self.prospect_id = None
async def demo_health_check(self):
"""Test 1: Health Check - Verify the system is running"""
print("🏥 DEMO 1: Health Check")
print("=" * 50)
try:
response = await self.client.get(f"{BASE_URL}/health")
health_data = response.json()
print(f"✅ System Status: {health_data['status']}")
print(f"🔒 Kill Switch: {health_data['kill_switch']}")
print(f"🔴 Live Mode: {health_data['live_mode']}")
print(f"🔗 HubSpot: {health_data['hubspot']}")
print(f"⏰ Timestamp: {health_data['timestamp']}")
print()
except Exception as e:
print(f"❌ Health check failed: {e}")
return False
return True
async def demo_enrichment(self):
"""Test 2: Prospect Enrichment - Full signal collection"""
print("🔍 DEMO 2: Prospect Enrichment Pipeline")
print("=" * 50)
# Demo prospect - a fictional AI startup
prospect_data = {
"company_name": "TechFlow AI",
"contact_name": "Sarah Chen",
"contact_email": "sarah@techflow.ai",
"contact_phone": "+1-555-0123",
"contact_title": "CTO"
}
print(f"📋 Enriching prospect: {prospect_data['company_name']}")
print(f"👤 Contact: {prospect_data['contact_name']} ({prospect_data['contact_title']})")
try:
response = await self.client.post(f"{BASE_URL}/prospects/enrich", json=prospect_data)
enrichment_result = response.json()
self.prospect_id = enrichment_result['prospect_id']
print(f"✅ Prospect ID: {self.prospect_id}")
print(f"🎯 Segment: {enrichment_result['segment']}")
print(f"📊 Confidence: {enrichment_result['confidence']:.2f}")
print(f"🤖 AI Maturity Score: {enrichment_result.get('ai_maturity', 'N/A')}")
print(f"📈 Bench Match: {enrichment_result.get('bench_match', 'N/A')}")
print(f"📊 Hiring Velocity: {enrichment_result.get('hiring_velocity', 'N/A')}")
print(f"⚠️ Honesty Flags: {enrichment_result.get('honesty_flags', [])}")
hubspot = enrichment_result.get('hubspot', {})
print(f"🏢 HubSpot Sync: {hubspot.get('status', 'N/A') if isinstance(hubspot, dict) else hubspot}")
print()
except Exception as e:
print(f"❌ Enrichment failed: {e}")
return False
return True
async def demo_outreach(self):
"""Test 3: Automated Outreach - Email composition and sending"""
print("📧 DEMO 3: Automated Outreach")
print("=" * 50)
if not self.prospect_id:
print("❌ No prospect ID available")
return False
try:
response = await self.client.post(f"{BASE_URL}/prospects/{self.prospect_id}/outreach")
if response.status_code == 400:
err = response.json()
print(f"⚠️ State conflict: {err.get('detail', 'unknown')}")
print(" Resetting: creating a fresh prospect for outreach...")
# Create a fresh prospect just for outreach
fresh = await self.client.post(f"{BASE_URL}/prospects/enrich", json={
"company_name": "OutreachTest Corp",
"contact_name": "Alex Demo",
"contact_email": "alex@outreachtest.com",
"contact_title": "VP Engineering",
})
fresh_data = fresh.json()
fresh_id = fresh_data["prospect_id"]
response = await self.client.post(f"{BASE_URL}/prospects/{fresh_id}/outreach")
outreach_result = response.json()
if response.status_code >= 400:
print(f"❌ Outreach error: {outreach_result.get('detail', outreach_result)}")
return False
print(f"✅ Email Status: {outreach_result['status']}")
print(f"📬 Subject: {outreach_result['email_subject']}")
print(f"🎯 Confidence Level: {outreach_result.get('confidence_level', 'N/A')}")
print(f"📊 Signal References: {len(outreach_result.get('signal_references', []))}")
print(f"🔤 Tokens Used: {outreach_result.get('tokens_used', 'N/A')}")
print()
except Exception as e:
print(f"❌ Outreach failed: {e}")
return False
return True
async def demo_conversation(self):
"""Test 4: Conversation Management - Handle prospect reply"""
print("💬 DEMO 4: Conversation Management")
print("=" * 50)
if not self.prospect_id:
print("❌ No prospect ID available")
return False
# Simulate a positive prospect reply
reply_data = {
"prospect_id": self.prospect_id,
"message": "Hi! This sounds interesting. I'd like to learn more about how you can help us with our AI implementation. Can we schedule a call?",
"channel": "email"
}
print(f"📨 Simulating prospect reply: '{reply_data['message'][:50]}...'")
try:
response = await self.client.post(f"{BASE_URL}/prospects/{self.prospect_id}/reply", json=reply_data)
conversation_result = response.json()
if response.status_code >= 400:
print(f"❌ Reply error: {conversation_result.get('detail', conversation_result)}")
return False
print(f"✅ Reply processed successfully")
print(f"🤖 Agent Response: '{conversation_result['reply'][:100]}...'")
print(f"📊 New State: {conversation_result['state']}")
print(f"🏷️ Reply Class: {conversation_result.get('reply_class', 'N/A')}")
print(f"📞 Should Book Call: {conversation_result['should_book_call']}")
print(f"👤 Needs Human Handoff: {conversation_result['needs_human_handoff']}")
print()
except Exception as e:
print(f"❌ Conversation handling failed: {e}")
return False
return True
async def demo_prospect_details(self):
"""Test 5: Prospect Details - View complete prospect profile"""
print("👤 DEMO 5: Prospect Profile")
print("=" * 50)
if not self.prospect_id:
print("❌ No prospect ID available")
return False
try:
response = await self.client.get(f"{BASE_URL}/prospects/{self.prospect_id}")
prospect_details = response.json()
print(f"🆔 ID: {prospect_details['id']}")
print(f"🏢 Company: {prospect_details['company_name']}")
print(f"👤 Contact: {prospect_details['contact_name']} ({prospect_details.get('contact_title', 'N/A')})")
print(f"📧 Email: {prospect_details.get('contact_email', 'N/A')}")
print(f"📱 Phone: {prospect_details.get('contact_phone', 'N/A')}")
print(f"📊 State: {prospect_details['state']}")
print(f"📬 Emails Sent: {prospect_details['emails_sent']}")
print(f"🕒 Last Contact: {prospect_details.get('last_contact', 'N/A')}")
print()
except Exception as e:
print(f"❌ Failed to get prospect details: {e}")
return False
return True
async def demo_webhook_endpoints(self):
"""Test 6: Webhook Endpoints - Verify webhook receivers are working"""
print("🔗 DEMO 6: Webhook Endpoints")
print("=" * 50)
all_ok = True
# Test email webhook
email_webhook_data = {
"type": "email.delivered",
"data": {
"email_id": "test-email-123",
"to": "sarah@techflow.ai",
"subject": "Test Email"
}
}
try:
response = await self.client.post(f"{BASE_URL}/webhooks/email/reply", json=email_webhook_data)
print(f"✅ Email Webhook: {response.status_code} - {response.json()}")
except Exception as e:
print(f"❌ Email webhook test failed: {e}")
all_ok = False
# Test SMS webhook
sms_webhook_data = {
"from": "+1-555-0123",
"text": "Yes, I'm interested in learning more",
"to": "4571"
}
try:
response = await self.client.post(f"{BASE_URL}/webhooks/sms/inbound", json=sms_webhook_data)
print(f"✅ SMS Webhook: {response.status_code} - {response.json()}")
except Exception as e:
print(f"❌ SMS webhook test failed: {e}")
all_ok = False
print()
return all_ok
async def demo_prospects_list(self):
"""Test 7: List All Prospects"""
print("📋 DEMO 7: All Prospects")
print("=" * 50)
try:
response = await self.client.get(f"{BASE_URL}/prospects")
prospects_list = response.json()
print(f"📊 Total Prospects: {len(prospects_list)}")
for prospect in prospects_list:
print(f" 🆔 {prospect['id']} | 🏢 {prospect['company']} | 🎯 {prospect['segment']} | 📊 {prospect['state']} | 📬 {prospect['emails_sent']} emails")
print()
except Exception as e:
print(f"❌ Failed to list prospects: {e}")
return False
return True
async def run_full_demo(self):
"""Run the complete demo sequence"""
print("🚀 CONVERSION ENGINE DEMO")
print("=" * 60)
print(f"🌐 Base URL: {BASE_URL}")
print(f"⏰ Demo Started: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
print("=" * 60)
print()
# Run all demo steps
steps = [
("Health Check", self.demo_health_check),
("Prospect Enrichment", self.demo_enrichment),
("Automated Outreach", self.demo_outreach),
("Webhook Endpoints", self.demo_webhook_endpoints),
("Conversation Management", self.demo_conversation),
("Prospect Profile", self.demo_prospect_details),
("Prospects List", self.demo_prospects_list),
]
results = []
for step_name, step_func in steps:
print(f"⏳ Running: {step_name}...")
start_time = time.time()
try:
success = await step_func()
duration = time.time() - start_time
results.append((step_name, success, duration))
if success:
print(f"✅ {step_name} completed in {duration:.2f}s")
else:
print(f"❌ {step_name} failed after {duration:.2f}s")
except Exception as e:
duration = time.time() - start_time
results.append((step_name, False, duration))
print(f"💥 {step_name} crashed: {e}")
print("-" * 50)
time.sleep(1) # Brief pause between steps
# Summary
print("📊 DEMO SUMMARY")
print("=" * 60)
successful = sum(1 for _, success, _ in results if success)
total = len(results)
for step_name, success, duration in results:
status = "✅ PASS" if success else "❌ FAIL"
print(f"{status} | {step_name:<25} | {duration:.2f}s")
print("-" * 60)
print(f"🎯 Success Rate: {successful}/{total} ({successful/total*100:.1f}%)")
print(f"⏰ Total Duration: {sum(duration for _, _, duration in results):.2f}s")
print("=" * 60)
await self.client.aclose()
async def main():
"""Run the demo"""
demo = ConversionEngineDemo()
await demo.run_full_demo()
if __name__ == "__main__":
asyncio.run(main())