Created
June 15, 2018 08:28
-
-
Save LakshayNagpal/0c68a90173ccc8a072ef6a03d3d1f8ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let userStorage = request.body.originalDetectIntentRequest.payload.user.userStorage || JSON.stringify({}); | |
let userId; | |
console.log("userStorage", userStorage); | |
userStorage = JSON.parse(userStorage); | |
console.log("userStorage_after_parsing", userStorage); | |
if (userStorage.hasOwnProperty('userId')) { | |
userId = userStorage.userId; | |
console.log("userID In if", userId); | |
} else { | |
// Uses the "uuid" package. You can get this with "npm install --save uuid" | |
// var uuid = require('uuid/v4'); | |
var uuid = require('uuid/v4'); | |
userId = uuid(); | |
userStorage.userId = userId | |
} | |
console.log("userID", userId); | |
//SENDING RESPONSE | |
response.send({ | |
'fulfillmentText' : `We both hit ${runs} runs. Sorry, You're out on the first ball! \nUnluckily, Your total score is 0 run. \nWould you like to play again with me?`, | |
'payload': { | |
'google': { | |
'userStorage': JSON.stringify(userStorage) | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment