Fix Alexa bug if no value for slots
This commit is contained in:
parent
bc4ab4d70a
commit
9876a2a081
2 changed files with 40 additions and 1 deletions
|
@ -116,7 +116,7 @@ class AlexaResponse(object):
|
||||||
self.should_end_session = True
|
self.should_end_session = True
|
||||||
if intent is not None and 'slots' in intent:
|
if intent is not None and 'slots' in intent:
|
||||||
self.variables = {key: value['value'] for key, value
|
self.variables = {key: value['value'] for key, value
|
||||||
in intent['slots'].items()}
|
in intent['slots'].items() if 'value' in value}
|
||||||
else:
|
else:
|
||||||
self.variables = {}
|
self.variables = {}
|
||||||
|
|
||||||
|
|
|
@ -149,6 +149,45 @@ class TestAlexa(unittest.TestCase):
|
||||||
text = req.json().get('response', {}).get('outputSpeech', {}).get('text')
|
text = req.json().get('response', {}).get('outputSpeech', {}).get('text')
|
||||||
self.assertEqual('You told us your sign is virgo.', text)
|
self.assertEqual('You told us your sign is virgo.', text)
|
||||||
|
|
||||||
|
def test_intent_request_with_slots_but_no_value(self):
|
||||||
|
data = {
|
||||||
|
'version': '1.0',
|
||||||
|
'session': {
|
||||||
|
'new': False,
|
||||||
|
'sessionId': 'amzn1.echo-api.session.0000000-0000-0000-0000-00000000000',
|
||||||
|
'application': {
|
||||||
|
'applicationId': 'amzn1.echo-sdk-ams.app.000000-d0ed-0000-ad00-000000d00ebe'
|
||||||
|
},
|
||||||
|
'attributes': {
|
||||||
|
'supportedHoroscopePeriods': {
|
||||||
|
'daily': True,
|
||||||
|
'weekly': False,
|
||||||
|
'monthly': False
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'user': {
|
||||||
|
'userId': 'amzn1.account.AM3B00000000000000000000000'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'request': {
|
||||||
|
'type': 'IntentRequest',
|
||||||
|
'requestId': ' amzn1.echo-api.request.0000000-0000-0000-0000-00000000000',
|
||||||
|
'timestamp': '2015-05-13T12:34:56Z',
|
||||||
|
'intent': {
|
||||||
|
'name': 'GetZodiacHoroscopeIntent',
|
||||||
|
'slots': {
|
||||||
|
'ZodiacSign': {
|
||||||
|
'name': 'ZodiacSign',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
req = _req(data)
|
||||||
|
self.assertEqual(200, req.status_code)
|
||||||
|
text = req.json().get('response', {}).get('outputSpeech', {}).get('text')
|
||||||
|
self.assertEqual('You told us your sign is .', text)
|
||||||
|
|
||||||
def test_intent_request_without_slots(self):
|
def test_intent_request_without_slots(self):
|
||||||
data = {
|
data = {
|
||||||
'version': '1.0',
|
'version': '1.0',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue