Failure Handler
Introduction
When an exception occurs for the user input message, the bot will reply with a message configured in the Failure handler function. If you wish to customize the default response message to give a reply of your own, you can configure the Failure Handler function based on your bot’s specific needs.
In addition to the system defined input arguements of an execution function, the Failure handler function includes a custom argument called the userInput of String datatype, that stores the latest response from the user in the current chat session. The Failure handler function returns a map whose structure is similar to the return map of an Execution function.
To learn more about defining handler functions in Deluge, please refer to this page.
If you have chosen your development platform to be Functions, you can use the below listed sample codes for the Java, Node.js and Python stacks :
Java
copyimport org.json.JSONObject; import java.io.*; import java.util.logging.Logger; public class FailureHandler { Logger LOGGER = Logger.getLogger(FailureHandler.class.getName()); public JSONObject handleFailureRequest(JSONObject reqBody) throws Exception{ JSONObject jsonResponse = new JSONObject(); LOGGER.info("Failure Handler : : TODO : " + reqBody.get("todo")); jsonResponse.put("message", "Failure Response: Please define this question and try again"); return jsonResponse; } }
Node.js
copyimport logger from "./logger.js"; // Handle the failure functionality export default function handleFailure() { logger.info('Handling failure request'); return { "message": "Failure Response: Please define this question and try again" }; }
Python
copyimport logging def handle_failure_request(): # This is your Failure Response Handler. # You need to write the Failure Response when the bot Fails during execution of the function. # The way to return Failure message is to be returned is as follows : # { # 'message': 'Sorry, Something went wrong' # } # Sample code to set the same is available Below. logging.info('Handling failure request') return { 'message': 'Failure Response: Please define this question and try again' }
Last Updated 2024-06-11 18:57:28 +0530 +0530
Yes
No
Send your feedback to us