-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessaging.py
34 lines (29 loc) · 1.19 KB
/
messaging.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
30
31
32
33
34
import africastalking
class SMS():
def __init__(self):
username = ''
self.sender = ""
api_key = ''
africastalking.initialize(username, api_key)
self.sms = africastalking.SMS
def sending(self, number, location, meter_id,message_type):
# Set the numbers in international format
recipients = [number]
# Set your message
message = ""
if int(message_type) == 1:
message = f"""OUTAGE ALERT:\n
A water outage has been reported at {location}, affecting meter number {meter_id}.\n
Please investigate and take immediate action.\n
For more details, contact {number}."""
elif int(message_type) == 2:
message = f"""LEAKAGE ALERT:\n
A water outage has been reported at {location}, affecting meter number {meter_id}.\n
Please investigate and take immediate action.\n
For more details, contact {number}.
"""
try:
response = self.sms.send(message, recipients, self.sender)
print (response)
except Exception as e:
print (f'Houston, we have a problem: {e}')