Skip to content

Commit

Permalink
[WIP] Match the input from user call and continue the flow
Browse files Browse the repository at this point in the history
  • Loading branch information
danimaribeiro committed Dec 1, 2018
1 parent 7ed6b83 commit 5987c23
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
9 changes: 8 additions & 1 deletion voice_twilio/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ def call_completed(self, voice_call_id, vals):

def call_in_progress(self, voice_call_id, vals):
flow_obj = request.env['twilio.voice.flow'].sudo()

if "Digits" in vals or "SpeechResult" in vals:
result = vals.get('Digits') or vals.get('SpeechResult')
flow = flow_obj.current_flow(voice_call_id.voice_flow_sequence)
match = flow.match_response(result)
if not match:
return str(flow.generate_twiml())

flow = flow_obj.next_flow(voice_call_id.voice_flow_sequence)
if not flow:
resp = VoiceResponse()
Expand All @@ -58,7 +66,6 @@ def call_in_progress(self, voice_call_id, vals):
@http.route('/twilio/voice', type='http', auth="public",
cors="*", csrf=False)
def twilio_voice_request(self, **vals):
print(vals)
voice_obj = request.env['twilio.voice.call'].sudo()
voice_call_id = voice_obj.register_new_call(vals)
call_status = vals['CallStatus']
Expand Down
1 change: 0 additions & 1 deletion voice_twilio/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
from . import twilio_voice_call
from . import voice_flow
from . import res_partner
from . import mail_channel
8 changes: 0 additions & 8 deletions voice_twilio/models/mail_channel.py

This file was deleted.

31 changes: 21 additions & 10 deletions voice_twilio/models/voice_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def next_flow(self, sequence):
[('sequence', '>', sequence)], limit=1, order='sequence asc')
return flow

def current_flow(self, sequence):
flow = self.search(
[('sequence', '=', sequence)], limit=1)
return flow

def _get_dial_to(self):
if self.to_partner_id and self.to_partner_id.twilio_client:
return [self.to_partner_id.twilio_client]
Expand All @@ -67,21 +72,20 @@ def _generate_say(self, response):
response.say(self.say_message, voice="alice", language="pt-BR")

def _generate_gather(self, response):
gather = Gather()
self._generate_say(gather)

input = ''
if self.gather_possible_values:
values = [x.strip() for x in
self.gather_possible_values.split('\n')]
if ";" in values[0]:
gather.input = 'dtmf speech'
gather.speechTimeout = 'auto'
input = 'dtmf speech'
elif values[0].isdigit():
gather.input = 'dtmf'
input = 'dtmf'
else:
gather.input = 'speech'
gather.speechTimeout = 'auto'
input = 'speech'

gather = Gather(timeout=10, speechTimeout='auto',
input=input, language='pt-BR')
self._generate_say(gather)
response.append(gather)

def _generate_dial(self, response):
Expand Down Expand Up @@ -109,7 +113,14 @@ def generate_twiml(self):
if not base_url:
base_url = self.env['ir.config_parameter'].sudo().get_param(
'web.base.url')
response.say('Nenhuma pessoa para atender', voice='alice', language='pt-BR')
response.redirect(base_url + '/twilio/voice')
print(str(response))
return response

def match_response(self, result):
if self.gather_possible_values:
values = [x.strip() for x in
self.gather_possible_values.split('\n')]
for value in values:
if result in value.split(';'):
return True
return False

0 comments on commit 5987c23

Please sign in to comment.