import requests import json import sys import io # Force UTF-8 for console output if sys.platform == "win32": sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace') # Configuration API_URL = "http://127.0.0.1:8004/api/guvi/analyze" API_KEY = "GUVI_HACKATHON_V2" def run_test(): print("Starting End-to-End Verification Flow...") # Simulate a scam message containing intelligence (MATCHING USER SPEC SECTION 6.1) payload = { "sessionId": "GUVI-DEMO-SESSION-001", "message": { "sender": "scammer", "text": "Your bank account will be blocked today. Verify immediately.", "timestamp": "2026-01-21T10:15:30Z" }, "conversationHistory": [], "metadata": {"channel": "SMS", "language": "English", "locale": "IN"} } headers = {"x-api-key": API_KEY, "Content-Type": "application/json"} print("\n[STEP 1] Sending scam message to Sentinel (Section 6.1)...") try: response = requests.post(API_URL, json=payload, headers=headers) print(f"Server Status: {response.status_code}") if response.status_code != 200: print(f"Server Error: {response.text}") return data = response.json() print(f"Sentinel Reply: {data.get('reply')}") print(f"Scam Detected: {data.get('scamDetected')}") print(f"Intelligence Extracted: {json.dumps(data.get('extractedIntelligence'), indent=2)}") # Engagement loop (Turn 2 - Section 6.2) payload["conversationHistory"] = [ payload["message"], {"sender": "user", "text": data.get("reply"), "timestamp": "2026-01-21T10:16:10Z"} ] payload["message"] = {"sender": "scammer", "text": "Share your UPI ID to avoid account suspension.", "timestamp": "2026-01-21T10:17:10Z"} print("\n[STEP 2] Sending follow-up to trigger final callback (Section 6.2)...") response = requests.post(API_URL, json=payload, headers=headers) print(f"Server Status: {response.status_code}") print(f"Final Step Note: If turn count >= 3 or intel found, callback triggers automatically.") # Engagement loop (Turn 3 - FORCE CALLBACK with High Value Intel) print("\n[STEP 3] Sending final triggers (UPI + Turn 3)...") payload["conversationHistory"].append(payload["message"]) # Add prev scammer msg payload["conversationHistory"].append({"sender": "user", "text": "I can't find my UPI, can I send to a number?", "timestamp": "2026-01-21T10:18:10Z"}) # Scammer provides actionable intel payload["message"] = {"sender": "scammer", "text": "Ok send to 9876543210@paytm fast!", "timestamp": "2026-01-21T10:19:10Z"} response = requests.post(API_URL, json=payload, headers=headers) print(f"Server Status: {response.status_code}") data = response.json() print(f"Final Reply: {data.get('reply')}") print(f"Final Intel: {json.dumps(data.get('extractedIntelligence'), indent=2)}") print("\nVerification sequence complete. Review Server/Mock logs for JSON results.") except Exception as e: print(f" Test Failed: {e}") if __name__ == "__main__": run_test()