在我的交互模型中,我定义了一个名为
city
的插槽,它是可选的,不是必需的,可以实现意图。
我正在使用 python Ask sdk,所以我的处理程序是这样的:
class IntentHandler(RequestHandler):
"""
Intent handler
"""
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return is_request_type("IntentRequest")(handler_input) and \
is_intent_name("ExampleIntent")(handler_input)
def handle(self, handler_input):
# type: (HandlerInput) -> Response
access_token = handler_input.request_envelope.context.system.user.access_token
if access_token is None:
raise Exception("no access_token provided")
speech = RESPONSE_MESSAGE_DEFAULT
handler_input.response_builder.speak(speech)
return handler_input.response_builder.response
如何检查该槽位是否已被用户填充以及如何获取其值?
根据here找到的文档,您可以执行以下操作:
import ask_sdk_core.utils as ask_utils
slot = ask_utils.request_util.get_slot(handler_input, "slot_name")
if slot.value:
# do stuff