-
Notifications
You must be signed in to change notification settings - Fork 0
/
sms.py
35 lines (26 loc) · 963 Bytes
/
sms.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
35
import argparse
from twilio.rest import Client
from dotenv import load_dotenv
import os
import config
# Load environment variables from .env file
load_dotenv()
# Get account SID and auth token from environment variables
account_sid = os.getenv("TWILIO_ACCOUNT_SID")
auth_token = os.getenv("TWILIO_AUTH_TOKEN")
# Create Twilio client
client = Client(account_sid, auth_token)
def send_sms(message, to_number=config.ALERT_PHONE_NUMBER):
"""
Send SMS to a phone number using Twilio API
"""
message = client.messages.create(
body=message, from_=config.TWILIO_PHONE_NUMBER, to=to_number
)
print(f"Message sent to {to_number} with SID: {message.sid}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Send SMS using Twilio")
parser.add_argument("message", type=str, help="Message to send via SMS")
args = parser.parse_args()
# Send SMS to a phone number
send_sms(message=args.message)