-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWhatsapp.py
29 lines (25 loc) · 895 Bytes
/
Whatsapp.py
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
def send_whatsapp_alert(tonumber):
try:
from twilio.rest import Client
from dotenv import load_dotenv
import os
load_dotenv()
account_sid = os.getenv('TWILIO_ACCOUNT_SID')
auth_token = os.getenv('TWILIO_AUTH_TOKEN')
client = Client(account_sid, auth_token)
to_number = 'whatsapp:'+tonumber
print(to_number)
from_number = os.getenv('SENDER_WHATSAPP_NUMBER')
message_body = 'Fall Detected - Check Email for more information'
message = client.messages.create(
from_=from_number,
body=message_body,
to=to_number
)
print(f"WhatsApp alert sent (SID: {message.sid})")
return True
except Exception as e:
print(f"Error sending WhatsApp message: {e}")
return False
# if __name__ == "__main__":
# send_whatsapp_alert()