Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function saveContexts(userId, contexts) {
- let UID = userId;
- //get all contexts + parameters
- if (contexts === undefined) {
- console.log("contexts are undefined! returning");
- return false;
- }
- db.collection("user-contexts-prod").doc(UID).set({
- dateCreated: new Date(),
- contexts: JSON.stringify(contexts)
- })
- .then(function () {
- console.log("success!");
- return true;
- })
- .catch(function (error) {
- console.log("error writing document..", error);
- return false;
- });
- }
- async function getContexts(userId) {
- let UID = userId;
- let docRef = db.collection("user-contexts-prod").doc(UID);
- return docRef.get()
- .then(res => {
- if (res.exists) {
- let contexts = JSON.parse(res.data().contexts);
- console.log("<><> parsed contexts <><>: ");
- console.log(contexts);
- return contexts;
- } else {
- console.log(" UID DOES NOT EXIST!");
- return false;
- }
- })
- }
- knownUser = await db.isKnownUser(senderId);
- if (knownUser) {
- //knownUser
- console.log("Known user");
- let userData = db.getUserDataById(senderId)
- //initialize contexts with data you need
- payload = returningUser_useSameData();
- messenger.send(payload, senderId);
- dashbot.logBotMessage(payload.toString, sessionId, intentName);
- break;
- } else {
- //newUser
- console.log("new user");
- createContext('await_fillInTogether', '', sessionPath, sessionId, 1);
- createContext('session', '', sessionPath, sessionId, 500);
- payload = fillInTogetherNewUser();
- messenger.send(payload, senderId);
- dashbot.logBotMessage(payload.toString, sessionId, intentName);
- break;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement