virtual-storage
v0.2.0
Published
Virtual Storage (node) for those who do not have access to localStorage like Dialogflow
Downloads
4
Maintainers
Readme
virtual-storage
Virtual Storage (node) for those who do not have access to localStorage like Dialogflow
Insert in project
vStorage = require('virtual-storage');
Basic Usage
Create a virtual storage:
vStorage.set('name', 'value')
Read virtual storage:
vStorage.get('name') // => 'value'
vStorage.get('nothing') // => undefined
Delete virtual storage:
vStorage.remove('name')
Delete virtual storage by name:
vStorage.remove('name')
Delete all virtual storage:
vStorage.remove()
When deleting a virtual storage it will generate a empty array {}
Simple set / get example:
let json = [{title:'Title 1', description:'Descriptions 1'},{title:'Title 2', description:'Descriptions 2'}];
vStorage.set('json_infos', json);
Get json infos
let json_info = vStorage.get('json_infos');
let tile_1 = json_info[0].title; // Title 1
let description_2 = json_info[1].description // Descriptions 2
For Dialogflow
You may need a uniq name / key for your app. like Dialogflow.
Create a uniq name for Dialogflow:
You can create a uniq id at the top of your app.js file like this.
const sessionID = new Date().getTime(); // or any code you may find on the web
vStorage.set('name'+sessionID, store_json_response);
Get stored values
vStorage.get('name'+sessionID);
Or with Dialogflow session id.
let sessionID = vStorage.set('json_list'+SessionID(conv.body.session);
vStorage.set('uniq_name'+sessionID, store_json_response);
Get stored values
let getmyjsonStorage = vStorage.get('uniq_name'+sessionID);
// Get only the id part from Dialogflow conv response
function SessionID(sID) {
var n = sID.lastIndexOf('/');
return sID.substring(n + 1);
}