Call Rotation Script

Created by Rob Garcia, Modified on Mon, 29 May 2023 at 04:30 PM by Rob Garcia

In Megadialer there is a possibility of creating a script which will rorate the numbers (contained in different fields). This is possible by adding the below script in to the script section of the dialer, and then adapting the relevant fields to your campaign.


//Phone number rotation
function onUpdate(data){

    if (data.$status === "failed" && data.$status_detail == "$wrong_number" && !data.$phone && (data.telephone_1 || data.telephone_2 || data.mobile)) {
        return {
            $status : "open",
            $status_detail : "$none",
            $phone : data.telephone_1 || data.telephone_2 || data.mobile
        };
    }

    if(data.$status === "open" && data.$status_detail === "$none"){
        var update = {};

        //save the old number ... insert correct phone data.field(s)
        if(!data._phone) update._phone = data._phone = data.$phone;

        //swap phone number array ... insert correct phone data.field(s)
        var numbers = [];
        if(data._phone) numbers.push(data._phone);
        if(data.telephone_1) numbers.push(data.telephone_1);
        if(data.telephone_2) numbers.push(data.telephone_2);
        if(data.mobile) numbers.push(data.mobile);

        var transactions = data.$task_log[data.$task_log.length-1].transactions;
        var lastTx = transactions[transactions.length-1];
        if(lastTx.type === "dial_result" && ["no_response","am_detect","invalid"].indexOf(lastTx.result) >= 0 && lastTx.fired != data._phoneSwapDate){

           if (numbers.length > 1) {
                update.$phone = numbers[Math.floor(numbers.length * Math.random())];
                update._phoneSwapDate = lastTx.fired;
                return update;
           }
        }
    }
    return;
}

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article