Friday 21 April 2017

setTimeout() function not executed properly

I have to send a sms 15 min before the appointment is there. I have written the code, but it is called at the time of execution itself. is there any other method or how do i solve this. "RP.remindePatient" is the function that has to be called 15 min before the appointment time

sendApptConf(s) {

    var number = Phone;
    var msg = urlencode("Hello " );


    var smsData = 'username=' + username + '&hash=' + hash + '&sender=' + sender + '&numbers=' + number + '&message=' + msg;
    var options = {

        host: 'api.textlocal.in',
        path: '/send?' + smsData
    };
    var callback;
    console.log(options);
    callback = function (response) {
        var str = '';

        //another chunk of data has been recieved, so append it to `str`
        response.on('data', function (chunk) {
            console.log("new Data received")
            str += chunk;
            console.log(str);
        });

        //the whole response has been recieved, so we just print it out here
        response.on('end', function () {
            console.log(str);
        });
    }

    http.request(options, callback).end();
    //Send SMS using Textlocal DONE

    const convertTime = consultDate + ' ' + consultTime;

    var d = new Date(convertTime);
    var ms = d.getTime();
    var milliLess15 = ms - (15 * 60 * 1000);

    console.log(milliLess15);

   setTimeout(function () {

       console.log("i should be called after some delay")
       RP.remindePatient(userPhone, patientName, drName, consultMode, consultDate, consultTime, transId, email, paymentDetails);

     }, milliLess15);



via bhanu

No comments:

Post a Comment