0

我正在尝试实现内置的 YesIntent 和 NoIntent ...

HelpIntent 有效,我复制了我为 HelpIntent 调用的函数并对其进行自定义,即:

HelpIntent 功能(注意 - 这有效):

def get_help_response():

session_attributes = {}
card_title = "Help"
speech_output = "<speak>You can say something like ... </speak>"

caption = None
sm_img = None
lg_img = None
reprompt_text = "You can say something like ...."
should_end_session = False
return build_response(session_attributes, build_speechlet_response(
    card_title, speech_output, caption, sm_img, lg_img, reprompt_text, should_end_session))

我对 YesIntent 和 NoIntent 函数做了同样的事情,但稍微定制了答案:

def get_yes_response():

session_attributes = {}
card_title = "Yes"
speech_output = "<speak> Yes response speech output</speak>"

caption = None
sm_img = None
lg_img = None
reprompt_text = "Yes response speech output."
should_end_session = False
return build_response(session_attributes, build_speechlet_response(
    card_title, speech_output, caption, sm_img, lg_img, reprompt_text, should_end_session))

每当我测试“是”或“否”时 - 我可以看到 Intent 被正确识别并且 Lambda 尝试返回响应但我收到以下错误:

An error occurred during JSON serialization of response: <function get_yes_response at 0x7f4743de0848> is not JSON serializable 

Traceback (most recent call last): File "/usr/lib64/python2.7/json/__init__.py", line 250, in dumps sort_keys=sort_keys, **kw).encode(obj) 

File "/usr/lib64/python2.7/json/encoder.py", line 207, in encode chunks = self.iterencode(o, _one_shot=True) File "/usr/lib64/python2.7/json/encoder.py", line 270, in iterencode return _iterencode(o, 0) 

File "/var/runtime/awslambda/bootstrap.py", line 41, in decimal_serializer raise TypeError(repr(o) + " is not JSON serializable") 

TypeError: <function get_yes_response at 0x7f4743de0848> is not JSON serializable

我不明白为什么 JSON 会有问题。知道这里发生了什么吗?

4

0 回答 0