Skip to main content

Unsuccessful call attempts

When developing a script, you need to take into account that the bot cannot always reach the client. For example, the client did not pick up the phone or the number was busy. Such calls are included in the telephony statistics but are not handled in the script.

tip
To handle an unsuccessful call attempt and, for example, schedule a new one, you need to provide the onCallNotConnected event handler in the script.

Configuring chatbot.yaml

Before using the event handler in the script, specify the onCallNotConnected flag in chatbot.yaml:

additionalEvents:
- onCallNotConnected

If the bot fails to reach the client, it receives the onCallNotConnected event.

How to use

Consider the following example in which the bot failed to reach the client.

state: OnCallNotConnected
event: onCallNotConnected
script:
$dialer.setCallResult("Failed to reach the client. Reason: " + $dialer.getCallNotConnectedReason());
var now = new Date();
$dialer.redial({
startDateTime: new Date(now.getTime() + 60 * 60000), // Another call in an hour
maxAttempts: 2, // 2 call attempts in total
retryIntervalInMinutes: 5 // 5-minute pause between attempts
});

When the onCallNotConnected event is triggered, $dialer.getCallNotConnectedReason returns the reason the call failed and $dialer.setCallResult sets its result in call campaign and session reports. The following message will appear: Failed to reach the client. Reason: NO_ANSWER.

tip
To determine the reason the bot could not reach the client, use the $dialer.getCallNotConnectedReason method. It returns a string: BUSY or NO_ANSWER.

Then the new call will be rescheduled in an hour via the $dialer.redial method.