AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

User Variables vs. Session Variables and Database Connectivity
 
 

We are building a travel bot with ChatScript. We have a need to have a few variables which apply to user (and thus for all sessions with the user) and other variables which should be valid only for the session.

Example -
We need to remember where the user lives and their address. When the user re-connects to our bot, the bot need not ask for these details again once provided.

While the user’s home location does not change, the user’s travel itinerary changes for each session. The first time, the user wants to go from New Delhi to New York, the second time from Bangalore to San Francisco, etc.

The user’s $homelocation variable should not be cleared between sessions, but $from and $to must be reset at the beginning of each session.

What is the recommended way to do this in ChatScript?

As a related question, can we connect the bot to a database. For instance, user’s address is loaded from a database instead of storing in file system?

 

 
  [ # 1 ]

session variables can be passed in as OOB data, probably best as a json struct built transiently. If you do that every volley in the session, then you can just access them as facts whenever you need them.  Otherwise you could just pass it once at start of a session built permanently (with some mark that this is start of session so chatbot could delete the prior json data).

CS supports directly talking to Postgres and Mongo databases. And it supports calling out to external website apis via TCPOPEN or JSONOPEN(recommended).

 

 
  [ # 2 ]

Hello Bruce, Thank you for the response. How do we pass the OOB data? From the control script?

 

 
  [ # 3 ]

I think you are asking, how do you receive it. Yes, in the control script. It probably has something that looks like this…

passing in every volley:
u: ( \[ _* \]  ) 

$sessiondata = ^jsonparse(transient ‘_0)
^end(sentence)


Assuming most of your data is top level in a json object, you can access when you need it via
$$location = ^jsonpath(.location $$sessiondata)

if you dont want to pass it every volley, then
u: ( \[ _* \]  _0 )
^jsondelete($sessiondata)
$sessiondata = ^jsonparse(permanent ‘_0)
^end(sentence)

 

 
  [ # 4 ]

This might sound trivial, but how do I identify the start of the session?

I am doing this by setting below in control script

$sessionstart 

And I reset the session variables in my top file:

topic: ~T_MAIN nostay []

t
: ($sessionstart)
   
$X=null
   $Y
=null
   $sessionstart
=null
   Hi 
%userI am your friendly travel botI will help you plan your travel.
   ^
respond(~T_INTRO

When I close the chat window and reopen (without doing a :reset or deleting user files), shouldn’t $sessionstart be set to 1? I am seeing $sessionstart is set to null and hence the above “main gambit” is not being called.

$X and $Y are variables I set based on user input. When the user opens a new session, bot should not remember these values from previous session.

 

 
  [ # 5 ]

Hello Bruce,

You mentioned “with some mark that this is start of session so chatbot could delete the prior json data”—we are trying to set this mark. Is the approach in the previous answer right? What do you suggest?

 

 
  [ # 6 ]

Are you going to pass session data only at the start of each session, or repeat it per volley?

if once, then obviously the existence of the oob data IS a session mark. You create data permanently and delete on next session arrival.

if always, then you just create data transiently and it self-deletes.

 

 
  [ # 7 ]

Hello Bruce, we want to set only at the start of each session, not per volley.

I have tried to simplify the issue and have posted a new thread: https://www.chatbots.org/ai_zone/viewthread/2647/

 

 
  login or register to react