question

Steve L. avatar image
Steve L. asked

How to get alexa to listen for a second response? Session issue?

How do I format my json response to get alexa to keep listening for another response? I am setting shouldEndSession to false but each time it is sending a new session. For instance, Alexa, open myskilltest {"version":"1.0","response":{"outputSpeech":{"type":"PlainText","text":"Pick a difficulty level: easy, medium, hard, or genius."}},"shouldEndSession":"false","reprompt":{"outputSpeech":{"type":"PlainText","text":null}},"sessionAttributes":null} Then I want to listen for my response but alexa does not respond. Note: I posted this here but they said it looked ok. I thought I would try you guys since this seems to be a bug. https://forums.developer.amazon.com/forums/thread.jspa?threadID=10824&tstart=0
alexa skills kitsubmission testing certification
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
You aren't really going to get a different answer here. It's all the same forum. And given the large number of skills working perfectly fine, I'm pretty sure it isn't a bug. What I suggest is this. Below is output from one of my skills. (Knock Knock) It works. Change your skill to return exactly this. [i]Exactly this[/i]. Validate that when you ping it in the test panel you get [i]exactly[/i] this. Then ping it with the Echo. If it doesn't not leave the session open, then you have something legitimate to go to the Echo team with. Click the feedback link that was posted in the other thread. Otherwise start changing your code from returning this static text, to returning what you want to return. Make one change at a time. Work out when, between returning this static code, the fully dynamic code, that it stops working. Then you will find what you are doing wrong. [code] { "version": "1.0", "response": { "outputSpeech": { "type": "PlainText", "text": "knock knock" }, "card": { "type": "Simple", "content": "knock knock", "title": "TsaTsatzu's Knock Knock jokes" }, "reprompt": { "outputSpeech": { "type": "PlainText", "text": "knock knock" } }, "shouldEndSession": false }, "sessionAttributes": { "call": "1", "state": 0, "lastIntent": "RESPONSE", "joke": "knock knock|meg!|meg up your mind!" } } [/code]
10 |5000

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

Steve L. avatar image
Steve L. answered
Thanks so much! That was exactly what I needed.
10 |5000

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

Galactoise avatar image
Galactoise answered
I think I figured it out - your original response uses the JSON String ("false") instead of the JSON boolean (false) for the shouldEndSession field. I'm frankly surprised that it accepted your response at all.
10 |5000

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

Kostya avatar image
Kostya answered
I've run into the same problem, but I'm using the Java 8 libraries. When I create the response, I took to dumping the Response structure and examining the actual flag before I send it back. DEBUG 23 Jan 2016 22:19:06,844 [main] response.getShouldEndSession? false But when I see the JSON in the test pane, it has "shouldEndSession": true. I'm using the SpeechletResponse helper methods, and those explicitly set shouldEndSession to false. I'm a bit stumped.
10 |5000

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

Steve L. avatar image
Steve L. answered
jjaquinta's answer was very helpful for me. I had the shouldEndSession param outside of the response object. It has to be inside the response object.
10 |5000

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

Kostya avatar image
Kostya answered
Yeah, I'm using the Java libs with Lambda. I've been double-checking my JSON, and what appears to happen is that when shouldEndSession is set to true on the SpeechletResponse, you see "shouldEndSession": true in the JSON. When it's set to false, nothing appears in the JSON--and apparently the Alexa Cloud Service is then treating that as true (at least for my app). What I don't get is that the Score Keeper Java sample works fine--and I used that code and the SDK to build my skill.
10 |5000

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

Levon@Amazon avatar image
Levon@Amazon answered
Hi Kostya, Please note that there could be several places in your code where you set its value, so make sure they are all correct in all places. For example, in this Java sample that jjaquinta provided: http://forums.developer.amazon.com/forums/message.jspa?messageID=17557 check the onLaunch(), buildSpeechletResponse(), and your sayHello() and sayHelloToUser() equivalents.
10 |5000

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

Kostya avatar image
Kostya answered
Levon, I have checked. I'm sure there's something really minor here, but I have actually created unit test at the Lambda RequestHandler. I've run the speechlet through that unit test, and I see JSON that has no "shouldEndSession" value. Based on the source code for the SpeechletResponse, the Jaxon config says it should skip serializing that value if it isn't the default (the default is true). So I set the shouldEndSession manually and verify the java property is set to false, but I don't ever see the value in the JSON for my ask responses. When I send a tell response, I see it set to true. I can only assume that Alexa assumes true when it isn't present, but I can't figure out why my false value isn't being persisted.
10 |5000

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

Levon@Amazon avatar image
Levon@Amazon answered
Thanks Kostya, could you please confirm whether the Java sample works for you -- just copy and paste the code and give it a try. Otherwise, if possible share your code, system configuration, Java version, etc -- you can use the Contact Us form in your dev portal account, if you wish. Thanks.
10 |5000

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

Kostya avatar image
Kostya answered
I believe I found the issue. I manually overrode the getShouldEndSession Jackson properties and everything worked fine. So I then worked backwards from there, and it appears to be my Jackson libs. My maven build was including the Jackson Data Bind libraries directly. I think the version I was using was not respecting the annotations in the same way the libs that come in with the sample do for shouldEndSession. Thanks for all your help and patience!
1 comment
10 |5000

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

Thanks! I spend most of the day trying to understand why AskResponses were not keeping the Session open. Commenting out the jackson-databind dependency in my POM resolved the issue.

0 Likes 0 ·