Skip to content

Commit

Permalink
TwiML view methods: passing the user_id as a GET param to the TwiML r…
Browse files Browse the repository at this point in the history
…esources.
  • Loading branch information
Teddy Wing committed Oct 22, 2011
1 parent ae26fc9 commit f56f192
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions callforme/views.py
Expand Up @@ -10,7 +10,7 @@
from twilio.twiml import Response, Sms
from twilio import twiml

from callforme.models import Contact, ContactForm
from callforme.models import Contact, ContactForm, User
from userena.signals import activation_complete

account = settings.TWILIO_ACCOUNT_SID
Expand Down Expand Up @@ -42,7 +42,7 @@ def twilio_call(request):
phone = "+1" + user_profile.phone

call = client.calls.create(to=phone, from_=settings.TWILIO_DEFAULT_CALLERID,
url="http://pickupconnect-staging.djangozoom.net/twiml-response")
url="http://pickupconnect-staging.djangozoom.net/twiml-response?user_id=%s" %request.user.id)

# Steve: 6172901329
# John: 6262721760 #6175174953
Expand All @@ -54,27 +54,30 @@ def twilio_call(request):
def twiml_response(request):
import random

num_contacts = request.user.contact_set.count()
user = User.objects.filter(id=int(request.GET['user_id']))[0]
num_contacts = user.contact_set.count()
contact_select = random.randrange(0, num_contacts) if num_contacts > 1 else 0 # Pick a random contact (fails if you have no contacts)

user_profile = request.user.get_profile()
contact = request.user.contact_set.all()[contact_select]
user_profile = user.get_profile()
contact = user.contact_set.all()[contact_select]

r = twiml.Response()
# r.say(text, voice=voice, language=language, loop=loop)
r.say("Pickup Connect would like to connect you to %s." %contact.name)
with r.gather(action="http://pickupconnect-staging.djangozoom.net/twiml-connect?contact_id=%s" %contact.id, finishOnKey=1, timeout=15) as g:
with r.gather(action="http://pickupconnect-staging.djangozoom.net/twiml-connect?contact_id=%s&user_id=%s" %(contact.id, request.GET['user_id']), finishOnKey=1, timeout=15) as g:
# When we get a background queue, stop using a GET param and take the contact_id from a call
g.say('Press 1 followed by the pound key to continue connecting.')
# "... or stay on the line to continue with the call"
return HttpResponse(r, mimetype='text/xml')

def twiml_connect(request):
user = User.objects.filter(id=int(request.GET['user_id']))[0]

r = twiml.Response()
user_profile = request.user.get_profile()
user_profile = user.get_profile()

try:
contact_phone = ( request.user.contact_set.filter(id=request.GET['contact_id']) )[0].phone
contact_phone = ( user.contact_set.filter(id=request.GET['contact_id']) )[0].phone
except IndexError: # Exception on contact not found
pass

Expand Down

0 comments on commit f56f192

Please sign in to comment.