def FavouriteBoardgame(self, hermes: Hermes,
                        intent_message: IntentMessage):
     hermes.publish_end_session(intent_message.session_id, "")
     favouriteBoardgame = self.apiHandler.getMostPlayedBoardgame()
     hermes.publish_start_session_notification(
         intent_message.site_id,
         "Votre jeu préféré est {}".format(favouriteBoardgame), "")
    def RepeatThrowCallback(self, hermes: Hermes,
                            intent_message: IntentMessage):
        hermes.publish_end_session(intent_message.session_id, "")

        answer = self.GenerateAnswer(self.last_number, self.last_type)
        hermes.publish_start_session_notification(intent_message.site_id,
                                                  answer, "")
Exemple #3
0
    def intent_1_callback(hermes: Hermes, intent_message: IntentMessage):
        # terminate the session first if not continue

        # action code goes here...
        intentname = intent_message.intent.intent_name
        if intentname == "atesfa:info":
            hermes.publish_end_session(intent_message.session_id, "Info")
 def PossessedBoardgames(self, hermes: Hermes,
                         intent_message: IntentMessage):
     hermes.publish_end_session(intent_message.session_id, "")
     numberOfOwnedBoardgames = self.apiHandler.getNumberOfBoardgames()
     hermes.publish_start_session_notification(
         intent_message.site_id,
         "Vous possédez {} jeux".format(numberOfOwnedBoardgames), "")
Exemple #5
0
    def makeCoffee(self, hermes: Hermes, intent_message: IntentMessage):

        current_session_id = intent_message.session_id
        formatoCoffe_slot = intent_message.slots.coffeeFormat.first(
        ).value or coffee_dict_slot['formatoCoffe']
        tipoCoffe_slot = intent_message.slots.coffeeType.first(
        ).value or coffee_dict_slot['tipoCoffe']

        coffee_dict_slot['formatoCoffe'] = formatoCoffe_slot
        coffee_dict_slot['tipoCoffe'] = tipoCoffe_slot

        if not formatoCoffe_slot:
            result_sentence = "Certo! Come lo preferisci? Corto,lungo o espresso?"
            return hermes.publish_continue_session(current_session_id,
                                                   result_sentence,
                                                   [MAKE_COFFE])

        if not tipoCoffe_slot:
            result_sentence = "Come lo preferisci? Schiumato,macchiato o decaffeinato?"
            return hermes.publish_continue_session(current_session_id,
                                                   result_sentence,
                                                   [MAKE_COFFE])

        result_sentence = "Caffè {} {} in preparazione.".format(
            tipoCoffe_slot, formatoCoffe_slot)
        coffee_dict_slot['formatoCoffe'] = None
        coffee_dict_slot['tipoCoffe'] = None
        hermes.publish_end_session(current_session_id, result_sentence)
    def GiveLastThrowParamsCallback(self, hermes: Hermes,
                                    intent_message: IntentMessage):
        hermes.publish_end_session(intent_message.session_id, "")

        hermes.publish_start_session_notification(
            intent_message.site_id,
            "J'ai lancé {} dés {}".format(self.last_number,
                                          self.last_type), "")
    def HeadsOrTailsCallback(self, hermes: Hermes,
                             intent_message: IntentMessage):
        hermes.publish_end_session(intent_message.session_id, "")

        heads = random.randint(0, 1)
        answer = "Face" if heads == 1 else "Pile"

        hermes.publish_start_session_notification(intent_message.site_id,
                                                  answer, "")
Exemple #8
0
def on_message(client, userdata, msg):
	print('On message')
	print(msg.topic)
	intent_json = json.loads(msg.payload)
	input = intent_json['input']
	slots = intent_json['slots']
	val = processing(slots)
	result = searchInWiki(val)
	Hermes.publish_end_session(msg.session_id, result)
    def ElicitNumPlayersCallback(self, hermes: Hermes,
                                 intent_message: IntentMessage):
        hermes.publish_end_session(intent_message.session_id, "")

        num_players = extractSlot(intent_message.slots, "numberOfPlayers")
        boardgames = self.apiHandler.getRandomBoardgames(
            num_players, int(intent_message.custom_data))
        hermes.publish_start_session_notification(
            intent_message.site_id,
            self.GenerateBoardgamesAnswer(boardgames, num_players), "")
Exemple #10
0
    def intent_2_callback(hermes: Hermes, intent_message: IntentMessage):

        # terminate the session first if not continue
        hermes.publish_end_session(intent_message.session_id, "")

        # action code goes here...
        print('[Received] intent: {}'.format(
            intent_message.intent.intent_name))

        # if need to speak the execution result by tts
        hermes.publish_start_session_notification(intent_message.site_id,
                                                  "Action 2", "")
Exemple #11
0
    def makeTea(self, hermes: Hermes, intent_message: IntentMessage):

        current_session_id = intent_message.session_id
        formatoTea_slot = intent_message.slots.teaFormat.first().value

        if not formatoTea_slot:
            result_sentence = "Certo! Come lo preferisci? Grande, medio o piccolo?"
            return hermes.publish_continue_session(current_session_id,
                                                   result_sentence, [MAKE_TEA])

        result_sentence = "Tè {} in preparazione.".format(formatoTea_slot)
        hermes.publish_end_session(current_session_id, result_sentence)
    def tell_joke(self, hermes: Hermes, intent_message: IntentMessage):

        # terminate the session first if not continue
        hermes.publish_end_session(intent_message.session_id, "")

        # action code goes here...
        print("[Received] intent: {}".format(
            intent_message.intent.intent_name))

        # if need to speak the execution result by tts
        hermes.publish_start_session_notification(intent_message.site_id,
                                                  self.joke_service.get_joke(),
                                                  "")
Exemple #13
0
    def makeChoc(self, hermes: Hermes, intent_message: IntentMessage):

        current_session_id = intent_message.session_id
        formatoChoc_slot = intent_message.slots.chocFormat.first().value

        if not formatoChoc_slot:
            result_sentence = "Certo! Come la preferisci? Grande, media o piccola?"
            return hermes.publish_continue_session(current_session_id,
                                                   result_sentence,
                                                   [MAKE_CHOC])

        result_sentence = "Cioccolata {} in preparazione.".format(
            formatoChoc_slot)
        hermes.publish_end_session(current_session_id, result_sentence)
    def addition_callback(hermes: Hermes, intent_message: IntentMessage):

        # terminate the session first if not continue
        hermes.publish_end_session(intent_message.session_id, "")

        # action code goes here...
        print('[Received] intent: {}'.format(
            intent_message.intent.intent_name))

        # if need to speak the execution result by tts
        hermes.publish_start_session_notification(
            intent_message.site_id,
            "Enfin, qulqu'un me donne du travail. Merci beaucoup!!!",
            "Calculatrice_APP")
    def ThrowDiceCallback(self, hermes: Hermes, intent_message: IntentMessage):
        hermes.publish_end_session(intent_message.session_id, "")

        numberOfDicesSlot = extractSlot(intent_message.slots, "numberOfDices")
        numberOfDices = numberOfDicesSlot if numberOfDicesSlot != None else 1
        self.last_number = numberOfDices

        diceTypeSlot = extractSlot(intent_message.slots, "diceType")
        diceType = diceTypeSlot if diceTypeSlot != None else 6
        self.last_type = diceType

        answer = self.GenerateAnswer(numberOfDices, diceType)
        hermes.publish_start_session_notification(intent_message.site_id,
                                                  answer, "")
    def common(self, script: str, hermes: Hermes, intent_message: IntentMessage):
        hermes.publish_end_session(intent_message.session_id, "")

        url = "{}/services/script/turn_on".format(self.config[HASS].get(API_URL))
        headers = {
            "Authorization": "Bearer {}".format(self.config[HASS].get(AUTH_TOKEN)),
            "Content-Type": "application/json",
        }
        post_data = {"entity_id": "script.{}".format(script)}

        resp = requests.post(url, headers=headers, json=post_data)
        if resp.status_code != 200:
            print(
                "[Error] Request to {} returned: '{} {}'".format(
                    url, resp.status_code, resp.reason
                )
            )
Exemple #17
0
    def play_track(hermes: Hermes, intent_message: IntentMessage):

        # terminate the session first if not continue
        hermes.publish_end_session(intent_message.session_id, "")

        # action code goes here...
        logger.info("[Received] intent: {}".format(
            intent_message.intent.intent_name))
        logger.info("[Received] slots: {} / {}".format(
            intent_message.slots.keys(), intent_message.slots.values()))

        searched_track = "obladi oblada"
        if len(intent_message.slots.musicTrack) > 0:
            searched_track = intent_message.slots.musicTrack.first().value

        track_id = DeezerApp.get_deezer_id(searched_track)

        # if need to speak the execution result by tts
        hermes.publish_start_session_notification(intent_message.site_id,
                                                  str(track_id), "")
    def PickRandomBoardgameCallback(self, hermes: Hermes,
                                    intent_message: IntentMessage):
        num_players_slot = extractSlot(intent_message.slots, "numberOfPlayers")
        num_boardgames_slot = extractSlot(intent_message.slots,
                                          "numberOfPropositions")
        numberOfBoardgames = num_boardgames_slot if num_boardgames_slot else self.numberOfBoardgames

        if not num_players_slot:
            return hermes.publish_continue_session(
                intent_message.session_id,
                required_slots_questions["num_players"],
                ["hjwk:ElicitNumPlayers"],
                custom_data=str(numberOfBoardgames))

        hermes.publish_end_session(intent_message.session_id, "")

        boardgames = self.apiHandler.getRandomBoardgames(
            num_players_slot, numberOfBoardgames)
        hermes.publish_start_session_notification(
            intent_message.site_id,
            self.GenerateBoardgamesAnswer(boardgames, num_players_slot), "")
Exemple #19
0
class Assistant:
    def __init__(self):
        self.intents = {}
        self.last_message = None

        snips_config = toml.load('/etc/snips.toml')

        mqtt_username = None
        mqtt_password = None
        mqtt_broker_address = "localhost:1883"

        if 'mqtt' in snips_config['snips-common'].keys():
            mqtt_broker_address = snips_config['snips-common']['mqtt']
        if 'mqtt_username' in snips_config['snips-common'].keys():
            mqtt_username = snips_config['snips-common']['mqtt_username']
        if 'mqtt_password' in snips_config['snips-common'].keys():
            mqtt_password = snips_config['snips-common']['mqtt_password']

        mqtt_opts = MqttOptions(username=mqtt_username,
                                password=mqtt_password,
                                broker_address=mqtt_broker_address)

        self.hermes = Hermes(mqtt_options=mqtt_opts)
        self.conf = read_configuration_file()

        if 'OPENHAB_SERVER_URL' in environ:
            self.conf['secret']['openhab_server_url'] = environ.get(
                'OPENHAB_SERVER_URL')
        if 'OPENHAB_DEFAULT_ROOM' in environ:
            self.conf['secret']['default_room'] = environ.get(
                'OPENHAB_DEFAULT_ROOM')
        if 'OPENHAB_SITEID2ROOM_MAPPING' in environ:
            self.conf['secret']['siteid2room_mapping'] = environ.get(
                'OPENHAB_SITEID2ROOM_MAPPING')
        if 'OPENHAB_SOUND_FEEDBACK' in environ:
            self.conf['secret']['sound_feedback'] = environ.get(
                'OPENHAB_SOUND_FEEDBACK')

        self.sound_feedback = self.conf['secret']["sound_feedback"] == "on"

    def add_callback(self, intent_name, callback):
        self.intents[intent_name] = callback

    def register_sound(self, sound_name, sound_data):
        self.hermes.register_sound(RegisterSoundMessage(
            sound_name, sound_data))

    def callback(self, intent_message):
        intent_name = intent_message.intent.intent_name

        if intent_name in self.intents:
            success, message = self.intents[intent_name](self, intent_message,
                                                         self.conf)

            self.last_message = message

            if self.sound_feedback:
                if success is None:
                    self.hermes.publish_end_session(intent_message.session_id,
                                                    message)
                elif success:
                    self.hermes.publish_end_session(intent_message.session_id,
                                                    "[[sound:success]]")
                else:
                    # TODO: negative sound
                    self.hermes.publish_end_session(intent_message.session_id,
                                                    message)
            else:
                self.hermes.publish_end_session(intent_message.session_id,
                                                message)

    def inject(self, entities):
        self.hermes.request_injection(
            InjectionRequestMessage([AddFromVanillaInjectionRequest(entities)
                                     ]))

    def __enter__(self):
        self.hermes.connect()
        return self

    def __exit__(self, exception_type, exception_val, trace):
        if not exception_type:
            self.hermes.disconnect()
            return self
        return False

    def start(self):
        def helper_callback(hermes, intent_message):
            self.callback(intent_message)

        with open(path.join(path.dirname(__file__), 'success.wav'), 'rb') as f:
            self.register_sound("success", bytearray(f.read()))

        self.hermes.subscribe_intents(helper_callback)
        self.hermes.start()