-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_call.py
More file actions
65 lines (57 loc) · 2.14 KB
/
Copy pathtest_call.py
File metadata and controls
65 lines (57 loc) · 2.14 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
from twilio.rest import Client
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Twilio credentials
account_sid = os.getenv('TWILIO_ACCOUNT_SID')
auth_token = os.getenv('TWILIO_AUTH_TOKEN')
from_number = '+14134660906' # Hardcoded verified number
to_number = '+14134660906' # Hardcoded destination number
print("\n=== Making Emergency Call ===")
print(f"From: {from_number}")
print(f"To: {to_number}")
try:
# Initialize Twilio client
client = Client(account_sid, auth_token)
# Make the call with more interactive TwiML
call = client.calls.create(
to=to_number,
from_=from_number,
twiml='''
<Response>
<Say voice="alice" language="en-US">
Alert! This is an urgent test call from your fire detection system.
A potential fire has been detected in the monitored area.
Please press any key to acknowledge this message.
</Say>
<Gather numDigits="1" timeout="10"/>
<Say>No input received. Repeating message.</Say>
<Pause length="1"/>
<Say voice="alice" language="en-US">
This is a repeat of the emergency alert.
A potential fire has been detected. Please respond immediately.
</Say>
</Response>
'''
)
print("\n=== Call Status ===")
print(f"Call SID: {call.sid}")
print(f"Status: {call.status}")
# Fetch and print call details
call_details = client.calls(call.sid).fetch()
print("\n=== Call Details ===")
print(f"From: {call_details.from_}")
print(f"To: {call_details.to}")
print(f"Status: {call_details.status}")
print(f"Direction: {call_details.direction}")
except Exception as e:
print("\n=== Error Details ===")
print(f"Error Type: {type(e).__name__}")
print(f"Error Message: {str(e)}")
if hasattr(e, 'code'):
print(f"Error Code: {e.code}")
if hasattr(e, 'msg'):
print(f"Error Message: {e.msg}")
if hasattr(e, 'status'):
print(f"HTTP Status: {e.status}")