【问题标题】:Null response from dialogAction(Python)来自 dialogAction(Python) 的空响应
【发布时间】:2018-05-26 05:00:04
【问题描述】:

当我的代码成功运行时,我得到空响应。我无法从 dialogAction 中得到响应,我是

import json
import requests

def getdata(intent_name, fulfillment_state, message):
  response = {

        'dialogAction': {
            'type': 'Close',
            'intentName': intent_name,
            'fulfillmentState': fulfillment_state,
            'message': message
        }
  }
  return response


def lambda_handler(event,context):
 payload = {'userId':4,'type':'PARENT'}

 r = requests.post("http://ec2-54-226-57-153.compute-1.amazonaws.com:8080/Tracking/rest/api", data=json.dumps(payload), headers = {'Content-Type': 'application/json','Accept': 'application/json'})
 print(r.content) 
 getdata(
        'currentIntent',
        'Fulfilled',
        {
            'contentType': 'PlainText',
            'content': 'message'
        }
    )

【问题讨论】:

    标签: python amazon-web-services aws-lambda amazon-lex


    【解决方案1】:

    据我了解,您的代码应该是:

    import json
    import requests
    
    def getdata(message):
        return {
            'dialogAction':{
                'type':'Close',
                'fulfillmentState':'Fulfilled',
                'message':{
                    'contentType':'PlainText',
                    'content':message
                }
            }
        }
    
    def lambda_handler(event, context):
        payload = {'userId':4,'type':'PARENT'}
        r = requests.post("http://ec2-54-226-57-153.compute-1.amazonaws.com:8080/Tracking/rest/api", data=json.dumps(payload), headers = {'Content-Type': 'application/json','Accept': 'application/json'})
        print(r.content) 
        return getdata(r.content)
    

    如果您遇到任何错误,请告诉我们。

    【讨论】:

    • 太棒了。最后一个问题如何获得我在 lex 中编写的插槽的值。在这里,我没有从我的机器人那里得到任何东西。让我的意图是“coffee_intent”,并有像“type”这样的插槽。
    • 该信息存在于event。尝试打印/记录它并查看您获得的属性。
    • 我收到消息成功,但无法将其打印成 2 行。我怎样才能做到这一点?
    • 渲染输出取决于您的客户端。
    • 就像我收到“嗨,您的订单已完成”这样的响应消息,我希望它在第一行打印为“嗨”,然后在第二行打印。
    猜你喜欢
    • 1970-01-01
    • 2023-03-25
    • 2014-03-27
    • 1970-01-01
    • 1970-01-01
    • 2021-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多