【发布时间】:2018-08-20 01:11:03
【问题描述】:
我创建了一个custom alexa skill,其中我有一个intent,名为intentone,这个意图有2 个slots - slotone 和slottwo。当这个意图被调用时,它会调用pythonlambda function。现在从这个python lambda function 我想elicitSlot 为slotone 提供值,在用户提供响应后,然后elcitSlot 为slottwo。
我编写了这段代码,它只是在调用意图后向用户发送一个静态响应,我无法在其中添加 elicitSlot:
##############################
# Builders
##############################
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
def build_PlainSpeech(body):
speech = {}
speech['type'] = 'PlainText'
speech['text'] = body
return speech
def build_response(message, session_attributes={}):
response = {}
response['version'] = '1.0'
response['sessionAttributes'] = session_attributes
response['response'] = message
return response
##############################
# Responses
##############################
def conversation(title, body, session_attributes):
speechlet = {}
speechlet['outputSpeech'] = build_PlainSpeech(body)
speechlet['shouldEndSession'] = False
return build_response(speechlet, session_attributes=session_attributes)
def statement(title, body):
speechlet = {}
speechlet['outputSpeech'] = build_PlainSpeech(body)
speechlet['shouldEndSession'] = True
return build_response(speechlet)
##############################
# Custom Intents
##############################
def intentone(event, context):
session_attributes = {}
respnse = "Would you like to order a large or regular"
return conversation("order_size", respnse,session_attributes)
##############################
# Required Intents
##############################
def cancel_intent():
return statement("CancelIntent", "You want to cancel") #don't use CancelIntent as title it causes code reference error during certification
def help_intent():
return statement("CancelIntent", "You want help") #same here don't use CancelIntent
def stop_intent():
return statement("StopIntent", "You want to stop") #here also don't use StopIntent
##############################
# On Launch
##############################
def on_launch(event, context):
return statement("title", "body")
##############################
# Routing
##############################
def intent_router(event, context):
logger.debug("EVENT REQUEST RECEIVED = {}".format(event))
intent = event['request']['intent']['name']
# Custom Intents
if intent == "intentone":
return intentone(event, context)
# Required Intents
if intent == "AMAZON.CancelIntent":
return cancel_intent()
if intent == "AMAZON.HelpIntent":
return help_intent()
if intent == "AMAZON.StopIntent":
return stop_intent()
##############################
# Program Entry
##############################
def lambda_handler(event, context):
if event['request']['type'] == "LaunchRequest":
return on_launch(event, context)
elif event['request']['type'] == "IntentRequest":
return intent_router(event, context)
我在 python 中四处寻找elicitSlot 示例,但找不到。大多数示例显示Node.js 示例this.emit(),如在此link 中。
如何在 python lambda 函数中实现elicitSlot。一个简单的例子将有助于了解它
【问题讨论】:
标签: python aws-lambda alexa alexa-skills-kit