Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon dynamodb 在Alexa技能上更新项目DynamoDB表时出现问题_Amazon Dynamodb_Alexa_Alexa Skill - Fatal编程技术网

Amazon dynamodb 在Alexa技能上更新项目DynamoDB表时出现问题

Amazon dynamodb 在Alexa技能上更新项目DynamoDB表时出现问题,amazon-dynamodb,alexa,alexa-skill,Amazon Dynamodb,Alexa,Alexa Skill,我试图更新表中的一个项目,该技能只有一个目的,它应该根据条件将项目“状态”更新为“开”或“关” const Alexa = require('ask-sdk'); var AWS = require("aws-sdk"); const dynamoDBTableName = "automation-test"; AWS.config.update({region: "ap-southeast-2"}); const tableName = "automation-test"; var docCl

我试图更新表中的一个项目,该技能只有一个目的,它应该根据条件将项目“状态”更新为“开”或“关”

const Alexa = require('ask-sdk');
var AWS = require("aws-sdk");
const dynamoDBTableName = "automation-test";
AWS.config.update({region: "ap-southeast-2"});
const tableName = "automation-test";
var docClient = new AWS.DynamoDB.DocumentClient();


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


const LivingRoomLightsIntentHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
            && Alexa.getIntentName(handlerInput.requestEnvelope) === 'LivingRoomLightsIntent';
    },
    handle(handlerInput) {

        const LightStatus = handlerInput.requestEnvelope.request.intent.slots.LightStatus.resolutions.resolutionsPerAuthority[0].values[0].value.name;
        const deviceID = "livingRoomLights"

        if (LightStatus === "On") {

            const status = "true"
            const params = {
                TableName: tableName,
                Key: {
                  'deviceID' : deviceID,
                },
                UpdateExpression: 'set status = :s', 
                ExpressionAttributeValues: {
                  ':s' : status
                }
            };

        docClient.update(params, function(err, data) {
            if (err) {
              console.log("Error", err);
            } else {
              console.log("Success", data);
            }
          });

        const speakOutput = `The living room light has been set to ${LightStatus}`;
        return handlerInput.responseBuilder
          .speak(speakOutput)
          .reprompt()
          .getResponse();

        }




         else if (LightStatus === "Off") {

            const status = "false"
            const params = {
                TableName: tableName,
                Key: {
                  'deviceID' : deviceID,
                },
                UpdateExpression: 'set status = :s', 
                ExpressionAttributeValues: {
                  ':s' : status
                }
            };

        docClient.update(params, function(err, data) {
            if (err) {
              console.log("Error", err);
            } else {
              console.log("Success", data);
            }
          });

        const speakOutput = `The living room light has been set to ${LightStatus}`;
        return handlerInput.responseBuilder
          .speak(speakOutput)
          .reprompt()
          .getResponse();
           }
           } 
    };


const HelpIntentHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
            && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.HelpIntent';
    },
    handle(handlerInput) {
        const speakOutput = 'You can say hello to me! How can I help?';

        return handlerInput.responseBuilder
            .speak(speakOutput)
            .reprompt(speakOutput)
            .getResponse();
    }
};
const CancelAndStopIntentHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
            && (Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.CancelIntent'
                || Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.StopIntent');
    },
    handle(handlerInput) {
        const speakOutput = 'Goodbye!';
        return handlerInput.responseBuilder
            .speak(speakOutput)
            .getResponse();
    }
};
const SessionEndedRequestHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'SessionEndedRequest';
    },
    handle(handlerInput) {
        // Any cleanup logic goes here.
        return handlerInput.responseBuilder.getResponse();
    }
};

// The intent reflector is used for interaction model testing and debugging.
// It will simply repeat the intent the user said. You can create custom handlers
// for your intents by defining them above, then also adding them to the request
// handler chain below.
const IntentReflectorHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest';
    },
    handle(handlerInput) {
        const intentName = Alexa.getIntentName(handlerInput.requestEnvelope);
        const speakOutput = `You just triggered ${intentName}`;

        return handlerInput.responseBuilder
            .speak(speakOutput)
            //.reprompt('add a reprompt if you want to keep the session open for the user to respond')
            .getResponse();
    }
};

// Generic error handling to capture any syntax or routing errors. If you receive an error
// stating the request handler chain is not found, you have not implemented a handler for
// the intent being invoked or included it in the skill builder below.
const ErrorHandler = {
    canHandle() {
        return true;
    },
    handle(handlerInput, error) {
        console.log(`~~~~ Error handled: ${error.stack}`);
        const speakOutput = `Sorry, I had trouble doing what you asked. Please try again.`;

        return handlerInput.responseBuilder
            .speak(speakOutput)
            .reprompt(speakOutput)
            .getResponse();
    }
};

// The SkillBuilder acts as the entry point for your skill, routing all request and response
// payloads to the handlers above. Make sure any new handlers or interceptors you've
// defined are included below. The order matters - they're processed top to bottom.
exports.handler = Alexa.SkillBuilders.custom()
    .addRequestHandlers(
        LaunchRequestHandler,
        LivingRoomLightsIntentHandler,
        HelpIntentHandler,
        CancelAndStopIntentHandler,
        SessionEndedRequestHandler,
        IntentReflectorHandler, // make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers
        ) 

        .addErrorHandlers(ErrorHandler)
  .withTableName(dynamoDBTableName)
  .withAutoCreateTable(true)
    .lambda();
这是日志

无法导入模块“索引”:错误位于 Function.Module.\u解析文件名(Module.js:547:15)位于 Function.Module.\在Module.require处加载(Module.js:474:25) (module.js:596:17)at require(internal/module.js:11:18)at 对象(/var/task/index.js:1:77)在模块中 (module.js:652:30)at Object.module._extensions..js (module.js:663:10)在tryModuleLoad的module.load(module.js:565:32)处 (module.js:505:12)在Function.module.\u加载(module.js:497:3)


请帮忙

DynamoDb使用2个唯一ID来检测特定行。
确保您发送的信息正确无误。然后只检测您的行并更新值。

请排除所有不相关的代码。例如,这是alexa问题还是dynamodb问题?您可以通过运行代码来解决这个问题,而无需从alexa触发。如果您可以将代码示例缩减为导致问题的几行代码,您将得到更好的答案,请参见:请向我们展示lambda函数的文件结构!我希望这是因为lambdat中的文件夹结构不正确。文件结构是在开发人员控制台中创建托管Alexa skill时默认创建的原始结构。