Skip to content

Commit

Permalink
Starting to get outgoing calls to work
Browse files Browse the repository at this point in the history
  • Loading branch information
arfrank committed Nov 22, 2010
1 parent 6e4b496 commit 344a47d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
6 changes: 5 additions & 1 deletion handlers/calls.py
Expand Up @@ -100,6 +100,9 @@ def post(self,API_VERSION,ACCOUNT_SID,*args):
format = response.response_format(self.request.path.split('/')[-1]) format = response.response_format(self.request.path.split('/')[-1])
if parameters.required(['From','To','Url'],self.request): if parameters.required(['From','To','Url'],self.request):
Phone_Number = incoming_phone_numbers.Incoming_Phone_Number.all().filter('PhoneNumber = ',self.request.get('From')).filter('AccountSid =',ACCOUNT_SID).get() Phone_Number = incoming_phone_numbers.Incoming_Phone_Number.all().filter('PhoneNumber = ',self.request.get('From')).filter('AccountSid =',ACCOUNT_SID).get()
if Phone_Number is None:
Phone_Number = outgoing_caller_ids.Outgoing_Caller_Id.all().filter('PhoneNumber =', self.request.get('From')).filter('AccountSid =', ACCOUNT_SID).get()

if Phone_Number is not None: if Phone_Number is not None:
Call = calls.Call.new( Call = calls.Call.new(
From = self.request.get('From'), From = self.request.get('From'),
Expand Down Expand Up @@ -130,7 +133,8 @@ def post(self,API_VERSION,ACCOUNT_SID,*args):
Call.disconnect(StatusCallback,StatusCallbackMethod) Call.disconnect(StatusCallback,StatusCallbackMethod)
self.response.out.write(response.format_response(response.add_nodes(self,response_data,format),format)) self.response.out.write(response.format_response(response.add_nodes(self,response_data,format),format))
else: else:
self.response.out.write(response.format_response(errors.rest_error_response(404,"Resource not found",format),format)) #we dont have a valid outgoing phone number to which to make the call
self.response.out.write(response.format_response(errors.rest_error_response(400,"Resource not found",format,21212, 'http://www.twilio.com/docs/error/21212' ),format))
else: else:
self.response.out.write(response.format_response(errors.rest_error_response(400,"Missing Parameters",format),format)) self.response.out.write(response.format_response(errors.rest_error_response(400,"Missing Parameters",format),format))


Expand Down
37 changes: 24 additions & 13 deletions helpers/twiml.py
Expand Up @@ -309,7 +309,7 @@ def process_record(verb, Twiml, ModelInstance, Input = ''):
Account = accounts.Account.all().filter('Sid =',ModelInstance.AccountSid).get() Account = accounts.Account.all().filter('Sid =',ModelInstance.AccountSid).get()


#Whether or not twiml parsed, the twiml dictionary, and any error messages #Whether or not twiml parsed, the twiml dictionary, and any error messages
Valid, Twiml, AddMessage = get_external_twiml(Account, Action, Method, ModelInstance, {'SmsSid' : Instance.Sid, 'SmsStatus' : Message.Status}, OTwiml) Valid, Twiml, AddMessage = get_external_twiml(Account, Action, Method, ModelInstance, {'SmsSid' : Instance.Sid, 'SmsStatus' : Message.Status}, OrigionalTwiml)
msg+=AddMessage msg+=AddMessage
if 'transcribe' in verb['Attr'] and verb['Attr']['transcribe'] == 'true': if 'transcribe' in verb['Attr'] and verb['Attr']['transcribe'] == 'true':
transcribeCallback = verb['Attr']['transcribeCallback'] if 'Attr' in verb and 'transcribeCallback' in verb['Attr'] else None transcribeCallback = verb['Attr']['transcribeCallback'] if 'Attr' in verb and 'transcribeCallback' in verb['Attr'] else None
Expand Down Expand Up @@ -422,7 +422,7 @@ def process_gather(verb, Twiml, ModelInstance, Input):
return msg, False, False return msg, False, False


#the verb node of the tiwml document, the twiml document, and the instance that caused the creation of the twiml document #the verb node of the tiwml document, the twiml document, and the instance that caused the creation of the twiml document
def process_sms(verb, OTwiml, Instance): def process_sms(verb, OrigionalTwiml, Instance):
msg = '' msg = ''
To = verb['Attr']['to'] if 'Attr' in verb and 'to' in verb['Attr'] else Instance.From To = verb['Attr']['to'] if 'Attr' in verb and 'to' in verb['Attr'] else Instance.From
From = verb['Attr']['from'] if 'Attr' in verb and 'from' in verb['Attr'] else Instance.To From = verb['Attr']['from'] if 'Attr' in verb and 'from' in verb['Attr'] else Instance.To
Expand All @@ -449,10 +449,10 @@ def process_sms(verb, OTwiml, Instance):
if Action is None: if Action is None:
#then techincally we should rerequest the original url #then techincally we should rerequest the original url
#but i dont make sure the method is the same :/ #but i dont make sure the method is the same :/
#Action = OTwiml.Url #Action = OrigionalTwiml.Url
pass pass
if Action is not None: if Action is not None:
Valid, Twiml, AddMessage = get_external_twiml(Account, Action, Method, Instance,{'SmsSid' : Instance.Sid, 'SmsStatus' : Message.Status}, OTwiml) Valid, Twiml, AddMessage = get_external_twiml(Account, Action, Method, Instance,{'SmsSid' : Instance.Sid, 'SmsStatus' : Message.Status}, OrigionalTwiml)


msg+=AddMessage msg+=AddMessage


Expand Down Expand Up @@ -481,26 +481,37 @@ def process_dial(verb, OrigionalTwiml, Instance):
else: else:
pass pass


def process_number(verb): def process_number(verb, OrigionalTwiml, Instance):
msg = 'Dialing number: '+ process_text(verb) msg = 'Dialing number: '+ process_text(verb)
if 'sendDigits' in verb['Attr']: if 'sendDigits' in verb['Attr']:
msg+='\nSending digits: '+verb['Attr']['sendDigits'] msg+='\nSending digits: '+verb['Attr']['sendDigits']
if 'url' in verb['Attr']: if 'url' in verb['Attr']:
pass pass
#need to grab this twiml document, create a new call and pass in a bunch of other things, damn this gets much more complex to maintain state for, not impossible, but certainly harder and more trees #can i make it look like it came from a different number
#create a new call and make it ring!
"""
Call = calls.Call.new( AccountSid = Instance.AccountSid,
ParentSid = Instance.Sid,
request = None,
To = str( process_text( verb ) ),
From = Instance.From,
PhoneNumberSid = Instance.PhoneNumberSid,
Direction = 'outbound-dial')
"""
#need to grab this twiml document, create a new call and pass in a bunch of other things, damn this gets much more complex to maintain state for, not impossible, but certainly harder and more trees
return return


def process_conference(verb): def process_conference(verb, OrigionalTwiml, Instance):
return 'Putting into conference room: '+process_text(verb) return 'Putting into conference room: '+process_text(verb)


def process_hangup(verb): def process_hangup(verb):
return 'Call Hung Up' return 'Call Hung Up'


def process_redirect(verb, OTwiml, Instance): def process_redirect(verb, OrigionalTwiml, Instance):
msg = 'Redirecting to '+process_text(verb) msg = 'Redirecting to '+process_text(verb)
Account = accounts.Account.all().filter('Sid =',Instance.AccountSid).get() Account = accounts.Account.all().filter('Sid =',Instance.AccountSid).get()
NewDoc = False NewDoc = False
Valid, Twiml, AddMessage = get_external_twiml(Account,process_text(verb),verb['Attr']['method'] if 'method' in verb['Attr'] else 'POST', Instance, {}, OTwiml) Valid, Twiml, AddMessage = get_external_twiml(Account,process_text(verb),verb['Attr']['method'] if 'method' in verb['Attr'] else 'POST', Instance, {}, OrigionalTwiml)
msg+=AddMessage msg+=AddMessage
if Valid: if Valid:
msg+='A new Twiml document was created, processing will continue on that document' msg+='A new Twiml document was created, processing will continue on that document'
Expand All @@ -523,7 +534,7 @@ def process_text(verb):


#this not ideal, but was getting errors other ways so will refactor when needed. #this not ideal, but was getting errors other ways so will refactor when needed.
#returns the text, whether or not it should stop processing and wait for input and the new twiml document, if applicable #returns the text, whether or not it should stop processing and wait for input and the new twiml document, if applicable
def process_verb(verb,Twiml, ModelInstance, Input): def process_verb(verb, Twiml, ModelInstance, Input):
#logging.info(verb) #logging.info(verb)
if verb['Type'] =='Say': if verb['Type'] =='Say':
return process_say(verb) #done return process_say(verb) #done
Expand All @@ -536,11 +547,11 @@ def process_verb(verb,Twiml, ModelInstance, Input):
elif verb['Type'] == 'Sms': elif verb['Type'] == 'Sms':
return process_sms(verb, Twiml, ModelInstance) #done return process_sms(verb, Twiml, ModelInstance) #done
elif verb['Type'] == 'Dial': elif verb['Type'] == 'Dial':
return (process_dial(verb),True,False) return (process_dial(verb, Twiml, ModelInstance),True,False)
elif verb['Type'] == 'Number': elif verb['Type'] == 'Number':
return (process_number(verb),False,False) return (process_number(verb, Twiml, ModelInstance),False,False)
elif verb['Type'] == 'Conference': elif verb['Type'] == 'Conference':
return (process_conference(verb),False,False) return (process_conference(verb, Twiml, ModelInstance),False,False)
elif verb['Type'] == 'Hangup': elif verb['Type'] == 'Hangup':
return (process_hangup(verb),True,False) #done return (process_hangup(verb),True,False) #done
elif verb['Type'] == 'Redirect': elif verb['Type'] == 'Redirect':
Expand Down

0 comments on commit 344a47d

Please sign in to comment.