dialogAction(Python)的空响应

时间:2018-01-03 09:48:44

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

我的代码成功运行时,我的响应为空。我无法从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'
        }
    )

1 个答案:

答案 0 :(得分: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)

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