File size: 6,084 Bytes
c024705
 
 
 
 
 
 
 
 
 
 
eeacc46
c024705
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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.")