var https = require('https');

module.exports = function (context, req) {
    //context.log('context:', JSON.stringify(context, null, 2));
    context.log(process.env[functionUrl]);
    var input = JSON.stringify(req.body);
    var command = input.split('&')[7].split('=')[1];
    var userquery = input.split('&')[8].split('=')[1];
    var callback = input.split('&')[9].split('=')[1];
    var username = input.split('&')[6].split('=')[1];

    // define function to call other Azure function to get the weather
    function getMetar(icaocode) {

        context.log(`https://${process.env[functionUrl]}/api/metarSlackbot?icao=${icaocode}&callback=${callback}&user=${username}`);

        https.get(`https://${process.env[functionUrl]}/api/metarSlackbot?icao=${icaocode}&callback=${callback}&user=${username}`, function (res) {
            var body = ''; // Will contain the final response
            // Received data is a buffer.
            // Adding it to our body
            res.on('data', function (data) {
                body += data;
            });
            // After the response is completed, parse it and log it to the console
            res.on('end', function () {
                var parsed = JSON.parse(body);
                context.log(parsed);
            });
        })
            // If any error has occured, log error to console
            .on('error', function (e) {
                context.log("Got error: " + e.message);
            });
    }

    function getFlightStatus(flightnumber) {
        if (req.query.simple == "true") {
        context.log(`https://${process.env[functionUrl]}/api/flightStatus?flightnumber=${flightnumber}&callback=${callback}&user=${username}&simple=true`);
        https.get(`https://${process.env[functionUrl]}/api/flightStatus?flightnumber=${flightnumber}&callback=${callback}&user=${username}&simple=true`, function (res) {
            var body = ''; // Will contain the final response
            // Received data is a buffer.
            // Adding it to our body
            res.on('data', function (data) {
                body += data;
            });
            // After the response is completed, parse it and log it to the console
            res.on('end', function () {
                var parsed = JSON.parse(body);
                context.log(parsed);
            });
        })
            // If any error has occured, log error to console
            .on('error', function (e) {
                context.log("Got error: " + e.message);
            });
        } else {
        context.log(`https://${process.env[functionUrl]}/api/flightStatus?flightnumber=${flightnumber}&callback=${callback}&user=${username}`);
        https.get(`https://${process.env[functionUrl]}/api/flightStatus?flightnumber=${flightnumber}&callback=${callback}&user=${username}`, function (res) {  
            var body = ''; // Will contain the final response
            // Received data is a buffer.
            // Adding it to our body
            res.on('data', function (data) {
                body += data;
            });
            // After the response is completed, parse it and log it to the console
            res.on('end', function () {
                var parsed = JSON.parse(body);
                context.log(parsed);
            });
        })
            // If any error has occured, log error to console
            .on('error', function (e) {
                context.log("Got error: " + e.message);
            });  
        }       
    }

    context.log('Command was %s', command); 
    context.log('Input was %s', userquery);
    
    if (command == '%2Fmetar') {

        context.bindings.response = `Hello ${username}, I am getting your weather for ${userquery}, try again if you have not heard back in 20s.`;

        getMetar(userquery);

        context.done();
    }
    else if (command == '%2Fflightstatus') {
        context.bindings.response = `Hello ${username}, I am getting the status for ${userquery}, try again if you have not heard back in 20s.`;
        getFlightStatus(userquery);
        context.done();
    }
};
@@ -156,32 +156,33 @@
 log(process.env%5B
+%22
 functionUrl%5D);%0D%0A
@@ -176,16 +176,17 @@
 ctionUrl
+%22
 %5D);%0D%0A   
@@ -591,32 +591,33 @@
 //$%7Bprocess.env%5B
+%22
 functionUrl%5D%7D/ap
@@ -603,32 +603,33 @@
 env%5B%22functionUrl
+%22
 %5D%7D/api/metarSlac
@@ -727,32 +727,33 @@
 //$%7Bprocess.env%5B
+%22
 functionUrl%5D%7D/ap
@@ -743,24 +743,25 @@
 %22functionUrl
+%22
 %5D%7D/api/metar
@@ -1633,32 +1633,33 @@
 //$%7Bprocess.env%5B
+%22
 functionUrl%5D%7D/ap
@@ -1645,32 +1645,33 @@
 env%5B%22functionUrl
+%22
 %5D%7D/api/flightSta
@@ -1790,32 +1790,33 @@
 //$%7Bprocess.env%5B
+%22
 functionUrl%5D%7D/ap
@@ -1802,32 +1802,33 @@
 env%5B%22functionUrl
+%22
 %5D%7D/api/flightSta
@@ -2639,32 +2639,33 @@
 //$%7Bprocess.env%5B
+%22
 functionUrl%5D%7D/ap
@@ -2651,32 +2651,33 @@
 env%5B%22functionUrl
+%22
 %5D%7D/api/flightSta
@@ -2792,16 +2792,17 @@
 ess.env%5B
+%22
 function
@@ -2804,16 +2804,17 @@
 ctionUrl
+%22
 %5D%7D/api/f

Fix syntax.