Using "final_response" in Main Method

Using final_response

The format or values which the code will return depends on final_response present in def main(event, context).

The default final_response is as follows -

final_response = {
    'status': True,
    'entities':entities,
    'user_full_name': user_data.get("full_name"),
    'user_device_platform': user_data.get("device_platform"),
    'conversation_details':conversation_details
    }
    response = {'statusCode': 200, 'body': json.dumps(final_response), 'headers': {'Content-Type': 'application/json'}}
    return response

The main method returns response. In response we dump them final_response in JSON format. The final_reponse is the JSON key-value pair that gets executed every time the code runs. The output which you will receive upon running this code will be in the same format as defined in the final_response.

On final_response -

  • You can call any method defined on the code editor.
  • You can call any variable name declared on the code editor.

A sample final_response -

final_response = {
'status': status,
'hsl': hsl,
'channel': channel,
'name': name,
'query':get_query(entities),
'message': message,
'email': email,
'ps_date': date,
'ps_time': time,
'tool': tool_name,
'issue_type': issue_type,
'description': description,
'env': issue_faced_at,
'issue_key': issue_key,
'issue_link': issue_link,
'conversation_details': conversation_details
}

After defining the final_response and providing the Sample input data (JSON), you can run the code. When the code is executed successfully, you get a program output in JSON format. This format is the same as final_response.

To know more about live testing of your code, click here

This output format needs to be added as a Sample Output JSON Format on Code stepas well to create a connection between Code stepand Output step.

If the format of final_response is wrong, the bot gives a bot break message.

Can’t find what you’re looking for? Email us at support@haptik.ai.