def onSessionStarted(self, session: DialogSession): self.changeFeedbackSound(inDialog=True, siteId=session.siteId) if self.ThreadManager.getEvent( 'authUser').isSet() and session.currentState != 'userAuth': self.SnipsServicesManager.toggleFeedbackSound(state='on') user = self.UserManager.getUser(session.user) if user == constants.UNKNOWN_USER: self.endDialog(sessionId=session.sessionId, text=self.randomTalk('userAuthUnknown')) elif self.UserManager.hasAccessLevel(session.user, AccessLevel.ADMIN): # End the session immediately because the ASR is listening to the previous wakeword call self.endSession(sessionId=session.sessionId) AdminAuth.setUser(user) #Delay a greeting as the user might already by authenticated through cookies self.ThreadManager.doLater(interval=0.75, func=self.greetAndAskPin, args=[session]) else: self.endDialog( sessionId=session.sessionId, text=self.randomTalk('userAuthAccessLevelTooLow')) elif session.currentState == 'userAuth': AdminAuth.setLinkedSnipsSession(session)
def explainInterfaceAuth(self): AdminAuth.setUser(None) self.ThreadManager.clearEvent('authUser') self.ThreadManager.newEvent('authUserWaitWakeword').set() self.SnipsServicesManager.toggleFeedbackSound(state='off') self.say(text=self.randomTalk('explainInterfaceAuth'), canBeEnqueued=False)
def onSessionStarted(self, session: DialogSession): self.changeFeedbackSound(inDialog=True, siteId=session.siteId) if self.ThreadManager.getEvent('authUser').isSet( ) and session.currentState != DialogState('userAuth'): self.SnipsServicesManager.toggleFeedbackSound(state='on') user = self.UserManager.getUser(session.user) if user == constants.UNKNOWN_USER: self.endDialog(sessionId=session.sessionId, text=self.randomTalk('userAuthUnknown')) elif self.UserManager.hasAccessLevel(session.user, AccessLevel.ADMIN): # End the session immediately because the ASR is listening to the previous wakeword call self.endSession(sessionId=session.sessionId) AdminAuth.setUser(user) #Delay a greeting as the user might already by authenticated through cookies self.ThreadManager.doLater(interval=0.75, func=self.greetAndAskPin, args=[session]) else: self.endDialog( sessionId=session.sessionId, text=self.randomTalk('userAuthAccessLevelTooLow')) elif session.currentState == DialogState('userAuth'): AdminAuth.setLinkedSnipsSession(session) elif self.ThreadManager.getEvent( 'TuningWakewordUpWakewordCaught').is_set(): if self.wakewordTuningFailedTimer: self.wakewordTuningFailedTimer.cancel() self.ThreadManager.clearEvent('TuningWakewordUpWakewordCaught') self.endSession(sessionId=session.sessionId) self.say(text=self.randomTalk(text='tuneWakewordUpWorked')) self.SnipsServicesManager.toggleFeedbackSound(state='on') elif self.ThreadManager.getEvent( 'TuningWakewordDownWakewordCaught').is_set(): if self.wakewordTuningFailedTimer: self.wakewordTuningFailedTimer.cancel() self.ThreadManager.clearEvent('TuningWakewordDownWakewordCaught') self.endSession(sessionId=session.sessionId) sensitivity = self.WakewordManager.getUserWakewordSensitivity( session.user) if sensitivity + 0.03 < 0.2: self.ThreadManager.clearEvent('TuningWakewordUp') self.say(text=self.randomTalk('tuneWakewordStop')) self.SnipsServicesManager.toggleFeedbackSound(state='on') return self.WakewordManager.setUserWakewordSensitivity( username=session.user, sensitivity=sensitivity - 0.03) self.say(text=self.randomTalk(text='tuneWakewordDownFailed'), customData={'username': session.user})
def greetAndAskPin(self, session: DialogSession): if not AdminAuth.getUser( ).isAuthenticated and self.ThreadManager.getEvent('authUser').isSet(): self.ask(text=self.randomTalk('greetAndNeedPinCode', replace=[session.user]), siteId=session.siteId, intentFilter=[self._INTENT_ANSWER_NUMBER], currentDialogState='userAuth', customData={'user': session.user.lower()})