Способ в Python проверить, не ответил ли пользователь?Python

Программы на Python
Ответить
Anonymous
 Способ в Python проверить, не ответил ли пользователь?

Сообщение Anonymous »

Я разрабатываю приложение, позволяющее расширить возможности домашней автоматизации с помощью Alexa. Мой код на Python работает отлично, база данных в MySQL хранится дома, и мои сценарии позволяют мне запускать запрос веб-перехватчика на моем Domotics.
Некоторые из его сценариев запрашивают ответ «да». отсутствие ответа от пользователя; благодаря YesHandler и NoHandler я могу получить ответ.
Однако я не могу найти решение, если пользователь не отвечает. Я могу обнаружить ошибочный ответ благодаря FallbackIntentHandler, но если Alexa не слышит ответ, вызывается только намерение SessionEndedRequestHandler, которое не позволяет мне ответить или задать вопрос еще раз.
В моем handler_input.response_builder я добавил set_should_end_session(False), но без успех.
Мой тестовый код (не моя рабочая версия), он очень простой:
import logging
import ask_sdk_core.utils as ask_utils
import json
from ask_sdk_model.interfaces.alexa.presentation.apl import (
RenderDocumentDirective)

from ask_sdk_core.skill_builder import SkillBuilder
from ask_sdk_core.dispatch_components import AbstractRequestHandler
from ask_sdk_core.dispatch_components import AbstractExceptionHandler
from ask_sdk_core.handler_input import HandlerInput

from ask_sdk_model import Response

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

class LaunchRequestHandler(AbstractRequestHandler):
"""Handler for Skill Launch."""
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool

return ask_utils.is_request_type("LaunchRequest")(handler_input)

def handle(self, handler_input):
# type: (HandlerInput) -> Response
speak_output = ''

return (
handler_input.response_builder
.speak(speak_output)
.ask(speak_output)
.response
)

def handle(self, handler_input):
# type: (HandlerInput) -> Response
speak_output = "Welcome, you can say Hello or Help. Which would you like to try?"

return (
handler_input.response_builder
.speak(speak_output)
.ask(speak_output)
.response
)

class HelloWorldIntentHandler(AbstractRequestHandler):
"""Handler for Hello World Intent."""
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return ask_utils.is_intent_name("HelloWorldIntent")(handler_input)

def handle(self, handler_input):
# type: (HandlerInput) -> Response
speak_output = "Hello World!"

return (
handler_input.response_builder
.speak(speak_output)
.ask("Bonjour Zimko")
.response
)

class DebugIntentHandler(AbstractRequestHandler):
"""Handler for Hello World Intent."""
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return ask_utils.is_intent_name("DebugIntent")(handler_input)

def handle(self, handler_input):
print("In debug intent")
# type: (HandlerInput) -> Response
speak_output = "Hello Debug"
reprompt = "tu veut lancer le test ?"

return (
handler_input.response_builder
.speak(speak_output)
.ask(reprompt)
.set_should_end_session(False)
.response
)

class HelpIntentHandler(AbstractRequestHandler):
"""Handler for Help Intent."""
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return ask_utils.is_intent_name("AMAZON.HelpIntent")(handler_input)

def handle(self, handler_input):
# type: (HandlerInput) -> Response
speak_output = "You can say hello to me! How can I help?"

return (
handler_input.response_builder
.speak(speak_output)
.ask(speak_output)
.response
)

class CancelOrStopIntentHandler(AbstractRequestHandler):
"""Single handler for Cancel and Stop Intent."""
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return (ask_utils.is_intent_name("AMAZON.CancelIntent")(handler_input) or
ask_utils.is_intent_name("AMAZON.StopIntent")(handler_input))

def handle(self, handler_input):
# type: (HandlerInput) -> Response
speak_output = "Goodbye!"

return (
handler_input.response_builder
.speak(speak_output)
.response
)

class FallbackIntentHandler(AbstractRequestHandler):
"""Single handler for Fallback Intent."""
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return ask_utils.is_intent_name("AMAZON.FallbackIntent")(handler_input)

def handle(self, handler_input):
print("In FallbackIntentHandler")
speech = "Hmm, je n'ai pas compris"

return handler_input.response_builder.speak(speech).response

class SessionEndedRequestHandler(AbstractRequestHandler):
"""Handler for Session End."""
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return ask_utils.is_request_type("SessionEndedRequest")(handler_input)

def handle(self, handler_input):
# type: (HandlerInput) -> Response
print("Fin de session")
# Any cleanup logic goes here.
speech = "Fin de session"
return handler_input.response_builder.speak(speech).response

class IntentReflectorHandler(AbstractRequestHandler):
"""The intent reflector is used for interaction model testing and debugging.
It will simply repeat the intent the user said. You can create custom handlers
for your intents by defining them above, then also adding them to the request
handler chain below.
"""
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return ask_utils.is_request_type("IntentRequest")(handler_input)

def handle(self, handler_input):
# type: (HandlerInput) -> Response
intent_name = ask_utils.get_intent_name(handler_input)
speak_output = "You just triggered " + intent_name + "."

return (
handler_input.response_builder
.speak(speak_output)
# .ask("add a reprompt if you want to keep the session open for the user to respond")
.response
)

class CatchAllExceptionHandler(AbstractExceptionHandler):
"""Generic error handling to capture any syntax or routing errors. If you receive an error
stating the request handler chain is not found, you have not implemented a handler for
the intent being invoked or included it in the skill builder below.
"""
def can_handle(self, handler_input, exception):
# type: (HandlerInput, Exception) -> bool
return True

def handle(self, handler_input, exception):
# type: (HandlerInput, Exception) -> Response
logger.error(exception, exc_info=True)

speak_output = "Sorry, I had trouble doing what you asked. Please try again."

return (
handler_input.response_builder
.speak(speak_output)
.ask(speak_output)
.response
)

sb = SkillBuilder()

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(HelloWorldIntentHandler())
sb.add_request_handler(DebugIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(FallbackIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(IntentReflectorHandler()) # make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers

sb.add_exception_handler(CatchAllExceptionHandler())

lambda_handler = sb.lambda_handler()


Подробнее здесь: https://stackoverflow.com/questions/792 ... dnt-answer
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»