def consume_user_message(self, message): self.log("User message received from %s '%s'" % (message['from_addr'], message['content'])) try: ref = None actions = [] active_dialogues = self.get_active_dialogues() for dialogue in active_dialogues: scriptHelper = Dialogue(dialogue['Dialogue']) ref, actions = scriptHelper.get_matching_reference_and_actions( message['content'], actions) if ref: break actions = self.get_matching_request_actions( message['content'], actions) self.save_history( message_content=message['content'], participant_phone=message['from_addr'], message_type='received', reference_metadata=ref) self.log("actions %s reference %s" % (actions, ref)) for action in actions: self.run_action(message['from_addr'], action) except: exc_type, exc_value, exc_traceback = sys.exc_info() self.log( "Error during consume user message: %r" % traceback.format_exception(exc_type, exc_value, exc_traceback))
def consume_user_message(self, message): self.log("User message received from %s '%s'" % (message['from_addr'], message['content'])) try: ref = None actions = [] active_dialogues = self.get_active_dialogues() for dialogue in active_dialogues: scriptHelper = Dialogue(dialogue['Dialogue']) ref, actions = scriptHelper.get_matching_reference_and_actions( message['content'], actions) if ref: break actions = self.get_matching_request_actions( message['content'], actions) self.save_history(message_content=message['content'], participant_phone=message['from_addr'], message_type='received', reference_metadata=ref) self.log("actions %s reference %s" % (actions, ref)) for action in actions: self.run_action(message['from_addr'], action) except: exc_type, exc_value, exc_traceback = sys.exc_info() self.log( "Error during consume user message: %r" % traceback.format_exception(exc_type, exc_value, exc_traceback))
def test_get_matchin_question_answer(self): script = Dialogue(self.question_answer) ref, actions = script.get_matching_reference_and_actions("feel 1", []) self.assertEqual(ref, {'dialogue-id': '01', 'interaction-id': '01-01', 'matching-answer': 'Fine'}) self.assertEqual(len(actions), 2) self.assertEqual(actions[0], {'type-action': 'feedback', 'content': 'thank you'}) self.assertEqual(actions[1], {'type-action': 'feedback', 'content': 'thank you again'}) ref, actions = script.get_matching_reference_and_actions("feel 0", []) self.assertEqual(ref, {'dialogue-id': '01', 'interaction-id': '01-01', 'matching-answer': None}) self.assertEqual(len(actions), 1) self.assertEqual(actions[0],{'type-action': 'unmatching-answer', 'answer': '0'}) ref, actions = script.get_matching_reference_and_actions("feel 3", []) self.assertEqual(ref, {'dialogue-id': '01', 'interaction-id': '01-01', 'matching-answer': None}) self.assertEqual(len(actions), 1) ref, actions = script.get_matching_reference_and_actions("feel ok", []) self.assertEqual(ref, {'dialogue-id': '01', 'interaction-id': '01-01', 'matching-answer': 'Ok'}) self.assertEqual(len(actions), 0) ref, actions = script.get_matching_reference_and_actions("fel ok", []) self.assertEqual(ref, {'dialogue-id': '01', 'interaction-id': '01-01', 'matching-answer': 'Ok'}) self.assertEqual(len(actions), 0) ref, actions = script.get_matching_reference_and_actions("name john doe", []) self.assertEqual(ref, {'dialogue-id': '01', 'interaction-id': '01-02'}) self.assertEqual(len(actions), 2) self.assertEqual(actions[0], {'type-action': 'feedback', 'content': 'thank you for this answer'}) self.assertEqual(actions[1], {'type-action': 'profiling', 'label': 'name', 'value': 'john doe'}) ref, actions = script.get_matching_reference_and_actions("name", []) self.assertEqual(ref, {'dialogue-id': '01', 'interaction-id': '01-02'}) self.assertEqual(len(actions), 2) self.assertEqual(actions[0], {'type-action': 'feedback', 'content': 'thank you for this answer'}) self.assertEqual(actions[1], {'type-action': 'profiling', 'label': 'name', 'value': ''}) script = Dialogue(self.other_question_answer) ref, actions = script.get_matching_reference_and_actions("something good", []) self.assertEqual(ref, {}) self.assertEqual(actions, []) ref, actions = script.get_matching_reference_and_actions('Gen Male', []) self.assertEqual(ref, {'dialogue-id': 'script.dialogues[0]', 'interaction-id': 'script.dialogues[0].interactions[2]', 'matching-answer': 'Male'}) self.assertEqual(len(actions), 1) self.assertEqual(actions[0], {'type-action': 'profiling', 'label': 'gender', 'value': 'Male'})
def test_get_matchin_question_answer(self): script = Dialogue(self.question_answer) ref, actions = script.get_matching_reference_and_actions("feel 1", []) self.assertEqual( ref, { 'dialogue-id': '01', 'interaction-id': '01-01', 'matching-answer': 'Fine' }) self.assertEqual(len(actions), 2) self.assertEqual(actions[0], { 'type-action': 'feedback', 'content': 'thank you' }) self.assertEqual(actions[1], { 'type-action': 'feedback', 'content': 'thank you again' }) ref, actions = script.get_matching_reference_and_actions("feel 0", []) self.assertEqual( ref, { 'dialogue-id': '01', 'interaction-id': '01-01', 'matching-answer': None }) self.assertEqual(len(actions), 1) self.assertEqual(actions[0], { 'type-action': 'unmatching-answer', 'answer': '0' }) ref, actions = script.get_matching_reference_and_actions("feel 3", []) self.assertEqual( ref, { 'dialogue-id': '01', 'interaction-id': '01-01', 'matching-answer': None }) self.assertEqual(len(actions), 1) ref, actions = script.get_matching_reference_and_actions("feel ok", []) self.assertEqual( ref, { 'dialogue-id': '01', 'interaction-id': '01-01', 'matching-answer': 'Ok' }) self.assertEqual(len(actions), 0) ref, actions = script.get_matching_reference_and_actions("fel ok", []) self.assertEqual( ref, { 'dialogue-id': '01', 'interaction-id': '01-01', 'matching-answer': 'Ok' }) self.assertEqual(len(actions), 0) ref, actions = script.get_matching_reference_and_actions( "name john doe", []) self.assertEqual(ref, {'dialogue-id': '01', 'interaction-id': '01-02'}) self.assertEqual(len(actions), 2) self.assertEqual(actions[0], { 'type-action': 'feedback', 'content': 'thank you for this answer' }) self.assertEqual(actions[1], { 'type-action': 'profiling', 'label': 'name', 'value': 'john doe' }) ref, actions = script.get_matching_reference_and_actions("name", []) self.assertEqual(ref, {'dialogue-id': '01', 'interaction-id': '01-02'}) self.assertEqual(len(actions), 2) self.assertEqual(actions[0], { 'type-action': 'feedback', 'content': 'thank you for this answer' }) self.assertEqual(actions[1], { 'type-action': 'profiling', 'label': 'name', 'value': '' }) script = Dialogue(self.other_question_answer) ref, actions = script.get_matching_reference_and_actions( "something good", []) self.assertEqual(ref, {}) self.assertEqual(actions, []) ref, actions = script.get_matching_reference_and_actions( 'Gen Male', []) self.assertEqual( ref, { 'dialogue-id': 'script.dialogues[0]', 'interaction-id': 'script.dialogues[0].interactions[2]', 'matching-answer': 'Male' }) self.assertEqual(len(actions), 1) self.assertEqual(actions[0], { 'type-action': 'profiling', 'label': 'gender', 'value': 'Male' })