def execute(self): resp = self.handle_hours() if resp is not None: return str(resp) resp = VoiceResponse() gather = Gather() gather.play(self.section_data['play_sample'], digits=1) pause = 2 if 'pause' in self.section_data.keys(): pause = int(self.section_data['pause']) gather.pause(length=pause) resp.append(gather) if ('no_input_max_loops' in self.section_data.keys() and self.loop_count >= int( self.section_data['no_input_max_loops'])): if 'no_input_action_on_max_loops' in self.section_data.keys(): resp.redirect( self.url_of( '/ivr/action/' + self.section_data['no_input_action_on_max_loops'])) else: resp.hangup() if 'no_input_sample' in self.section_data.keys(): resp.play(self.section_data['no_input_sample']) resp.redirect(self.url_of(f'/ivr/menu?loop_count={self.loop_count}')) return str(resp)
def voice(): twiml = VoiceResponse() gather = Gather(action='store', input='dtmf speech', timeout="3") gather.say('hello') gather.pause(length="3") twiml.append(gather) twiml.hangup() # hang up call after gathering speech return str(twiml)
def test_nested_say_play_pause(self): """ a gather with a say, play, and pause """ g = Gather() g.say('Hey') g.play(url='hey.mp3') g.pause() r = VoiceResponse() r.append(g) assert_equal( self.strip(r), '<?xml version="1.0" encoding="UTF-8"?><Response><Gather><Say>Hey</Say><Play>hey.mp3</Play><Pause /></Gather></Response>' )
def assistant(): """End point dedicated to communicate with the user as assistant 'Yelp Voice'""" message = '' number = '' twilio_number = '' global sessionID assistant = AssistantV2(username=watson_username, password=watson_password, url=watson_url, version=watson_version) if request.values.get('SpeechResult'): print(message) message = request.values['SpeechResult'] if request.values.get('From'): number = request.values['From'] if request.values.get('To'): twilio_number = request.values['To'] twilio_response = VoiceResponse() gather = Gather(input='speech', action='/assistant', speechTimeout='auto') # print(sessionID) if sessionID == "": session = assistant.create_session(watson_assistanceID).get_result() sessionID = session['session_id'] print("message: {}".format(message)) if message != '': watson_call = assistant.message(watson_assistanceID, sessionID, options={'return_context': 'true'}, input={'text': message}) response_watson = watson_call.get_result() print(json.dumps(response_watson, indent=1)) if (len(response_watson['output']['generic']) > 0): for intern_response in response_watson['output']['generic']: if intern_response['response_type'] == 'text': print(intern_response['text']) flag_variable = "" flag_values = "" if len(intern_response['text'].split("::")) > 1: flag_variable = intern_response['text'].split( "::")[0].strip() flag_values = intern_response['text'].split( "::")[1].strip() if flag_variable == "{restaurant}": gather.say( 'sure, I will let you know about some restaurants nearby', voice='alice') gather.say(getRestaurantList(flag_values), voice='alice') elif (len(response_watson['output']['intents']) > 0): for intern_intent in response_watson['output'][ 'intents']: if intern_intent["intent"] == "No" or intern_intent[ "intent"] == "General_Ending": twilio_response.say(intern_response['text'], voice='alice') assistant.delete_session( watson_assistanceID, sessionID) sessionID = "" gather.pause(2) twilio_response.hangup() else: gather.say(intern_response['text'], voice='alice') else: gather.say(intern_response['text'], voice='alice') gather.pause(4) gather.say('Is there other question that I can answer?', voice='alice') else: response_watson = assistant.message(watson_assistanceID, sessionID, options={ 'return_context': 'true' }, input={ 'text': login(number) }).get_result() if (len(response_watson['output']['generic']) > 0): for intern_response in response_watson['output']['generic']: if intern_response['response_type'] == 'text': print(intern_response['text']) gather.say(intern_response['text'], voice='alice') gather.pause(3) gather.say( 'Remember, you can know what the people is thinking about some store or business. Just ask: Yelp, let me know about Thai Restaurants.', voice='alice') twilio_response.append(gather) return str(twilio_response)
def airecruiter(): """End point dedicated to communicate with the user as assistant""" # welcome_message = ['Wellcome to the AI Recruiter Tool...', # # 'How can I help you?', # 'You can ask for status of your licences, check the candidates growth in latest month, and even know the most used actions from recruiters.', # 'Just ask whenever you feel ready, saying Please let me know the candidates grow, for example...'] message = '' number = '' twilio_number = '' session = None assistant = AssistantV2(username=watson_username, password=watson_password, url=watson_url, version=watson_version) if request.values.get('SpeechResult'): message = request.values['SpeechResult'] if request.values.get('From'): number = request.values['From'] if request.values.get('To'): twilio_number = request.values['To'] twilio_response = VoiceResponse() gather = Gather(input='speech', action='/airecruiter', speechTimeout='auto') if session is None: session = assistant.create_session(watson_assistanceID).get_result() sessionID = session['session_id'] if message != '': print("message: {}".format(message)) message = assistant.message(watson_assistanceID, sessionID, input={ 'text': message }).get_result() if (len(message['output']['generic']) > 0): for intern_response in message['output']['generic']: if intern_response['response_type'] == 'text': print(intern_response['text']) if intern_response['text'] == "{userName}": messageApi = assistant.message(watson_assistanceID, sessionID, input={ 'text': login() }).get_result() if (len(messageApi['output']['generic']) > 0): for intern_api_response in messageApi['output'][ 'generic']: if intern_api_response[ 'response_type'] == 'text': print(intern_api_response['text']) gather.say(intern_api_response['text'], voice='alice') elif intern_response['text'] == "{growth}": gather.say( 'sure, I will let you know about the candidates growth in a second.', voice='alice') for idea_response in get_candidate_growth(): gather.say(idea_response, voice='alice') elif intern_response['text'] == "{resumeviewed}": gather.say( 'sure thing, I will let you know about the most recent resumes viewed.', voice='alice') for idea_response in most_viewed_resumes(): gather.say(idea_response, voice='alice') elif intern_response['text'] == "{actionused}": gather.say( 'hold on a second, I am collecting the data.', voice='alice') for idea_response in actions_used_by_recruiter(): gather.say(idea_response, voice='alice') elif (len(message['output']['intents']) > 0): for intern_intent in message['output']['intents']: if intern_intent["intent"] == "No" or intern_intent[ "intent"] == "General_Ending": twilio_response.say(intern_response['text'], voice='alice') gather.pause(2) twilio_response.hangup() else: gather.say(intern_response['text'], voice='alice') gather.pause(2) gather.say('Is there other question that I can answer?', voice='alice') else: message = assistant.message(watson_assistanceID, sessionID, input={ 'text': login() }).get_result() if (len(message['output']['generic']) > 0): for intern_response in message['output']['generic']: if intern_response['response_type'] == 'text': print(intern_response['text']) gather.say(intern_response['text'], voice='alice') gather.pause(2) gather.say( 'Remember, you can ask about the grow in candidates latest months. Just ask: "Alice, let me know the candidates grow."', voice='alice') twilio_response.append(gather) return str(twilio_response)