Bot Failure Handler

This handler gets invoked when the actions returned in the other handlers fail to execute. Example, when the message handler returns an action to forward the chat to an operator, and if the operator is not available, the failure handler gets invoked.

InputsTypeDescription
visitorMapDetails of the website visitor
causeMapThe cause of the failure (code, desc)
failed_responseMapThe previous response for the object due to which the action had failed.
requestMapDetails of the request

Error Response Format:

In case of failure, the input parameters for the failure handler will have the param map "cause," which contains information about the failure. It contains 2 keys, namely the "code" (unique error code) and the "desc" (description of the error)

Action: Forward

1. Forward chat to the operator during offline hours:

This error occurs when the bot tries to forward a chat after business hours.

code: 1001 ,
desc: "offline_hours"
 
2. Operator unavailable during business hours:

This error occurs when the bot tries to forward the chat to the operators during business hours, but no operator is available to take up the chat.

code: 1002,
desc: "operators_not_available"
 
3. Operator's email address is invalid or inactive in the portal:

This error occurs when the bot tries to forward the chat, and the given operator's email address is invalid or inactive in the portal.

code: 1003 ,
desc: "invalid_operators"

Action: Reply

4. Character limit exceeded in reply:

This error occurs when the chat reply length exceeds the allowed character limit, for example, If the character limit for a reply is 250 and the reply consists of 256 characters.

code: 1005 ,
desc: more_than_max_length
 
5. Execution failure:

This error occurs when there is a timeout exception or an invalid execution result. You can handle this case inside the Failure handler.

code: 1007 ,
desc: "execution_failure"

 

Failure Handler in Script

To embed the failure handler script:

  • Navigate to Settings > Bot > Zobot, click Add.
  • Enter the name, choose the platform - SalesIQ Scripts and then choose the brand. 
  • The Deluge code builder will appear.
  • Then, choose the Failure Handler in the drop-down.
  • And then draft the script in the Failure handler section, click Save, and Publish.

Note: The Failure handler code will be disabled by default, but if you wish to set up failure responses, you can enable it.

 

Sample Code:

Copiedresponse = Map();
if(failed_response.get("action").equalsIgnoreCase("forward"))
  {
    code = cause.get("code").toNumber();
    if(code == 1001)
    {
      // Outside business hours
      response.put("action","reply");
      response.put("replies",{"It seems that this is off working hours for us","Leave us a message and we will get back to you"});
    }
    else if(code == 1002)
    {
      // operators_not_available
      response.put("action","reply");
      response.put("replies",{"All our agents are busy at the moment","Leave us a message and we will get back to you"});
    }
    else if(code == 1003)
    {
      // invalid_operators - Operators may be disabled or invalid
      response.put("action","reply");
      response.put("replies",{"All our agents are busy at the moment","Leave us a message and we will get back to you"});
    }
  }
return response;

In this example, we have used a travel website called Zylker travels. And the bot acts as a travel assistant and guides the visitors visiting the website. Here, the failure handler will be invoked once the bot is configured to forward the chat to the operator, but currently, no operator is available to take the chat. So, a response stating the failure of the action is sent to the visitor.