alexa / alexa-skills-kit-sdk-for-nodejs

The Alexa Skills Kit SDK for Node.js helps you get a skill up and running quickly, letting you focus on skill logic instead of boilerplate code.
Apache License 2.0
3.12k stars 736 forks source link

Support both Dialog Directive and DisplayTemplate directive in same response #151

Closed DroopyTersen closed 6 years ago

DroopyTersen commented 7 years ago

I have successfully created a skill that uses the Dialog Directive delegate to collect my slot values. However, this skill is for an Echo Show, and I would like to display different screens as the user progresses through the delegated slot collection.

I have verified my Display.RenderTemplate directive is working. It is only when I try to include both a Dialog and Display directive in the response that I get the "response is invalid" error. They both work individually.

I have tried multiple strategies. I started trying to use [ { Dialog.Delegate }, { Display.RenderTemplate } ]. When that didn't work, I went with a more manual elicit slot strategy [ { Dialog.ElicitSlot }, { Display.RenderTemplate } ]. When that didn't work, I tried giving up and just showing a custom display on the intent confirmation `[ { Dialog.ConfirmIntent }, { Display.RenderTemplate } ]

In all cases, I get an invalid response error the anytime there are both Dialog and Display directives in the directives array. Here is an example of a response:

{
  "version": "1.0",
  "response": {
    "shouldEndSession": false,
    "directives": [
      {
        "type": "Dialog.Delegate",
        "updatedIntent": {
          "name": "GetVehicle",
          "confirmationStatus": "NONE",
          "slots": {
            "MODEL": {
              "name": "MODEL",
              "value": "wrangler",
              "resolutions": {
                "resolutionsPerAuthority": [
                  {
                    "authority": "...Vehicle_Model",
                    "status": {
                      "code": "ER_SUCCESS_MATCH"
                    },
                    "values": [
                      {
                        "value": {
                          "name": "Wrangler",
                          "id": "afb94ef09221efb2b79bf5a71c388a5b"
                        }
                      }
                    ]
                  }
                ]
              },
              "confirmationStatus": "NONE"
            },
            "YEAR": {
              "name": "YEAR",
              "confirmationStatus": "NONE"
            },
            "MAKE": {
              "name": "MAKE",
              "value": "jeep",
              "resolutions": {
                "resolutionsPerAuthority": [
                  {
                    "authority": "...Vehicle_Make",
                    "status": {
                      "code": "ER_SUCCESS_MATCH"
                    },
                    "values": [
                      {
                        "value": {
                          "name": "Jeep",
                          "id": "0bfc4b3d2ecfc06a969811c77066224e"
                        }
                      }
                    ]
                  }
                ]
              },
              "confirmationStatus": "NONE"
            }
          }
        }
      },
      {
        "type": "Display.RenderTemplate",
        "backButton": "HIDDEN",
        "template": {
          "type": "BodyTemplate1",
          "token": "GET_VEHICLE_TEMPLATE",
          "textContent": {
            "primaryText": {
              "type": "RichText",
              "text": "<font size=\"6\">Which Vehicle?</font>"
            },
            "secondaryText": {
              "type": "RichText",
              "text": "<font size=\"7\">____ jeep wrangler</font>"
            }
          },
          "title": "Tires Anytime",
          "backgroundImage": {
            "sources": [
              {
                "url": "http://www.example.com/background.jpg"
              }
            ]
          }
        }
      }
    ]
  },
  "sessionAttributes": {}
}
DroopyTersen commented 7 years ago

Is the Node.js SDK repo the right forum for this issue, or is it more of a core issue that should be surfaced somewhere else?

engineerChick commented 7 years ago

So I have been trying to figure out where I include this information to display something on the echo show. It doesn't look like the node.js code I upload to lambda, but surely it goes in it right?

On Mon, Jul 17, 2017 at 9:48 AM, Andrew Petersen notifications@github.com wrote:

Is the Node.js SDK repo the right forum for this issue, or is it more of a core issue that should be surfaced somewhere else?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/issues/151#issuecomment-315760351, or mute the thread https://github.com/notifications/unsubscribe-auth/ATAxOZBvq8i5WieN7-qCA6vZfTRsHNWkks5sO2XSgaJpZM4OXTWQ .

-- Lisa Marie Butler

DroopyTersen commented 7 years ago

@engineerChick , you're right, you need to include the response above in the Node.js code. Currently the alexa-sdk doesn't have any built in methods to support display templates, but under the covers, they appear to be managed very similar to how Dialog Directives are handled.

Here is a a code sample I found that manually creates a display template response: https://github.com/alexa/alexa-cookbook/blob/master/display-directive/listTemplate/index.js

Here is a forked version of the code I created to add support for display templates (I based it on the code above): https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/compare/master...DroopyTersen:display-template https://github.com/DroopyTersen/alexa-skills-kit-sdk-for-nodejs/tree/display-template

wacoder commented 7 years ago

@DroopyTersen Thank you for the post. I am trying to do the same thing. Do you have any sample code using displayTemplate in dialog directives?

DroopyTersen commented 7 years ago

@wacoder, unfortunately i was never able to get it working. I had to finish all the dialog directives before I was able to control the display on the Show. This was a few months ago though so maybe it's in a better place now?

wacoder commented 7 years ago

@DroopyTersen Actually, no. I still have the same issue for invalid response. Thank you for your quick response.

alexeystrakh commented 6 years ago

@wacoder did you find the solution?

Liamdelee commented 6 years ago

As of now i don't think it is possible since you can only do this "this.emit(':delegate', updatedIntent);" However in the early days you could construct your own intent and send it true with updatedIntent (if i remember correctly) you might have a look at that and see if you can play around with building your own intent from the ground up and give it echo interpreted options.

wolter commented 6 years ago

I use this code inside my intent handlers to achieve something similar:

this.handler.response = buildSpeechletResponse({
   sessionAttributes: this.attributes,
   directives: getDialogDirectives('Dialog.Delegate', null, null),
   cardTitle: "Card Title",
   cardContent: "Card Content...",
   // cardImage: imageObj,          
   shouldEndSession: false
});
this.emit(':responseReady'); 

// see function buildSpeechletResponse(options) from skillinator.io to build JSON
jacobweber commented 6 years ago

Looks like this is an Alexa issue, not an issue with the NodeJS SDK. When I manually construct a response with both a Dialog.ElicitSlot and a Display.RenderTemplate directive, I get a SessionEndedRequest from Alexa with:

        "error": {
            "type": "INVALID_RESPONSE",
            "message": "No other directives are allowed to be specified with a Dialog directive. The following Dialog Directives were returned: [Display.RenderTemplate]"
        }
TianTXie commented 6 years ago

Since this is not related to SDK, I'll close it for now. If you have more questions, you can go to this forum.

karri-sek commented 6 years ago

Hello guys, @DroopyTersen @wacoder @wolter .. I'm trying to build the same functionality, I would like to know, is this still possible to render the alexa response with both dialog and display directives?

theinternetguru2 commented 6 years ago

This is still a problem with Alexa as of August 4, 2018. You cannot combine both display and dialog directives in the same response. Clearly, something that needs to be fixed, no reason it should be a problem. And odd, in my opinion, that it has been a problem for over a year with no resolution.

tianrenz commented 6 years ago

Hi @theinternetguru2 ,

This is probably an implementation detail of the dialog interface. It's not related to the SDK. Therefore, we would recommend you to post this issue on the Alexa Developer Forum to get more feedback from the community.

Regards