简体   繁体   中英

AWS Lambda Function with depending object handler

right now i am trying to build a kind of cross-platform with AWS Lambda. My object handler in Lambda should be able to handle requests from an Alexa Skill and from a Google Action. That why i need a depending handler. The Alexa object handler looks like this:

const skillBuilder = Alexa.SkillBuilders.custom();

exports.handler = skillBuilder
  .addRequestHandlers(
    LaunchRequestHandler,
    HelloWorldIntentHandler
  )
  .addErrorHandlers(ErrorHandler)
  .lambda();

And the Assistant object handler looks like this:

exports.handler = function(event, context, callback) {     
  app.handler(event, {}).then((res) => {
      if (res.status != 200) {
          callback(null, {"fulfillmentText": `I got status code: 
${res.status}`});
      } else {
          callback(null, res.body);
      }
  }).catch((e) => {
  callback(null, {"fulfillmentText": `There was an error\n${e}`});
  });
};

Now i would like to check if the Lambda request comes from Assistant or Alexa and depending on that it should be handled correctly. But so far i am not sure how to do that. do you have any ideas? Thank you in advance!

You are getting to your lambda through API GATEWAY, right? Anyway you should get additional information from the event object.

The API GATEWAY will send all information about the request encapsulated in the event object passing it as an argument to your lambda function. You can then check its properties to see if you get information from where your request is coming from.

You can log the event object like this:

console.log(JSON.stringify(event));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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