dialogflow / dialogflow-nodejs-client

Node.js SDK for Dialogflow
Apache License 2.0
658 stars 287 forks source link

Information about Unique session Ids missing #32

Closed rishigb closed 7 years ago

rishigb commented 7 years ago

Hi, would you be able to provide more info on 'uniqueSessionIDs' ? How do I find them if I am building an independent web-application?

sstepashka commented 7 years ago

Hi @rishigb See https://docs.api.ai/docs/query#query-parameters-and-json-fields

A string token up to 36 symbols long, used to identify the client and to manage session parameters (including contexts) per client.

rishigb commented 7 years ago

Thank you. I have read this before. My question is how do I generate session Ids if I am building an independent web application. Is there a link you could guide me to?

sstepashka commented 7 years ago

@rishigb

Sorry, but now we doesn't have any detailed guid for sessionId. But, I'll try to explain...

Some data should be stored on server-side (contexts, user entities, etc...), and we should identify current user for store data for each unique user.

For example, you can see to information about slot filling https://docs.api.ai/docs/guidelines-slot-filling

This is concept store some partial data for create dialog.

On your site you can user some session id (like php) or some hashes of user id or email. If your user does not authorized you can generate UUID and store it into cookies and when user has send request, you send his unique id.

oprog commented 7 years ago

@rishigb I used this lib to generate session IDs https://www.npmjs.com/package/node-uuid

and I simply stored sessions in a map (map was enough for my app, of course it could not be the ideal solution)

tnvrbabu commented 6 years ago

How to map the Web Session ID with DialogFlow Session ID?

deyvidm18 commented 5 years ago

How to map the Web Session ID with DialogFlow Session ID?

A way to get this, is to use the local storage on JavaScript

var myStorage = localStorage;
if (!myStorage.getItem("session")) {
    myStorage.setItem("session", createUUID());
  }

function createUUID() {
  // http://www.ietf.org/rfc/rfc4122.txt
  var s = [];
  var hexDigits = "0123456789abcdef";
  for (var i = 0; i < 36; i++) {
    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
  }
  s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
  s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
  s[8] = s[13] = s[18] = s[23] = "-";

  var uuid = s.join("");
  return uuid;
}