question

James L Guinn avatar image
James L Guinn asked

Getting past "Hello World"

I've gotten all the examples to work (Hello World, Scorekeeper, etc), and my next progression would be baby steps from that to something of my own creation. One challenge I'm having is in performing a unit test using the Test button within Lambda. For instance, I can test "MyColorIs" and get JSON for "I now know your favorite color is blue." What I want to do next is test "WhatsMyColorIntent" with a color that I pass in. If I just change the intent name from the original example (which already specifies a color of blue) I get "I'm not sure what your favorite color is, you can say, my favorite color is red." (See my sample JSON call and return result at bottom). I took it that I was not passing the attributes correctly, so I've spent hours reviewing the specifications on the SDK and trying every combination I can think of. What would REALLY be helpful is if I could capture the string my Echo device sends so I can review and learn from the actual JSON examples. By the way, my color skill does function correctly. I can execute the entire sequence from my Echo and have it return any color (even naughty words which is funny to hear her say "I now know that your favorite color is sh ). So my first question is, #1 what is the correct JSON for "WhatsMyColorIntent" to reply with "Your favorite color is blue" using the Lambda test button? My second question is #2 is there a way to capture the incoming JSON text string from within Lambda? I couldn't find it anywhere in the logs. I presume if I had my own web endpoint I could do this. To that end, I've soaked 20+ hours in Lynda.com tuts, AWS how to's numerous EC2 instances and a fistful of hair trying to circumvent Lambda just so I can have more control of my own endpoint. The main thing I've learned is I probably need a Mac, because that's what everyone else seems to be using, but that's a topic for another thread. So, my third question is #3 Does anyone have an EC2 image (I believe these are called AMI's) correctly configured as an endpoint for Alexa skills (Node or Java)? If not in AWS, does anyone have a good handle on how to get up and running quickly--jjaquinta? Anyone? I really want to get off the ground with Alexa development... I guess what I'm asking is there anyone out there wanting to share knowledge or maybe team up? jjaquinta, I dropped your name because I read your book (highly recommend) and you're always generous with your knowledge on the forums. I'm not new to programming, entirely (20+ year career in computing--currently as MS SQL dev/dba), but I do feel like I'm on an island trying to learn this. I very much appreciate any answers to my specific questions here in the forum, and anyone else willing to share, mentor or just in general contact me, I would love to hear from you. Thanks for listening! Jim Guinn jguinn@bonevalleyfilms.com // Sample JSON call attempting to ask what is my favorite color to return "blue" yet I get "I'm not sure what your favorite color is as described above { "session": { "new": false, "sessionId": "session1234", "attributes": {}, "user": { "userId": null }, "application": { "applicationId": "amzn1.echo-sdk-ams.app.[unique-value-here]" } }, "version": "1.0", "request": { "intent": { "slots": { "Color": { "name": "Color", "value": "blue" } }, "name": "WhatsMyColorIntent" }, "type": "IntentRequest", "requestId": "request5678" } } // RETURNS: { "version": "1.0", "sessionAttributes": {}, "response": { "outputSpeech": { "type": "PlainText", "text": "I'm not sure what your favorite color is, you can say, my favorite color is and then tell me your favorite color" }, "card": { "type": "Simple", "title": "SessionSpeechlet - WhatsMyColorIntent", "content": "SessionSpeechlet - I'm not sure what your favorite color is, you can say, my favorite color is and then tell me your favorite color" }, "reprompt": { "outputSpeech": { "type": "PlainText", "text": null } }, "shouldEndSession": false } }
alexa skills kitdebugging
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jjaquinta avatar image
jjaquinta answered
Jeez, I can hardly say "go read my book", when you've already done so! :-) But, yeah, I tried not to replicate Amazon's tutorials in my book. So they are more about the general approach and advanced tricks rather than a blow-by-blow. >One challenge I'm having is in performing a unit >test using the Test button within Lambda. I found the testing suggestions from Amazon to be nearly useless. Hand coding JSON (including the date!) in Lambda, or CURL is just not workable in a professional context. That's partly the reason I wrote EchoSim, so you could do reasonable testing. At worst, it will at least format your JSON correctly to send to your skill. Now, using EchoSim with Lambda isn't obvious. The next draft of my book actually has two new sections on testing Lambda functions using EchoSim. That doesn't help you right now. (If you drop me a line at jo@111george.com I'll send you the draft, if you would like to "play test" it for me!) >#1 what is the correct JSON for "WhatsMyColorIntent" to reply with >"Your favorite color is blue" using the Lambda test button? The below code works for me. The key is that the lambda function stores its state in the session attributes. If you send in the standard text for "MyColorIsIntent" setting it to blue, you will see "attributes": {"favoriteColor": "blue"} come back in the response. You need to add that into the submission. Sending: [code] { "session": { "new": false, "sessionId": "session1234", "attributes": {"favoriteColor": "blue"}, "user": { "userId": null }, "application": { "applicationId": "amzn1.echo-sdk-ams.app.[unique-value-here]" } }, "version": "1.0", "request": { "intent": { "slots": { "Color": { "name": "Color", "value": "blue" } }, "name": "WhatsMyColorIntent" }, "type": "IntentRequest", "requestId": "request5678" } } [/code] Receiving: [code] { "version": "1.0", "sessionAttributes": {}, "response": { "outputSpeech": { "type": "PlainText", "text": "Your favorite color is blue, goodbye" }, "card": { "type": "Simple", "title": "SessionSpeechlet - WhatsMyColorIntent", "content": "SessionSpeechlet - Your favorite color is blue, goodbye" }, "reprompt": { "outputSpeech": { "type": "PlainText", "text": null } }, "shouldEndSession": true } } [/code] >#2 is there a way to capture the incoming JSON text >string from within Lambda? It isn't in the logs unless you put it in the logs. I'm more familiar with Java. For that, your Lambda function gets passed a "context" value, and that value has a getLog() function with an object you can log output too. Also it seems to redriect System.out to the log. I note in the sample Javascript code that the first function has a profile "exports.handler = function (event, context)". This looks like the same context object. However, context.logger.log("test") and context.getLogger().log("test") don't work, so I don't know what methods are there. print("test") also doesn't work. But, then, the very first line in the function calls console.log(). Doh. I added in this line: [code] exports.handler = function (event, context) { try { console.log("event.session.application.applicationId=" + event.session.application.applicationId); [b]console.log(JSON.stringify(event));[/b] [/code] and the output now contains the JSON: [code] START RequestId: d20bb3fb-4476-11e5-b99d-a9b0f0ea6c47 2015-08-17T00:28:02.750Z d20bb3fb-4476-11e5-b99d-a9b0f0ea6c47 event.session.application.applicationId=amzn1.echo-sdk-ams.app.[unique-value-here] 2015-08-17T00:28:02.751Z d20bb3fb-4476-11e5-b99d-a9b0f0ea6c47 {"session":{"new":false,"sessionId":"session1234","attributes":{"favoriteColor":"blue"},"user":{"userId":null},"application":{"applicationId":"amzn1.echo-sdk-ams.app.[unique-value-here]"}},"version":"1.0","request":{"intent":{"slots":{"Color":{"name":"Color","value":"blue"}},"name":"WhatsMyColorIntent"},"type":"IntentRequest","requestId":"request5678"}} 2015-08-17T00:28:02.751Z d20bb3fb-4476-11e5-b99d-a9b0f0ea6c47 onIntent requestId=request5678, sessionId=session1234 END RequestId: d20bb3fb-4476-11e5-b99d-a9b0f0ea6c47 [/code] >I presume if I had my own web endpoint I could do this. I find working with web endpoints much easier. But I'm generally a lot more familiar with them. >#3 Does anyone have an EC2 image I slogged through the Amazon tutorials and got one working. You just really have to follow them point-by-point. Push the stack each time they send you off to another tutorial, do that one, then pop the stack and continue on. The first time I did it I checked in a file I shouldn't have on GitHub, it got snatched by a hacker, and they racked up $1500 in charges. Embarrassing since my current day job is "Ethical Hacker". But Amazon reversed them. Just saying, even with 20+ years of experience in this it's still rather error prone. I don't have an image, but I did create a war file at one point with a plain old fashioned servlet endpoint that I was able to deploy on IBM's Bluemix. I can dig that up if it is any use.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

James L Guinn avatar image
James L Guinn answered
Wow! "favoriteColor!"... That was the missing link. I think one of the 1001 versions of JSON I submitted was probably structured identical to what you suggested, with the exception that I was trying to call the attribute "Color" and would not have guessed "favoriteColor." Thank you, jjaquinta for your prompt, thorough and thoughtful reply. I will definitely get in touch with you right away over the e-mail you provided, but want to also say thanks, publicly. Jim
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.