7

I am trying to get an Alexa skill (JS/Lambda) to post a value to a REST server using HTTP.request. I am trying to hack together something simple that will get the job done. I think I am missing something obvious.

Ideal Skill Usage

  1. I say, "Alexa, tell Posting Test five."
  2. Alexa updates the value at the URL specified in code to 5.
  3. Alexa says, "I have updated the value to five."

Problems

I have two problems:

  1. Spoken vs. typed utterances. If I type my slot value in the Amazon Service Simulator ("five") the value is posted to my server, as it should be. However, if I speak the same utterance, even though Alexa recognizes the words correctly (confirmed by looking at cards in the app), the value is not posted, and she says, "I can't find the answer to the question."

  2. Where and how to call output function. I think I need to add something like the two lines below, but depending on where I add it in my current code, Alexa either responds without updating the node, or doesn't do anything.

    var text = 'I have updated the value to' + targetSlot;
    output( text, context );
    

Invocation Name

posting test

Intent Schema

{
  "intents": [ {
    "intent": "writeTarget",
    "slots": [ {
       "name": "Target",
       "type": "NUMBER"
    } ]
  }]
}

Sample Utterances

writeTarget {Target}

AlexaSkill.js and index.js

I am using the AlexaSkill.js file that can be found in each example here.

My index.js looks like this. URL, req.write string, etc., are replaced with ****.

exports.handler = function( event, context ) {

    var APP_ID = undefined;

    const http = require( 'http' );

    var AlexaSkill = require('./AlexaSkill');

    var options = {
      host: '****.com',
      path: '/****',
      port: '****',
      method: 'PUT'
    };

    callback = function(response) {
      var str = ''
      response.on('data', function (chunk) {
        str += chunk;
      });

      response.on('end', function () {
        console.log(str);
      });
    };
    var targetSlot = event.request.intent.slots.Target.value;
    var req = http.request(options, callback);
    req.write("****");
    req.end();    
};

function output( text, context ) {

    var answer = {
        outputSpeech: {
            type: "PlainText",
            text: text
        },
        card: {
            type: "Simple",
            title: "System Data",
            content: text
        },
        shouldEndSession: true
    };

    context.succeed( { answer: answer } );

}

Current Usage: A

  1. I type "five" in the Service Simulator.
  2. Node updates but Alexa doesn't say anything.

Current Usage: B

  1. I tell Alexa, "Tell Posting Test two."
  2. Alexa says, "I can't find the answer to the question." Card confirms she heard me correctly.
  3. Nothing gets updated.

Thanks in advance for any help.

Update: Logs

Updating post to add logs:

Error message

{
  "errorMessage": "Process exited before completing request"
}

Log Output Error

TypeError: Cannot read property 'intent' of undefined
    at exports.handler (/var/task/index.js:24:35)

Lambda Response

The response is invalid
ARB
  • 71
  • 1
  • 7

0 Answers0