答案 0 :(得分:0)
如果WeatherApiCallIntent
是由CityName
插槽值触发的,则请求JSON将如下所示:
"request": {
"type": "IntentRequest",
"requestId": "amzn1.echo-api.request.xxxxx-xxx-xxx-xx-xxxxxxx",
"timestamp": "2018-09-12T13:35:25Z",
"locale": "en-US",
"intent": {
"name": "WeatherApiCallIntent",
"confirmationStatus": "NONE",
"slots": {
"CityName ": {
"name": "CityName",
"value": "Kochi",
...
在您的WeatherApiCallIntent
处理程序中,您可以使用
print("Slot: " + intent_request['intent']['slots']['CityName']['value'])
答案 1 :(得分:0)
以上方法是正确的,但对我不起作用。
上述问题的另一个答案如下:
item, is_resolved = util.get_intent_(slots=handler_input.request_envelope.request.intent.slots)
然后定义函数get_intent_,如下所示:
import random
import six
from ask_sdk_core.handler_input import HandlerInput
from ask_sdk_core.utils import is_request_type
def get_intent_(slots):
item = []
resolved_item = None
for _,slot in six.iteritems(slots):
if slot.value is not None:
resolved_item = slot.value
if resolved_item is not None:
return resolved_item, True
else:
return resolved_item, False
此方法看起来很复杂,但是定义一个函数并调用它是一个好习惯。