Skip to content

Commit

Permalink
Adds transcription feature
Browse files Browse the repository at this point in the history
We can now support transcription feature from Twilio, updating the
response when it arrives.
  • Loading branch information
shyba committed Apr 6, 2016
1 parent 1d1cb59 commit 777aaaf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
9 changes: 9 additions & 0 deletions automated_survey/tests/questions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ def test_show_text_question_during_a_call(self):
assert '<Record' in text_response.content.decode('utf8')
assert question_store_url in text_response.content.decode('utf8')

def test_transcription_is_enabled(self):
save_url = reverse('save_response', kwargs=self.question_ids)
expected_attribute = 'transcribeCallback="%s"' % (save_url)

text_response = self.client.get(reverse('question',
kwargs=self.question_ids))

assert expected_attribute in text_response.content.decode('utf8')

def test_show_numeric_question_during_a_call(self):
self.question.kind = Question.NUMERIC
self.question.save()
Expand Down
4 changes: 2 additions & 2 deletions automated_survey/views/question_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def save_response(request, survey_id, question_id):
if not next_question:
return goodbye(request)
else:
return redirect_over_twiml(next_question.id, survey_id)
return next_question_redirect(next_question.id, survey_id)


def redirect_over_twiml(question_id, survey_id):
def next_question_redirect(question_id, survey_id):
parameters = {'survey_id': survey_id, 'question_id': question_id}
question_url = reverse('question', kwargs=parameters)

Expand Down
5 changes: 4 additions & 1 deletion automated_survey/views/questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ def voice_question(question):

action = save_response_url(question)
if question.kind == Question.TEXT:
twiml_response.record(action=action, method='POST')
kwargs = {'maxLength': 6,
'transcribe': True,
'transcribeCallback': action}
twiml_response.record(action=action, method='POST', **kwargs)
else:
twiml_response.gather(action=action, method='POST')
return twiml_response
Expand Down

0 comments on commit 777aaaf

Please sign in to comment.