Replace dots in Alexa built-in intent slots w/ underscores (#5092)
* Replace dots in built-in intent slots w/ underscores * Add a built-in intent test
This commit is contained in:
parent
aaff8d8602
commit
a2f17cccbb
2 changed files with 70 additions and 4 deletions
|
@ -203,11 +203,12 @@ class AlexaResponse(object):
|
||||||
self.reprompt = None
|
self.reprompt = None
|
||||||
self.session_attributes = {}
|
self.session_attributes = {}
|
||||||
self.should_end_session = True
|
self.should_end_session = True
|
||||||
|
self.variables = {}
|
||||||
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
|
for key, value in intent['slots'].items():
|
||||||
in intent['slots'].items() if 'value' in value}
|
if 'value' in value:
|
||||||
else:
|
underscored_key = key.replace('.', '_')
|
||||||
self.variables = {}
|
self.variables[underscored_key] = value['value']
|
||||||
|
|
||||||
def add_card(self, card_type, title, content):
|
def add_card(self, card_type, title, content):
|
||||||
"""Add a card to the response."""
|
"""Add a card to the response."""
|
||||||
|
|
|
@ -101,6 +101,12 @@ def setUpModule():
|
||||||
"text": "You told us your sign is {{ ZodiacSign }}.",
|
"text": "You told us your sign is {{ ZodiacSign }}.",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"AMAZON.PlaybackAction<object@MusicCreativeWork>": {
|
||||||
|
"speech": {
|
||||||
|
"type": "plaintext",
|
||||||
|
"text": "Playing {{ object_byArtist_name }}.",
|
||||||
|
}
|
||||||
|
},
|
||||||
"CallServiceIntent": {
|
"CallServiceIntent": {
|
||||||
"speech": {
|
"speech": {
|
||||||
"type": "plaintext",
|
"type": "plaintext",
|
||||||
|
@ -376,6 +382,65 @@ class TestAlexa(unittest.TestCase):
|
||||||
self.assertEqual(200, req.status_code)
|
self.assertEqual(200, req.status_code)
|
||||||
self.assertEqual("", req.text)
|
self.assertEqual("", req.text)
|
||||||
|
|
||||||
|
def test_intent_from_built_in_intent_library(self):
|
||||||
|
"""Test intents from the Built-in Intent Library."""
|
||||||
|
data = {
|
||||||
|
'request': {
|
||||||
|
'intent': {
|
||||||
|
'name': 'AMAZON.PlaybackAction<object@MusicCreativeWork>',
|
||||||
|
'slots': {
|
||||||
|
'object.byArtist.name': {
|
||||||
|
'name': 'object.byArtist.name',
|
||||||
|
'value': 'the shins'
|
||||||
|
},
|
||||||
|
'object.composer.name': {
|
||||||
|
'name': 'object.composer.name'
|
||||||
|
},
|
||||||
|
'object.contentSource': {
|
||||||
|
'name': 'object.contentSource'
|
||||||
|
},
|
||||||
|
'object.era': {
|
||||||
|
'name': 'object.era'
|
||||||
|
},
|
||||||
|
'object.genre': {
|
||||||
|
'name': 'object.genre'
|
||||||
|
},
|
||||||
|
'object.name': {
|
||||||
|
'name': 'object.name'
|
||||||
|
},
|
||||||
|
'object.owner.name': {
|
||||||
|
'name': 'object.owner.name'
|
||||||
|
},
|
||||||
|
'object.select': {
|
||||||
|
'name': 'object.select'
|
||||||
|
},
|
||||||
|
'object.sort': {
|
||||||
|
'name': 'object.sort'
|
||||||
|
},
|
||||||
|
'object.type': {
|
||||||
|
'name': 'object.type',
|
||||||
|
'value': 'music'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'timestamp': '2016-12-14T23:23:37Z',
|
||||||
|
'type': 'IntentRequest',
|
||||||
|
'requestId': REQUEST_ID,
|
||||||
|
|
||||||
|
},
|
||||||
|
'session': {
|
||||||
|
'sessionId': SESSION_ID,
|
||||||
|
'application': {
|
||||||
|
'applicationId': APPLICATION_ID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
req = _intent_req(data)
|
||||||
|
self.assertEqual(200, req.status_code)
|
||||||
|
text = req.json().get("response", {}).get("outputSpeech",
|
||||||
|
{}).get("text")
|
||||||
|
self.assertEqual("Playing the shins.", text)
|
||||||
|
|
||||||
def test_flash_briefing_invalid_id(self):
|
def test_flash_briefing_invalid_id(self):
|
||||||
"""Test an invalid Flash Briefing ID."""
|
"""Test an invalid Flash Briefing ID."""
|
||||||
req = _flash_briefing_req()
|
req = _flash_briefing_req()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue