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