node.jschatfuel

how to convert attribute/variable using node js


I created a bot from chat fuel. and it is asking about gender the bot make you choose if male or female..both is set to one attribute gender but what I wanted to do is to change the value of each selected like if I select male the value would be 1 and if female 0 ..

this is what it looks like...

what happen is when it saves to my db gender = male or gender = female what I wanted to achieve is when I select male the value that will be saved is 1 and if female 0 so it would look like on my db gender = 1 if male and gender = 0 if female

router.post('/chatbot_patient', (req, res) => {
    var ref = database.ref('patients');
    var body = _.pick(_.assign(patient, req.body), _.keys(patient));


    body['client_fk'] = req.body['chatfuel user id'];

    req.body['1'] = req.body['male'];
    req.body['0'] = req.body['female'];
    body['gender'] = req.body['gender1'];
    body['createdAt'] = moment().format('YYYY-MM-DD HH:mm:ss');
    ref.push(body);

    res.json({
                 "messages": [
                   {"text": "You are now registered as iWatcher."}
                 ]
                });
});

this is what my node script looks. I tried converting it but it doesn't work.. is there a way to do it on node?


Solution

  • Try to take the value and set it in another variable:

    var gender = req.body['gender'] === 'male' ? 1: 0;