【问题标题】:alexa how to use elicit slot from python lambda functionalexa如何从python lambda函数中使用elicit slot
【发布时间】:2018-08-20 01:11:03
【问题描述】:

我创建了一个custom alexa skill,其中我有一个intent,名为intentone,这个意图有2 个slots - slotoneslottwo。当这个意图被调用时,它会调用pythonlambda function。现在从这个python lambda function 我想elicitSlotslotone 提供值,在用户提供响应后,然后elcitSlotslottwo

我编写了这段代码,它只是在调用意图后向用户发送一个静态响应,我无法在其中添加 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


    【解决方案1】:

    您好,您必须使用对话功能。不幸的是,我现在没有任何例子。请谷歌一下

    【讨论】:

    • 感谢您尝试帮助 OP!你能用你找到的东西做谷歌搜索和edit your answer吗?否则,我建议您删除您的答案,因为它会吸引反对票。查看tourhow-to-answer page 了解更多关于这里的事情如何运行的信息。非常感谢!
    猜你喜欢
    • 2023-03-18
    • 1970-01-01
    • 2018-03-29
    • 2020-05-23
    • 1970-01-01
    • 2016-04-25
    • 2016-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多