336
Si
sinfo-talk / files
sinfo-talk / sms_and_voice.py
1.8 KB
1# -*- coding: utf-8 -*- 2import json 3 4from twilio.rest import Client 5 6 7secrets = None 8barata = None 9jpaiva = None 10volunteer = None 11 12with open(".secrets.json") as json_file: 13 secrets = json.loads(json_file.read()) 14 15 # our kind volunteers 16 jpaiva = secrets.get("jpaiva") # joao paiva 17 barata = secrets.get("rsbarata") # ricardo barata 18 19# Instantiate the Twilio client 20# ============================= 21client = Client(secrets.get("account_sid"), 22 secrets.get("auth_token")) 23 24 25# Send a text message 26# =================== 27 28# Purchase a number from Twilio 29sms_numbers = client.available_phone_numbers("PT") \ 30 .mobile.list(sms_enabled=True) 31 32sms_number = client.incoming_phone_numbers \ 33 .create(phone_number=sms_numbers[0].phone_number) 34 35print "This should be stored somewhere, like a datastore." 36print sms_number.sid 37 38# or ... 39 40# Get a previously purchased phone from Twilio 41 42# number_sid = "PN33845868b5fdbcb6a82dd172a17cb1eb" # previously aquired 43# my_number = client.incoming_phone_numbers(number_sid).fetch() 44 45# print "This should be stored somewhere, like a datastore." 46# print my_number.phone_number 47 48# Send the text 49client.messages.create( 50 to=volunteer, 51 from_=sms_number.phone_number, 52 body="Hey there, this is a test, can you tell me on Slack if you got it?" 53) 54 55 56# Voice call 57# ========== 58 59# Aquire the voice capable phone 60voice_numbers = client.available_phone_numbers("PT") \ 61 .local.list(voice_enabled=True) 62 63voice_number = client.incoming_phone_numbers \ 64 .create(phone_number=voice_numbers[0].phone_number) 65 66print "Aquired number, this should be stored in a datastore" 67print voice_number.sid 68 69# Send a voice call audio stolen from Twilio with 💖 70call = client.calls.create( 71 to=volunteer, 72 from_=voice_number.phone_number, 73 url="http://demo.twilio.com/docs/voice.xml" 74) 75 76print "Call is ongoing" 77print call.sid