在alexa技能中使用aws-sdk

问题描述 投票:0回答:1

我正在尝试开发一种Alexa技能,该技能可以从DynamoDB数据库中获取信息。为了使用它,我必须导入aws-sdk

但是由于某种原因,当我导入它时,我的技能停止了工作。该技能甚至无法打开。我的代码从Alexa开发人员控制台托管。这是发生了什么:

[在测试面板中,当我输入'Open Cricket Update'(应用程序名称)时,Alexa的回答是,'所请求的技能的回答有问题'。仅当我导入aws-sdk时才会发生这种情况。

我在做什么错?

index.js

const Alexa = require('ask-sdk-core');
const AWS = require('aws-sdk');
AWS.config.update({region:'us-east-1'});

const table = 'CricketData';
const docClient = new AWS.DynamoDB.DocumentClient();

const LaunchRequestHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
    },
    handle(handlerInput) {
        const speakOutput = 'Hello! Welcome to cricket update.';
        return handlerInput.responseBuilder
            .speak(speakOutput)
            .reprompt(speakOutput)
            .getResponse();
    }
};

package.json

{
  "name": "hello-world",
  "version": "1.1.0",
  "description": "alexa utility for quickly building skills",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Amazon Alexa",
  "license": "ISC",
  "dependencies": {
    "ask-sdk-core": "^2.6.0",
    "ask-sdk-model": "^1.18.0",
    "aws-sdk": "^2.326.0"
  }
}
amazon-web-services amazon-dynamodb alexa-skills-kit alexa-skill
1个回答
0
投票

[例如,您缺少在index.js末尾的exports.handler块,该块“建立”了由处理程序组成的技能,]]

exports.handler = Alexa.SkillBuilders.custom()
.addRequestHandlers(LaunchRequestHandler)
.lambda();

可以找到更完整的示例here

© www.soinside.com 2019 - 2024. All rights reserved.