def onHotwordDetected(self, client, data, msg):
        siteId = commons.parseSiteId(msg)
        payload = commons.payload(msg)

        if not self._multiDetectionsHolder:
            self.ThreadManager.doLater(interval=0.5,
                                       func=self.handleMultiDetection)

        self._multiDetectionsHolder.append(payload['siteId'])

        user = constants.UNKNOWN_USER
        if payload['modelType'] == 'personal':
            speaker = payload['modelId']
            users = {
                name.lower(): user
                for name, user in self.UserManager.users.items()
            }
            if speaker in users:
                user = users[speaker].name

        self.DialogSessionManager.preSession(siteId, user)
        SuperManager.getInstance().broadcast(method='onHotword',
                                             exceptions=[self.name],
                                             propagateToModules=True,
                                             siteId=siteId)
Example #2
0
 def _updateSessionData(self):
     self._payload = commons.payload(self._message)
     self._slots = {**self._slots, **commons.parseSlots(self._message)}
     self._slotsAsObjects = {
         **self._slotsAsObjects,
         **commons.parseSlotsToObjects(self._message)
     }
     self._customData = {
         **self._customData,
         **commons.parseCustomData(self._message)
     }
    def onSnipsSayFinished(self, client, data, msg: mqtt.MQTTMessage):
        sessionId = commons.parseSessionId(msg)
        payload = commons.payload(msg)

        session = self.DialogSessionManager.getSession(sessionId)
        if session:
            session.payload = payload

        SuperManager.getInstance().broadcast(method='onSayFinished',
                                             exceptions=[self.name],
                                             propagateToModules=True,
                                             session=session)
    def handleMultiDetection(self):
        if len(self._multiDetectionsHolder) <= 1:
            self._multiDetectionsHolder = list()
            return

        sessions = self.DialogSessionManager.sessions
        for sessionId in sessions:
            payload = commons.payload(sessions[sessionId].message)
            if payload['siteId'] != self._multiDetectionsHolder[0]:
                self.endSession(sessionId=sessionId)

        self._multiDetectionsHolder = list()
    def onSnipsSay(self, client, data, msg: mqtt.MQTTMessage):
        sessionId = commons.parseSessionId(msg)
        payload = commons.payload(msg)

        session = self.DialogSessionManager.getSession(sessionId)
        if session:
            session.payload = payload
            siteId = session.siteId
        else:
            siteId = commons.parseSiteId(msg)

        if 'text' in payload:
            module = self.ModuleManager.getModuleInstance('ContextSensitive')
            if module:
                module.addChat(text=payload['text'], siteId=siteId)

        SuperManager.getInstance().broadcast(method='onSay',
                                             exceptions=[self.name],
                                             propagateToModules=True,
                                             session=session)
Example #6
0
	def _parseMessage(self):
		self._payload = commons.payload(self._message)
		self._slots = commons.parseSlots(self._message)
		self._slotsAsObjects = commons.parseSlotsToObjects(self._message)
		self._customData = commons.parseCustomData(self._message)
    def onMessage(self, client, userdata, message: mqtt.MQTTMessage):
        try:
            if message.topic == constants.TOPIC_AUDIO_FRAME:
                SuperManager.getInstance().broadcast(method='onAudioFrame',
                                                     exceptions=[self.name],
                                                     propagateToModules=True,
                                                     message=message)
                return

            if message.topic == constants.TOPIC_INTENT_PARSED:
                return

            siteId = commons.parseSiteId(message)
            payload = commons.payload(message)
            sessionId = commons.parseSessionId(message)

            session = self.DialogSessionManager.getSession(sessionId)
            if session:
                session.update(message)
                if self.MultiIntentManager.processMessage(message):
                    return

            if message.topic == constants.TOPIC_TEXT_CAPTURED and session:
                return

            elif message.topic == constants.TOPIC_ASR_START_LISTENING:
                self.ModuleManager.broadcast('onListening', siteId=siteId)
                return

            elif message.topic == constants.TOPIC_HOTWORD_TOGGLE_ON:
                self.ModuleManager.broadcast('onHotwordToggleOn',
                                             siteId=siteId)
                return

            session = self.DialogSessionManager.getSession(sessionId)
            if not session:
                session = self.DeviceManager.onMessage(message)
                if not session:
                    self._logger.warning(
                        f'[{self.name}] Got a message on ({message.topic}) but nobody knows what to do with it'
                    )
                    self.endDialog(sessionId)
                    return

            redQueen = self.ModuleManager.getModuleInstance('RedQueen')
            if redQueen and not redQueen.inTheMood(session):
                return

            customData = session.customData
            if 'intent' in payload and payload['intent'][
                    'confidenceScore'] < self.ConfigManager.getAliceConfigByName(
                        'probabilityTreshold'):
                if session.notUnderstood < 3:
                    session.notUnderstood = session.notUnderstood + 1

                    self.continueDialog(sessionId=sessionId,
                                        text=self.TalkManager.randomTalk(
                                            'notUnderstood', module='system'))
                else:
                    del session.notUnderstood
                    self.endDialog(sessionId=sessionId,
                                   text=self.TalkManager.randomTalk(
                                       'notUnderstoodEnd', module='system'))
                return

            del session.notUnderstood

            module = self.ModuleManager.getModuleInstance('ContextSensitive')
            if module:
                module.addToMessageHistory(session)

            modules = self.ModuleManager.getModules()
            for modul in modules.values():
                module = modul['instance']
                try:
                    consumed = module.filterIntent(
                        message.topic, session) and module.onMessage(
                            message.topic, session)
                except AccessLevelTooLow:
                    # The command was recognized but required higher access level
                    return

                # Authentication might end the session directly from a module
                if not self.DialogSessionManager.getSession(sessionId):
                    return

                if self.MultiIntentManager.isProcessing(sessionId):
                    self.MultiIntentManager.processNextIntent(sessionId)
                    return

                elif consumed:
                    return

            self._logger.warning(
                f"[{self.name}] Intent \"{message.topic}\" wasn't consumed by any module"
            )
            self.endDialog(sessionId)
        except Exception as e:
            try:
                self._logger.info(traceback.print_exc())
            except:
                pass

            self._logger.error(
                f'[{self.name}] Uncaught error in onMessage: {e}')