node.js - createJson is not a function -
i'm trying create bot function enable store plan id along current job, years of experience , number of jobs of user. "createjson not function" appears. declared function. , list ain't stopping there log session stops on problem, please need lot of one. thanks...
const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeapp(functions.config().firebase); var fs = require('fs'); var moment = require('moment'); exports.hellohttp = functions.https.onrequest((req, res) => { if (req.body.result && (req.body.result.parameters || req.body.result.action || req.body.result.contexts)) { var userquery = req.body.result.resolvedquery || {}; var action = req.body.result.action || {}; var parameters = req.body.result.parameters || {}; var plan_id = req.body.result.parameters.plan_id || {}; createjson(); var data = json.stringify(cjson); fs.writefilesync('psedo json.json', data); var createjson = function() { userprofile(); var time = moment().format(); var cjson = { timestamp: time, lang: 'en', userinfo: { planid: iplanid, currentwork: icurjob, workexp: iyearexp, numberjob: inumjob } }; } var userprofile = function() { if (action == "get_plan_id") { inplanid(); if (action == "update_user_info" && cur_job !== null && num_job !== null && yr_exp !== null) { incurjob(); inumjob(); inyearexp(); } } } var inplanid = function() { var iplanid = req.body.result.parameters.plan_id; return [iplanid]; } var incurjob = function() { var cur_job = req.body.result.parameters.cur-job || {}; var icurjob = req.body.result.parameters.cur-job; return [icurjob]; } var inyearexp = function() { var yr_exp = req.body.result.parameters.yr-exp || {}; var iyearexp = req.body.result.parameters.yr-exp; return [iyearexp]; } var innumjob = function() { var num_job = req.body.result.parameters.number-job || {}; var inumjob = req.body.result.parameters.number-job; return [inumjob]; } } res.setheader('content-type', 'application/json'); //requires application/json mime type res.send(json.stringify({ "speech": response, "displaytext": response })) })
function expressions hoisted w/o value other variables do.
if want hoist value should use function statement instead
function createjson() { userprofile(); var time = moment().format(); var cjson = { timestamp: time, lang: 'en', userinfo: { planid: iplanid, currentwork: icurjob, workexp: iyearexp, numberjob: inumjob } }; }
and same rest of functions.
console.log(typeof x, typeof y) var x = function(){} function y() {}
Comments
Post a Comment