예제 #1
0
def test_json_parse_resume():
    # DOCS MARKER ConversationResumed
    evt = \
        {
            'event': 'resume',
        }
    # DOCS END
    assert Event.from_parameters(evt) == ConversationResumed()
예제 #2
0
    def run(self, dispatcher, tracker, domain):
        response = "Reaching out to a human agent [{}]...".format(
            tracker.sender_id)
        dispatcher.utter_message(response)
        """
		seems like rasa will stop listening once conversation
		is paused, which means no actions are attempted, therefore
		preventing triggering ConversationResumed() in a straightforward way.
		"""
        tracker.update(ConversationPaused())
        message = ""
        while message != "/unpause":
            url = "http://127.0.0.1:5000/handoff/{}".format(tracker.sender_id)
            req = requests.get(url)
            resp = json.loads(req.text)
            if "error" in resp:
                raise Exception("Error fetching message: " +
                                repr(resp["error"]))
            message = resp["message"]
            if message != "/unpause":
                dispatcher.utter_message("Human agent: {}".format(message))

        tracker.update(ConversationResumed())
예제 #3
0

@pytest.mark.parametrize("one_event,another_event", [
    (UserUttered("/greet", {
        "name": "greet",
        "confidence": 1.0
    }, []), UserUttered("/goodbye", {
        "name": "goodbye",
        "confidence": 1.0
    }, [])),
    (TopicSet("my_topic"), TopicSet("my_other_topic")),
    (SlotSet("my_slot", "value"), SlotSet("my__other_slot", "value")),
    (Restarted(), None),
    (AllSlotsReset(), None),
    (ConversationPaused(), None),
    (ConversationResumed(), None),
    (StoryExported(), None),
    (ActionReverted(), None),
    (ActionExecuted("my_action"), ActionExecuted("my_other_action")),
    (BotUttered("my_text",
                "my_data"), BotUttered("my_other_test", "my_other_data")),
    (ReminderScheduled("my_action",
                       "now"), ReminderScheduled("my_other_action", "now")),
])
def test_event_has_proper_implementation(one_event, another_event):
    # equals tests
    assert one_event != another_event, \
        "Same events with different values need to be different"
    assert one_event == deepcopy(one_event), \
        "Event copies need to be the same"
    assert one_event != 42, \
예제 #4
0
    (TopicSet("my_topic"),
     TopicSet("my_other_topic")),

    (SlotSet("my_slot", "value"),
     SlotSet("my__other_slot", "value")),

    (Restarted(),
     None),

    (AllSlotsReset(),
     None),

    (ConversationPaused(),
     None),

    (ConversationResumed(),
     None),

    (StoryExported(),
     None),

    (ActionReverted(),
     None),

    (ActionExecuted("my_action"),
     ActionExecuted("my_other_action")),

    (BotUttered("my_text", "my_data"),
     BotUttered("my_other_test", "my_other_data")),

    (ReminderScheduled("my_action", "now"),
예제 #5
0
    def say(self, request, cid):

        self.setHeaders(request)

        message, = request.args.get(b"message", [])
        _payload = request.args.get(b"payload", [])
        _display_name = request.args.get(b"display_name", [])
        _uuid = request.args.get(b"uuid", [])
        logger.info(message)

        message = message.decode("utf-8")

        output_channel = BotServerOutputChannel(self.message_store)

        if message == "_restart":
            self.message_store.clear(cid)
        else:
            if len(_uuid) > 0:
                self.message_store.log(
                    cid,
                    cid,
                    {
                        "type": "text",
                        "text": message
                    },
                    _uuid[0].decode("utf-8"),
                )
            else:
                self.message_store.log(cid, cid, {
                    "type": "text",
                    "text": message
                })

        tracker = self.agent.tracker_store.get_or_create_tracker(cid)
        paused_flag = tracker.is_paused()

        logger.info(tracker.current_state())
        logger.info("message is %s" % message)

        if len(_payload) > 0:
            logger.info("using payload")
            self.on_message(
                UserMessage(
                    _payload[0].decode("utf-8"),
                    output_channel=output_channel,
                    sender_id=cid,
                ))
        else:
            logger.info("using message")
            self.on_message(
                UserMessage(
                    message,
                    output_channel=output_channel,
                    sender_id=cid,
                ))

        tracker = self.agent.tracker_store.get_or_create_tracker(cid)
        intent = tracker.latest_message.intent
        logger.info(intent)

        if output_channel.questionnaireInterrupt is not None:
            paused_flag = True
            message = output_channel.questionnaireInterrupt
            output_channel.questionnaireInterrupt = None

        if paused_flag:

            dname_cookie = request.getCookie(b'dialogue_name')
            dname_val_is_None = False if dname_cookie is None else jwt.decode(
                request.getCookie(b'dialogue_name'),
                '@TODO Secret',
                algorithm='HS256')['name'] == 'None'

            dg_is_valid = True

            if dname_cookie is None or dname_val_is_None:

                flag, type = self.dialogue_handler.check_dialogue_exists(
                    message)

                if flag:
                    dialogueName = message
                    dialogue_name = jwt.encode({'name': message},
                                               '@TODO Secret',
                                               algorithm='HS256')
                    request.addCookie(b'dialogue_name', dialogue_name)
                else:
                    errorChoosingDialogue = random.choice(self.DIALOGUE_ERRORS)
                    logger.info(errorChoosingDialogue)
                    output_channel.send_text_message(cid,
                                                     errorChoosingDialogue)
                    dg_is_valid = False
            else:
                dialogueName = jwt.decode(request.getCookie(b'dialogue_name'),
                                          '@TODO Secret',
                                          algorithm='HS256')['name']
                logger.info(dialogueName)

            if dg_is_valid:

                currentPointInDialogue = self.getCurrentPointInDialogue(
                    request)

                try:
                    newPointInDialogue = self.dialogue_handler.handle_dialogue(
                        dialogueName, currentPointInDialogue, output_channel,
                        cid, message, intent['name'])
                except:
                    newPointInDialogue = "finished"

                if newPointInDialogue is not "finished":  # just increment the step
                    logger.info("incrementing step cookie")
                    self.resetCookie(request, 'dialogue_step',
                                     'pointInDialogue', newPointInDialogue)
                else:  ## unpause the tracker
                    logger.info("dialogue is finished")
                    events = [ConversationResumed()]

                    action_name = "special_resume_action_name"
                    if action_name is not None:
                        tracker.update(ActionExecuted(action_name))

                    for e in events:
                        tracker.update(e)

                    self.agent.tracker_store.save(tracker)

                    self.resetCookie(request, 'dialogue_name', 'name', 'None')
                    self.resetCookie(request, 'dialogue_step',
                                     'pointInDialogue', 'None')