Created
December 11, 2012 15:08
-
-
Save bebef1987/4259184 to your computer and use it in GitHub Desktop.
initiate a call with twilio wait to answer and hangup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Download the library from twilio.com/docs/libraries | |
from twilio.rest import TwilioRestClient | |
import time | |
# Get these credentials from http://twilio.com/user/account | |
account_sid = "SECRET" | |
auth_token = "SECRET" | |
client = TwilioRestClient(account_sid, auth_token) | |
# Make the call | |
call = client.calls.create(to="+SECRET", # Any phone number | |
from_="+SECRET", # Must be a valid Twilio number | |
url="http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient") | |
sid = call.sid | |
call = client.calls.get(sid) | |
print call.duration | |
print call.status | |
print call.sid | |
timeout = 10 | |
answer = False | |
timeout = float(timeout) + time.time() | |
# wait to answer | |
while time.time() < timeout: | |
time.sleep(0.5) | |
if client.calls.get(sid).status == "in-progress": | |
answer = True | |
print client.calls.get(sid).status | |
time.sleep(1) | |
break | |
print client.calls.get(sid).status | |
# stop call | |
print "hangup" | |
call.hangup() | |
call = client.calls.get(sid) | |
print "answer = %s" %answer | |
print call.duration | |
print call.status | |
print call.sid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment