【问题标题】:How do I tell Alexa to prompt user for input如何告诉 Alexa 提示用户输入
【发布时间】:2020-06-04 04:13:20
【问题描述】:

我需要告诉 alexa 提示用户输入,然后将该输入存储在我的代码中使用的变量中。

InvocationName:发送邮件

Alexa:告诉我邮件主题

用户:测试邮箱

Alexa:好的,告诉我消息正文。

用户:这只是一个示例测试

Alexa,好的,告诉我接收者的电子邮件

用户:test@gmail.com

以下是我的意图架构:

{
    "interactionModel": {
        "languageModel": {
            "invocationName": "send mail",
            "intents": [
                {
                    "name": "AMAZON.CancelIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.HelpIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.StopIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.FallbackIntent",
                    "samples": []
                },
                {
                    "name": "AMAZON.NavigateHomeIntent",
                    "samples": []
                },
                {
                    "name": "SendMailIntent",
                    "slots": [
                        {
                            "name": "ReceiverEmail",
                            "type": "AMAZON.SearchQuery"
                        }
                    ],
                    "samples": [
                        "mail",
                        "send mail"
                    ]
                }
            ],
            "types": []
        },
        "dialog": {
            "intents": [
                {
                    "name": "SendMailIntent",
                    "confirmationRequired": false,
                    "prompts": {},
                    "slots": [
                        {
                            "name": "ReceiverEmail",
                            "type": "AMAZON.SearchQuery",
                            "confirmationRequired": false,
                            "elicitationRequired": true,
                            "prompts": {
                                "elicitation": "Elicit.Slot.838288524310.965699312002"
                            }
                        }
                    ]
                }
            ],
            "delegationStrategy": "ALWAYS"
        },
        "prompts": [
            {
                "id": "Elicit.Slot.838288524310.965699312002",
                "variations": [
                    {
                        "type": "PlainText",
                        "value": "Enter subject"
                    }
                ]
            }
        ]
    }
}


and below is the code I have been able to come up with:

// sets up dependencies
const Alexa = require('ask-sdk-core');
const i18n = require('i18next');
const languageStrings = require('./languageStrings');


const SendMailHandler = {
  canHandle(handlerInput) {
   const request = handlerInput.requestEnvelope.request;
   // var code = this.event.request.intent.slots.code.value;
    //console.log(code)

    // checks request type
    return request.type === 'LaunchRequest'
      || (request.type === 'IntentRequest'
        && request.intent.name === 'SendMailIntent');
  },
  handle(handlerInput) {
    const speechText = 'Ok. Tell me the mail subject'

    const response =  handlerInput.responseBuilder
      .speak(speechText)
      .reprompt(speechText) // <--- Here is our reprompt
      .getResponse();
      console.log(response)
      return response;
  },
};

// Omitted default Alexa handlers
const skillBuilder = Alexa.SkillBuilders.custom();

exports.handler = skillBuilder
  .addRequestHandlers(
   SendMailHandler,
  )
  .lambda();

【问题讨论】:

    标签: aws-lambda alexa alexa-skills-kit alexa-skill alexa-slot


    【解决方案1】:

    您应该使用带有 2 个插槽的 dialog management

    正如我所见,目前您只收集一个带有对话管理的插槽(ReceiverEmail)。 但是您还需要为要发送的文本创建一个插槽。 稍后在您的代码中,您需要检查对话是否处于 COMPLETED 状态。

    查看示例 https://github.com/alexa/skill-sample-nodejs-petmatch/ 或此视频:https://www.youtube.com/watch?v=u99WMljnQXI

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-03
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多