Example #1
0
    def test_dialogue_configuration_local_site_id(self):
        conf = DialogueConfiguration(site_id="kitchen")
        conf\
            .disable_intent("intent_1", site_id="bedroom")

        dialogue_configure_message = conf.build()[0]
        assert dialogue_configure_message.site_id == "bedroom"
        assert len(dialogue_configure_message.intents) == 1
Example #2
0
    def test_dialogue_configuration_multiple_site_ids3(self):
        conf = DialogueConfiguration(site_id="bathroom")
        conf \
            .disable_intent("intent_2") \
            .disable_intent("intent_2", site_id="kitchen")

        dialogue_configure_messages = conf.build()
        assert dialogue_configure_messages[0].site_id == "bathroom"
        assert dialogue_configure_messages[1].site_id == "kitchen"
Example #3
0
    def test_dialogue_configuration_multiple_site_ids2(self):
        conf = DialogueConfiguration()
        conf \
            .disable_intent("intent_1") \
            .disable_intent("intent_1", site_id="kitchen")

        dialogue_configure_messages = conf.build()
        assert dialogue_configure_messages[0].site_id is None
        assert dialogue_configure_messages[1].site_id == "kitchen"
Example #4
0
    def test_dialogue_configuration_global_site_id(self):
        conf = DialogueConfiguration()
        conf\
            .for_site_id("kitchen")\
            .disable_intent("intent_1")

        dialogue_configure_message = conf.build()[0]
        assert dialogue_configure_message.site_id == "kitchen"
        assert len(dialogue_configure_message.intents) == 1
Example #5
0
    def test_dialogue_configuration_toggling_intent(self):
        conf = DialogueConfiguration()
        conf\
            .disable_intent("intent_2") \
            .enable_intent("intent_2")  \
            .disable_intent("intent_2") \
            .enable_intent("intent_2")

        dialogue_configure_messages = conf.build()
        assert dialogue_configure_messages[0].intents[0].enable
Example #6
0
    def test_dialogue_configuration_disabling_intents(self):
        conf = DialogueConfiguration()
        conf.disable_intents(["intent_1", "intent_2"])

        dialogue_configure_messages = conf.build()
        assert len(dialogue_configure_messages) == 1

        dialogue_configure_message = dialogue_configure_messages[0]

        assert dialogue_configure_message.site_id is None
        assert len(dialogue_configure_message.intents) == 2
Example #7
0
    def test_dialogue_configuration_disabling_intent(self):
        conf = DialogueConfiguration()
        conf.disable_intent("intent_1")

        dialogue_configure_messages = conf.build()
        assert len(dialogue_configure_messages) == 1

        dialogue_configure_message = dialogue_configure_messages[0]

        assert dialogue_configure_message.site_id is None
        assert len(dialogue_configure_message.intents) == 1
        assert dialogue_configure_message.intents[0].intent_id == "intent_1"
        assert not dialogue_configure_message.intents[0].enable
Example #8
0
def intent_not_recognized_callback(hermes, intent_message):
    configure_message = DialogueConfiguration().disable_intent(
        add_prefix("confirmFreezerList"))
    hermes.configure_dialogue(configure_message)
    shoppinglist.wanted_intents = []
    hermes.publish_end_session({
        'sessionId':
        intent_message.session_id,
        'text':
        "Die Tiefkühlliste wurde nicht gelöscht."
    })
Example #9
0
    def quiet(self, hermes, intent_message):
        """Handle the intent Quiet."""

        # Get all the intents from the assistant and remove the one to talk
        # again.
        intents = [intent['id'] for intent in self.assistant['intents']]
        intents.remove(i18n.INTENT_TALK)

        dialogue_conf = DialogueConfiguration().disable_intents(intents) \
                                               .enable_intent(i18n.INTENT_TALK)
        hermes.configure_dialogue(dialogue_conf)

        hermes.publish_end_session(intent_message.session_id,
                                   i18n.RESULT_QUIET)
Example #10
0
    def enable_disable_intent(self, hermes, intent_message, action):
        """"Enable or disable an intent.

        The argument `action` can be 'enable' or 'disable'.
        """
        intent = intent_message.slots.intent.first().value
        intent_id = self.intent_id_from_name(intent)

        function = getattr(DialogueConfiguration(), action + '_intent')
        dialogue_conf = function(intent_id)
        hermes.configure_dialogue(dialogue_conf)

        hermes.publish_end_session(
            intent_message.session_id,
            getattr(i18n,
                    'RESULT_' + action.upper() + '_INTENT').format(intent))
Example #11
0
def intent_callback(hermes, intent_message):
    # conf = read_configuration_file(CONFIG_INI)
    intentname = intent_message.intent.intent_name
    if intentname == add_prefix("addFreezerListItem"):
        result_sentence = shoppinglist.add_item(intent_message)
        hermes.publish_end_session(intent_message.session_id, result_sentence)

    elif intentname == add_prefix("removeFreezerListItem"):
        result_sentence = shoppinglist.remove_item(intent_message)
        hermes.publish_end_session(intent_message.session_id, result_sentence)

    elif intentname == add_prefix("isItemOnFreezerList"):
        result_sentence = shoppinglist.is_item(intent_message)
        hermes.publish_end_session(intent_message.session_id, result_sentence)

    elif intentname == add_prefix("clearFreezerList"):
        result_sentence = shoppinglist.try_clear()
        if result_sentence == "empty":
            result_sentence = "Die Tiefkühlliste ist schon leer."
            hermes.publish_end_session(intent_message.session_id,
                                       result_sentence)
        else:
            shoppinglist.wanted_intents = [add_prefix("confirmFreezerList")]
            dialogue_conf = DialogueConfiguration().enable_intent(
                add_prefix("confirmFreezerList"))
            hermes.configure_dialogue(dialogue_conf)
            hermes.subscribe_intent_not_recognized(
                intent_not_recognized_callback)
            hermes.publish_continue_session(intent_message.session_id,
                                            result_sentence,
                                            shoppinglist.wanted_intents)

    elif intentname == add_prefix("confirmFreezerList"):
        shoppinglist.wanted_intents = []
        result_sentence = shoppinglist.clear_confirmed(intent_message)
        hermes.publish_end_session(intent_message.session_id, result_sentence)

    elif intentname == add_prefix("showFreezerList"):
        result_sentence = shoppinglist.show()
        hermes.publish_end_session(intent_message.session_id, result_sentence)

    elif intentname == add_prefix("sendFreezerList"):
        result_sentence = shoppinglist.send()
        hermes.publish_end_session(intent_message.session_id, result_sentence)
Example #12
0
    def talk(self, hermes, intent_message):
        """Handle the intent Talk."""

        # Get all the intents from the assistant that are enabled by default.
        enabled_intents = [
            intent['id'] for intent in self.assistant['intents']
            if intent['enabledByDefault']
        ]

        # Get all the intents from the assistant that are disabled by default.
        disabled_intents = [
            intent['id'] for intent in self.assistant['intents']
            if not intent['enabledByDefault']
        ]

        dialogue_conf = DialogueConfiguration().enable_intents(enabled_intents) \
                                               .disable_intents(disabled_intents)
        hermes.configure_dialogue(dialogue_conf)

        hermes.publish_end_session(intent_message.session_id, i18n.RESULT_TALK)
Example #13
0
def disable_intents(hermes, intents):
    dialogue_conf = DialogueConfiguration().disable_intents(intents)
    hermes.configure_dialogue(dialogue_conf)
Example #14
0
def test_configure_dialogue(mqtt_server):
    from hermes_python.ontology.dialogue import DialogueConfiguration
    conf = DialogueConfiguration()

    with Hermes("localhost:1883") as h:
        h.configure_dialogue(conf)
Example #15
0
def disable_intent(hermes, intents, site_id):
    hermes.configure_dialogue(DialogueConfiguration().disable_intents(
        intents, site_id=site_id))