Skip to content

Instantly share code, notes, and snippets.

@LakshayNagpal
Created June 15, 2018 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LakshayNagpal/0c68a90173ccc8a072ef6a03d3d1f8ff to your computer and use it in GitHub Desktop.
Save LakshayNagpal/0c68a90173ccc8a072ef6a03d3d1f8ff to your computer and use it in GitHub Desktop.
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