Repository: alexa-js/alexa-app
Pull request #314 (2018-02-10 18:59:07)

Fix breaking logic in request.slot()
I started receiving the following Intent Requests when an empty slot is provided:
```
{
    "type": "IntentRequest",
    "requestId": "amzn1.echo-api.request.ID",
    "timestamp": "2018-02-10T18:35:41Z",
    "locale": "en-US",
    "intent": {
        "name": "PersonIntent",
        "confirmationStatus": "NONE",
        "slots": {
            "Name": {
                "name": "Name",
                "confirmationStatus": "NONE"
            }
        }
    }
}
```
This was causing my function `request.slot(SlotName, defaultValue)` to fail. Because as it stands the logic in `request.slot()` doesn't check if the `value` is `'undefined'` and so doesn't return the `'defaultValue'`. This fixes that.

alexa-app-bot: 


<table>
  <thead>
    <tr>
      <th width="50"></th>
      <th width="100%" data-danger-table="true">Warnings</th>
    </tr>
  </thead>
  <tbody><tr>
      <td>:warning:</td>
      <td>Did you forget to update CHANGELOG.md?</td>
    </tr>
  </tbody>
</table>



<p align="right">
  Generated by :no_entry_sign: <a href="http://github.com/danger/danger-js/">dangerJS</a>
</p>

dblock: Thanks. This needs tests and changelog, please.
User1m: will update soon 👍 
User1m: @dblock Updates made. All but 1 tests pass due to a dslint error in `types/index.d.ts` which I did not modify. Would look into it more  if you want me to.
kobim: @dblock there's some problem with dtslint's _strict-export-declare-modifiers_ rule ([ref 1](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/22503#issuecomment-354200016), [ref 2](https://github.com/Microsoft/dtslint/issues/88)).
Maybe it's worth disabling for now? (it affects [other builds as well](https://travis-ci.org/alexa-js/alexa-app/jobs/337861983))
lazerwalker: Good news / bad news: on a hunch, I had Travis re-build master, and it's now red.

The problem is we're pointing dtslint at its `production` branch, as per https://github.com/Microsoft/dtslint/issues/71. 

I'm going to try switching to `0.2.0` in another branch, and re-open an issue in the dtslint repo for them to figure their versioning shit out.
lazerwalker: Yeah, doing some IT work on our dtslint config cleaned that up (albeit in the form of ignoring the error, rather than switching versions). See #316. 

@User1m want to rebase off of that branch?
User1m: Thanks @lazerwalker  for the fix 👍 
@dblock we're all green. Would love for a merge soon.
Thanks guys

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ad148f3..b274b69 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@
 ### 4.2.2 (Next)
 
 * [#315](https://github.com/alexa-js/alexa-app/pull/315): Fix card tests and required card type - [@kobim](https://github.com/kobim).
+* [#314](https://github.com/alexa-js/alexa-app/pull/314): Fix handling of `undefined` slot values - [@User1m](https://github.com/user1m).
 * Your contribution here.
 
 ### 4.2.1 (February 1, 2018)
diff --git a/index.js b/index.js
index 1a895f8..201535e 100644
--- a/index.js
+++ b/index.js
@@ -208,7 +208,7 @@ alexa.request = function(json) {
     }
   }
   this.slot = function(slotName, defaultValue) {
-    if (this.slots && 'undefined' != typeof this.slots[slotName]) {
+    if (this.slots && 'undefined' != typeof this.slots[slotName] && 'undefined' != typeof this.slots[slotName].value) {
       return this.slots[slotName].value;
     } else {
       return defaultValue;


Test patch:
diff --git a/test/test_alexa_app_customslot.js b/test/test_alexa_app_customslot.js
index 1322199..1c7ca11 100644
--- a/test/test_alexa_app_customslot.js
+++ b/test/test_alexa_app_customslot.js
@@ -10,6 +10,30 @@ chai.config.includeStack = true;
 import * as Alexa from '..';
 
 describe("Alexa", function() {
+
+  context("#alexa.request.slot", function () {
+    var testReq = mockHelper.load("intent_request_airport_info.json");
+    
+    beforeEach(function () {
+      testReq = mockHelper.load("intent_request_airport_info.json");
+    });
+
+    afterEach(() => {
+      testReq = null;
+    });
+
+    it("get slot value if correct", function () {
+      var req = new Alexa.request(testReq);
+      expect(req.slot("AirportCode", "SEA")).to.eql("JFK");
+    });
+
+    it("gets defaultValue if slot value is undefined", function () {
+      testReq.request.intent.slots.AirportCode.value = undefined;
+      var req = new Alexa.request(testReq);
+      expect(req.slot("AirportCode", "SEA")).to.eql("SEA");
+    });
+  });
+  
   describe("app", function() {
     var testApp = new Alexa.app("testApp");