Search code examples
pythonamazon-web-servicesaws-lambdaamazon-lex

Null response from dialogAction(Python)


I am getting null response while my code is successfully working. I am not able to get response from dialogAction, i am

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'
        }
    )

Solution

  • From what I understand, your code should be:

    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)
    

    Let us know if you are getting any error.