Fallback Handler

Introduction

When a bot receives an input message that it can’t understand, it will reply with a message configured in the Fallback handler function. If you wish to customize the default response message to give a reply of your own, you can configure the fallback handler function based on your bot’s specific needs.

In addition to the system defined input arguements of an Execution function, the Fallback 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 Fallback handler function returns a map whose structure is similar to the return map of an Execution function.

Note :
  1. If the chosen development platform of your ConvoKraft bot is either Catalyst functions or Webhooks, you can enable the handler from the console and define the logic of your handler functions either in the Integration function or in the codebase associated with the configured webhook URL respectively.

  2. The response status for success scenarios of the fallback handler function should be configured as handled. If not, the status will be considered as failure. The return response of the function depends on the logic configured in the fallback function handler. This is applicable to both Catalyst functions and Webhooks.

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

    
copy
import org.json.JSONObject; import java.io.*; import java.util.logging.Logger; public class FallbackHandler { Logger LOGGER = Logger.getLogger(FallbackHandler.class.getName()); public JSONObject handleFallbackRequest(JSONObject reqBody) throws Exception{ JSONObject jsonResponse = new JSONObject(); LOGGER.info("Fallback Handler : : TODO : "+ reqBody.get("todo")); jsonResponse.put("message", "Fallback Response: Please define this question and try again"); return jsonResponse; } }

Node.js

    
copy
import logger from "./logger.js"; // Handle the fallback functionality export default function handleFallback() { logger.info('Handling fallback request'); return { "message": "Fallback Response: Please define this question and try again" }; }

Python

    
copy
import logging def handle_fallback_request(): # This is your Fallback Response Handler. # You need to write the Fallback Response when the bot doesnt know what to respond to users. # The way to return fallback message is to be returned is as follows : # { # 'message': 'Fallback Response: Please define this question and try again' # } # Sample code to set the same is available Below. logging.info('Handling fallback request') return { 'message': 'Fallback Response: Please define this question and try again' }

Last Updated 2024-06-11 18:57:28 +0530 +0530

ON THIS PAGE