简体   繁体   English

在 AWS Lambda function 中获取插槽的问题

[英]Problems getting slot in AWS Lambda function

I am trying to build a simple Alexa Skill.我正在尝试构建一个简单的 Alexa Skill。 Now, I want to access some of my slot values.现在,我想访问我的一些插槽值。 This is my code.这是我的代码。 When I uncomment even the line that I define Alexa in, my skill will not work.当我取消注释我定义 Alexa 的行时,我的技能将不起作用。 Also, if I only uncomment the line defining var text, I still get "there was a problem with the skills response".另外,如果我只取消注释定义 var text 的行,我仍然会得到“技能响应有问题”。 Const gives the same output. const 给出相同的 output。 I am using custom slots called recipe.我正在使用称为配方的自定义插槽。 How can I access the slots in my lambda function?如何访问 lambda function 中的插槽? Thanks.谢谢。

 const breakfast = { "bacon and eggs":["bacon","egg"], "buttered toast":["bread", "butter"] }; const lunch = { "ham sandwich":["ham","cheese"] }; const dinner = { "Steak and eggs": ['steak','eggs']}; //const Alexa = require('ask-sdk-core'); exports.handler = (event, context, callback) => { try { if (event.request.type === 'LaunchRequest') { callback(null, buildResponse('Hello from Lambda')); } else if (event.request.type === 'IntentRequest') { const intentName = event.request.intent.name; if (intentName === 'breakfast') { callback(null, buildResponse(Object.keys(breakfast)+"") ); } else if (intentName === 'lunch') { callback(null, buildResponse(Object.keys(lunch)+"") ); } else if (intentName === 'dinner') { callback(null, buildResponse(Object.keys(dinner)+"") ); } else if (intentName ==='requestRecipe'){ //var text = this.event.request.intent.slots.recipe.value; //const meal = Alexa.getSlotValue(intentName, "meal") callback(null, buildResponse("Recipe requested") ); } else { callback(null, buildResponse("Sorry, i don't understand")); } } else if (event.request.type === 'SessionEndedRequest') { callback(null, buildResponse('Session Ended')); } } catch (e) { context.fail(`Exception: ${e}`); } }; function buildResponse(response) { return { version: '1.0', response: { outputSpeech: { type: 'PlainText', text: response, }, shouldEndSession: false, }, sessionAttributes: {}, }; }

for a bit of context: my lambda has the endpoint of what my alexa hosted skill was, and the alexa skill has the endpoint of the lambda.对于一些上下文:我的 lambda 具有我的 alexa 托管技能的端点,而 alexa 技能具有 lambda 的端点。 when I say const gives the same output, i mean instead of using var, when I use const, it does the same thing.当我说 const 给出相同的 output 时,我的意思是当我使用 const 时,它会做同样的事情,而不是使用 var。 The JSON file that i get as a reply is empty brackets.我得到的 JSON 文件是空括号。

I found the issue behind my problem.我发现了我的问题背后的问题。 Instead of using而不是使用
//var text = this .event.request.intent.slots.recipe.value; //var text = this .event.request.intent.slots.recipe.value; i simply did var text = event.request.intent.slots.recipe.value;我只是做了 var text = event.request.intent.slots.recipe.value; I am now able to use text in building a response or something like that.我现在可以使用文本来构建响应或类似的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM