Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Example usage of SMS integration in AIMHSA | |
| Demonstrates how to send SMS notifications for bookings | |
| """ | |
| import requests | |
| import json | |
| import time | |
| # Configuration | |
| API_BASE_URL = "https://prodevroger-ishingiro.hf.space" | |
| def example_booking_with_sms(): | |
| """ | |
| Example: Complete booking flow with SMS notifications | |
| """ | |
| print("π AIMHSA SMS Integration Example") | |
| print("=" * 50) | |
| # Step 1: Register a user with phone number | |
| print("1οΈβ£ Registering user with phone number...") | |
| user_data = { | |
| "username": f"demo_user_{int(time.time())}", | |
| "password": "password123", | |
| "email": f"demo_{int(time.time())}@example.com", | |
| "fullname": "Demo User", | |
| "telephone": "+250788123456", # Rwanda phone number | |
| "province": "Kigali", | |
| "district": "Gasabo" | |
| } | |
| response = requests.post(f"{API_BASE_URL}/register", json=user_data) | |
| if response.status_code == 200: | |
| print(f"β User registered: {user_data['username']}") | |
| print(f"π± Phone: {user_data['telephone']}") | |
| else: | |
| print(f"β Registration failed: {response.text}") | |
| return | |
| # Step 2: Create conversation | |
| print("\n2οΈβ£ Creating conversation...") | |
| conv_response = requests.post(f"{API_BASE_URL}/conversations", json={ | |
| "account": user_data['username'] | |
| }) | |
| if conv_response.status_code == 200: | |
| conv_data = conv_response.json() | |
| conv_id = conv_data['id'] | |
| print(f"β Conversation created: {conv_id}") | |
| else: | |
| print(f"β Conversation creation failed: {conv_response.text}") | |
| return | |
| # Step 3: Send high-risk message to trigger booking | |
| print("\n3οΈβ£ Sending high-risk message...") | |
| high_risk_message = "I feel completely hopeless and want to end my life. I can't take this pain anymore." | |
| ask_response = requests.post(f"{API_BASE_URL}/ask", json={ | |
| "id": conv_id, | |
| "query": high_risk_message, | |
| "account": user_data['username'], | |
| "history": [] | |
| }) | |
| if ask_response.status_code == 200: | |
| ask_data = ask_response.json() | |
| print(f"β Message processed") | |
| print(f"π― Risk level: {ask_data.get('risk_level', 'unknown')}") | |
| if ask_data.get('booking_created'): | |
| print(f"π Automated booking created!") | |
| print(f"π Booking ID: {ask_data.get('booking_id')}") | |
| print(f"π¨ββοΈ Professional: {ask_data.get('professional_name')}") | |
| print(f"β° Session Type: {ask_data.get('session_type')}") | |
| print(f"π± SMS notifications sent to user and professional!") | |
| else: | |
| print("β οΈ No booking created - risk level may not be high enough") | |
| else: | |
| print(f"β Message sending failed: {ask_response.text}") | |
| def example_manual_sms_test(): | |
| """ | |
| Example: Manual SMS testing | |
| """ | |
| print("\n" + "=" * 50) | |
| print("π± Manual SMS Testing") | |
| print("=" * 50) | |
| # Test SMS service status | |
| print("1οΈβ£ Checking SMS service status...") | |
| status_response = requests.get(f"{API_BASE_URL}/admin/sms/status") | |
| if status_response.status_code == 200: | |
| status_data = status_response.json() | |
| print(f"β SMS Status: {status_data.get('status')}") | |
| print(f"π Connection Test: {status_data.get('connection_test')}") | |
| else: | |
| print(f"β Status check failed: {status_response.text}") | |
| return | |
| # Test sending SMS | |
| print("\n2οΈβ£ Testing SMS send...") | |
| test_phone = input("Enter test phone number (e.g., +250788123456): ").strip() | |
| if not test_phone: | |
| test_phone = "+250788123456" | |
| sms_response = requests.post(f"{API_BASE_URL}/admin/sms/test", json={ | |
| "phone": test_phone, | |
| "message": "AIMHSA SMS Test - Integration is working! π" | |
| }) | |
| if sms_response.status_code == 200: | |
| sms_data = sms_response.json() | |
| print(f"β SMS Test: {sms_data.get('success')}") | |
| print(f"π± Phone: {sms_data.get('result', {}).get('phone', 'N/A')}") | |
| else: | |
| print(f"β SMS test failed: {sms_response.text}") | |
| def example_professional_setup(): | |
| """ | |
| Example: Setting up professional with phone number | |
| """ | |
| print("\n" + "=" * 50) | |
| print("π¨ββοΈ Professional Setup Example") | |
| print("=" * 50) | |
| # This would typically be done through the admin dashboard | |
| # Here we show the data structure needed | |
| professional_data = { | |
| "username": "dr_mukamana", | |
| "password": "password123", | |
| "first_name": "Marie", | |
| "last_name": "Mukamana", | |
| "email": "dr.mukamana@example.com", | |
| "phone": "+250788111222", # Professional phone number | |
| "specialization": "psychiatrist", | |
| "expertise_areas": ["depression", "anxiety", "ptsd", "crisis"], | |
| "district": "Gasabo", | |
| "consultation_fee": 50000, | |
| "bio": "Experienced psychiatrist specializing in trauma and crisis intervention" | |
| } | |
| print("Professional data structure for SMS notifications:") | |
| print(json.dumps(professional_data, indent=2)) | |
| print("\nNote: This would be created via the admin dashboard") | |
| if __name__ == "__main__": | |
| print("Choose an example to run:") | |
| print("1. Complete booking flow with SMS") | |
| print("2. Manual SMS testing") | |
| print("3. Professional setup example") | |
| print("4. Run all examples") | |
| choice = input("\nEnter choice (1-4): ").strip() | |
| if choice == "1": | |
| example_booking_with_sms() | |
| elif choice == "2": | |
| example_manual_sms_test() | |
| elif choice == "3": | |
| example_professional_setup() | |
| elif choice == "4": | |
| example_booking_with_sms() | |
| example_manual_sms_test() | |
| example_professional_setup() | |
| else: | |
| print("Invalid choice. Running complete booking flow...") | |
| example_booking_with_sms() | |
| print("\nπ Example completed!") | |
| print("Check the SMS_INTEGRATION_README.md for more details.") | |