0
我試圖創建一個bot函數,使它能夠存儲計劃ID以及當前工作,多年的經驗和用戶的工作數量。但是出現「createJson不是函數」。我已經宣佈是一個功能。這個列表並沒有在那裏停止,但是日誌會話停止了這個問題,請幫我解決這個問題。謝謝...createJson不是函數
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
}))
})
也許調用函數 「createJson」 將是你的變種createJson的聲明後=函數()......試試吧。 – Roth