HTTP message using Alexa and JS

I am trying to get Alexa skill (JS / Lambda) to publish a value for a REST server using HTTP.request. I'm trying to hack something simple that will do the job. I think I am missing something obvious.

Perfect use of skill

  • I say, "Alexa, say five wiring test."
  • Alexa updates the value at the URL provided in the code to 5.
  • Alexa says, "I updated the value to five."

Problems

I have two problems:

  • Spoken and typed utterances . If I type the value of my slot in the Simulator Amazon Service ("five"), the value will be sent to my server, as it should be. However, if I say the same statement, although Alexa correctly recognizes the words (confirmed by viewing the cards in the application), the value is not published, and she says: "I can not find the answer to the question.

  • Where and how to call the output function . I think I need to add something like the two lines below, but depending on where I add it to my current code, Alexa either responds without updating the node or does nothing.

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

Call name

 posting test 

Scheme of Intent

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

Pronunciation Examples

 writeTarget {Target} 

AlexaSkill.js and index.js

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

My index.js looks like this. URL, req.write string, etc., 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 Use: A

  • I type "five" in the service simulator.
  • Node updates, but Alexa says nothing.

Current use: B

  • I say Alexa, "Tell Posting Test two."
  • Alexa says: "I can not find the answer to the question." The card confirms that she heard me correctly.
  • Nothing is updated.

Thanks in advance for your help.

Update: Logs

Update message to add logs:

Error message

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

Log Out Error

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

Lambda answer

 The response is invalid 
+5
source share
1 answer

It turned out with trial and error, here is the code that worked: http://dglogik.com/company/blog/197-alexa-dsa

+1
source

Source: https://habr.com/ru/post/1242674/


All Articles