[SOLVED] Detect display for Echo device

I’m making a skill and I want it to work in Echos without screen, as well as the Show and the Dot which do have a screen, but if I include the screen directives in the response, then the skill doesn’t work in devices without a screen; I know I could just remove the directives, but I want the skill response to look beautiful in devices with a screen.

I’m still learning how to code, and I pretty much have everything ready, except that I can’t make my code detect when the incoming call comes from an echo with a display, and when it comes from an echo with a display.

I have to response cards, one with the display directives, and one without it.
I also know I need a conditional, but I’m not really sure how to write it.

Here’s an example of an incoming call from a device with display:

{
  "time": "2018-04-03T01:46:33.567Z",
  "data": {
    "path": "/",
    "method": "post",
    "headers": {
      "x-real-ip": "72.21.217.110",
      "x-forwarded-proto": "https",
      "x-forwarded-for": "72.21.217.110",
      "x-queue-start": "1522719993.566",
      "content-length": "2702",
      "content-type": "application/json; charset=utf-8",
      "accept": "application/json",
      "accept-charset": "utf-8",
      "signature": "a+erhxHLwl/F/JXzJYjZJ6Q8WDUp717ixYf8fjn2rRyXCnaj0EfyN3j5qXLfthhNV8b4DstVP2Hx0Ye0ffPUSx0jN2R4BfwUVs27wDYwm7q/nkuUYPFHhzmGkPX3cTKgUv7f37VqkZ+bqnBKB4qo4YcOhqWr+Vscj9jwK9NBm27kt2nS5OHdPGUOPTnKVZv8+d+IgnqG5xVlNXQvYz/Rn6iYGnvAjTZDccgjy6u7/B4rumuSe43mdc3jstAakfSNWvVWyGl7f3ZKQD0jrcO3CmHgmPDneOJ3BLFb/8D89ski4KMaCchMaqeZVR4cnMab45WmnQT8YLEakUMG8KGZ6A==",
      "signaturecertchainurl": "https://s3.amazonaws.com/echo.api/echo-api-cert-5.pem",
      "user-agent": "Apache-HttpClient/4.5.x (Java/1.8.0_131)"
    },
    "query": {},
    "body": {
      "version": "1.0",
      "session": {
        "new": true,
        "sessionId": "amzn1.echo-api.session.396854fa-3504-4cfb-9a23-343530768022",
        "application": {
          "applicationId": "amzn1.ask.skill.5f428de1-7673-4cbc-9866-a71820a93fa5"
        },
        "user": {
          "userId": "amzn1.ask.account.AGZDI5NYAJ3OBE36OFQF2OK5B5KBBG53OBNF5QLJHM5AFRGJAYRG3SVRDLRXW3CGIR5DVPGV54OTIG5B6I4BZ6RICLR7PEGFBC4IHZIHZIHHFHWKNTGYDAVVLG6DQUZKEHAI5CVTOVO6VX5ZGRYFNXEDBHTPMFFQM3X44IZVDKVIWT5W63W5LQORZ7Y3HA75IZGGFKURMEBI7QQ"
        }
      },
      "context": {
        "AudioPlayer": {
          "playerActivity": "FINISHED"
        },
        "Display": {
          "token": "*****REDACTED*****"
        },
        "System": {
          "application": {
            "applicationId": "amzn1.ask.skill.5f428de1-7673-4cbc-9866-a71820a93fa5"
          },
          "user": {
            "userId": "amzn1.ask.account.AGZDI5NYAJ3OBE36OFQF2OK5B5KBBG53OBNF5QLJHM5AFRGJAYRG3SVRDLRXW3CGIR5DVPGV54OTIG5B6I4BZ6RICLR7PEGFBC4IHZIHZIHHFHWKNTGYDAVVLG6DQUZKEHAI5CVTOVO6VX5ZGRYFNXEDBHTPMFFQM3X44IZVDKVIWT5W63W5LQORZ7Y3HA75IZGGFKURMEBI7QQ"
          },
          "device": {
            "deviceId": "amzn1.ask.device.AHRWA4XFXSJEL2DCPDNVSCF34IXEHQRTOW6K73XC5ZKBGW3KY42SSWFGJXUZUZC62OQMDZFIU2AWHBCIZGBCJ5ZW75JF7IPGVHOJMVYG6OUQ2YOUSVMBRKIX2UIR4NSL4FAROKYTQE57AQWQIKE2KCM76H3A",
            "supportedInterfaces": {
              "AudioPlayer": {},
              "Display": {
                "templateVersion": "1.0",
                "markupVersion": "1.0"
              },
              "VideoApp": {}
            }
          },
          "apiEndpoint": "https://api.amazonalexa.com",
          "apiAccessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjEifQ.eyJhdWQiOiJodHRwczovL2FwaS5hbWF6b25hbGV4YS5jb20iLCJpc3MiOiJBbGV4YVNraWxsS2l0Iiwic3ViIjoiYW16bjEuYXNrLnNraWxsLjVmNDI4ZGUxLTc2NzMtNGN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est",
        "requestId": "amzn1.echo-api.request.1da964e8-b90e-496d-89c8-f5c8faf53fe8",
        "timestamp": "2018-04-03T01:46:33Z",
        "locale": "en-US",
        "intent": {
          "name": "bothPorts",
          "confirmationStatus": "NONE"
        }
      }
    },
    "replyId": "5aa1c418f1d49b000b74a770.aBQF~ekUsukHGvjgeOT9v.p9bEfq5RxJEocqFkkQqnYW"
  },
  "applicationId": "5aa1c3e1c98fb4000624f621",
  "triggerId": "5aa1c418f1d49b000b74a770",
  "triggerType": "webhook",
  "relayId": "000000000000000000000000",
  "relayType": "public",
  "flowVersion": "develop",
  "flowId": "5aa1c4c560f07c00077f274b",
  "flowName": "Border Wait",
  "applicationName": "Border Wait",
  "globals": {}
}

And one from a device without:

{
  "time": "2018-04-03T02:53:09.142Z",
  "data": {
    "path": "/",
    "method": "post",
    "headers": {
      "x-real-ip": "72.21.217.133",
      "x-forwarded-proto": "https",
      "x-forwarded-for": "72.21.217.133",
      "x-queue-start": "1522723989.138",
      "content-length": "2583",
      "content-type": "application/json; charset=utf-8",
      "accept": "application/json",
      "accept-charset": "utf-8",
      "signature": "Wmpaz5kUoGjO6hTBHNkQ0LhF/qpzbcagqZ0KGNboMjpgpA3shweWicJiI/b9AyZZhq0ihNwE5nR9GQmDbVrjTyPBpeXFMX3Tk3GY3rKn0kpYkQfGu6vbgajz9+jgNDI5RzsIOEu2lnHYfAzFS++HQ6WF0NgLJZs738bekYkPPa5HhvxBYlOaCewRsF5JmtkP1xeYBv2ccMRZvySWqOis0pZeOda6HFo/xMcosW4cws3VqroXuAjhN6ubMq/l5+8pJaoiBRL87W75Y6DHt+KInXU3qFHTaNExZWat6U8S6IZ2ach14dYitN7Aqur4ZlQRufeEBbGq71/qzxyRBuPtbQ==",
      "signaturecertchainurl": "https://s3.amazonaws.com/echo.api/echo-api-cert-5.pem",
      "user-agent": "Apache-HttpClient/4.5.x (Java/1.8.0_131)"
    },
    "query": {},
    "body": {
      "version": "1.0",
      "session": {
        "new": true,
        "sessionId": "amzn1.echo-api.session.2ad38269-cd79-45ac-b2ba-839a57f5672e",
        "application": {
          "applicationId": "amzn1.ask.skill.5f428de1-7673-4cbc-9866-a71820a93fa5"
        },
        "user": {
          "userId": "amzn1.ask.account.AGRE3J6SFU5GGB3AH27YHNEAYIHUPA4YMFG3TUHR6SP5WJ6KDFKKBT2NJFBWZRJPPCTF3UVD2BIHGJB3CBA5JER3JRFJOEBZP525DKEZJBIW6AWXTU6MAEKZRCB5MG32KFXYW7RRYBWJGSJDMXEZBPY4FW4NY7JNQ43ZXJD3LJSBPNYRF7DQC3NIVKJG6QJEEVXYG2Z7GCI3KEA"
        }
      },
      "context": {
        "AudioPlayer": {
          "playerActivity": "STOPPED"
        },
        "System": {
          "application": {
            "applicationId": "amzn1.ask.skill.5f428de1-7673-4cbc-9866-a71820a93fa5"
          },
          "user": {
            "userId": "amzn1.ask.account.AGRE3J6SFU5GGB3AH27YHNEAYIHUPA4YMFG3TUHR6SP5WJ6KDFKKBT2NJFBWZRJPPCTF3UVD2BIHGJB3CBA5JER3JRFJOEBZP525DKEZJBIW6AWXTU6MAEKZRCB5MG32KFXYW7RRYBWJGSJDMXEZBPY4FW4NY7JNQ43ZXJD3LJSBPNYRF7DQC3NIVKJG6QJEEVXYG2Z7GCI3KEA"
          },
          "device": {
            "deviceId": "amzn1.ask.device.AFFQH5XGRO2AG72EJZTSVSPUVEN6DW7VX6WXQ43P5XZO4MRJQC2DFMWIJOYOC3BKBNGPGINAMY4PE5ILKGZL2P3KRKWMASJOPHFECNCVFKSX2K5V3QBRYXGFMH7F4GZ3QBNNW2Y36NYKVXOENBYQHCAX375A",
            "supportedInterfaces": {
              "AudioPlayer": {}
            }
          },
          "apiEndpoint": "https://api.amazonalexa.com",
          "apiAccessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjEifQ.eyJhdWQiOiJodHRwczovL2FwaS5hbWF6b25hbGV4YS5jb20iLCJpc3MiOiJBbGV4YVNraWxsS2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_y2x51IoFXijabNU1Eyvk7ipwtnP8ggupizkGUwzEUI7Qwqj8Q"
        }
      },
      "request": {
        "type": "LaunchRequest",
        "requestId": "amzn1.echo-api.request.76f9857c-f713-4c67-a9e3-4a5750042694",
        "timestamp": "2018-04-03T02:53:08Z",
        "locale": "en-US",
        "shouldLinkResultBeReturned": false
      }
    },
    "replyId": "5aa1c418f1d49b000b74a770.aBQF~ekUsukHGvjgeOT9v.CzsQrcuXN_IF50eD9KCmHW"
  },
  "applicationId": "5aa1c3e1c98fb4000624f621",
  "triggerId": "5aa1c418f1d49b000b74a770",
  "triggerType": "webhook",
  "relayId": "000000000000000000000000",
  "relayType": "public",
  "flowVersion": "develop",
  "flowId": "5aa1c4c560f07c00077f274b",
  "flowName": "Border Wait",
  "applicationName": "Border Wait",
  "globals": {}
}

It looks like data.body.context.device.supportedInterfaces has some state that you can branch from. You could just look for the presence of the data.body.context.device.supportedInterfaces.Display object with a conditional node and branch your eventual response based on that. Perhaps we’ll need to parse the request a bit further, but give that a shot and let me know if that is sufficient.

That’s what I initially did.
Right now I have a conditional node before the response nodes with this code:

{{data.body.System.device.supportedInterfaces.Display}} == 'true'

The problem is that it keeps sending the response to the “no display” response like if the result was false, doesn’t matter if the call comes from a device with or without display.

I believe the issue with your conditional is that data.body.context.device.supportedInterfaces.Display is an object and you’re comparing it against the string “true”. That would be evaluated as false.

Try using:

{{ data.body.context.device.supportedInterfaces.Display  }} !== undefined

The above is simply checking something exists at that path.

Sorry for taking days to continue with the discussion… crazy week at work.

I tried that bit of code and still not working. No matter which device I use, with our without display, it always goes to “false”

It works!!!

I checked again in detail the call and changed the path. I used:

{{data.body.context.Display}} !== undefined

So now my skill works in all kind of devices.
Thanks for your help and fast responses!!