forked from PatKuz/BostonHacks2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_sms.py
48 lines (43 loc) · 1.28 KB
/
send_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
36
37
38
39
40
41
42
43
44
45
46
47
48
import yaml
from twilio.rest import Client
import http.server
import socketserver
import threading
PORT = 5000
def start_server():
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
httpd.serve_forever()
def send_message(messageToSend, toNum=None, image=None):
creds = yaml.safe_load(open("creds.yaml", "r"))
account_sid = creds['ACCOUNT_SID']
auth_token = creds['AUTH_TOKEN']
ngrok_url = creds['NGROK_URL']
client = Client(account_sid, auth_token)
if toNum == None:
toNum = creds['to']
fromNum = creds['from']
if toNum == None:
toNum = toNum
else:
toNum = toNum
if image:
target = threading.Thread(target=start_server)
target.start()
imageUrl = ngrok_url + '/' + image
print("ImageURL")
print(imageUrl)
message = client.messages.create(
body=messageToSend,
from_=fromNum,
to=toNum,
media_url=[imageUrl]
)
else:
message = client.messages.create(
body=messageToSend,
from_=fromNum,
to=toNum,
)
print(message)