node.js - wit.ai runActions how to handle context in follow-up message -


i'm using node-wit develop chatbot application. working fine mostly, i've run problem use of context.

i'm using runactions api :

       this.witclient.runactions(customer._key, messagetext, witcontext).then((newcontext => {} )).catch(reject); 

i have defined number of actions, set context.

this working fine, long context taking place on 1 message. example, if call action called addproduct :

addproduct({sessionid, context, text, entities}) {                  return new promise((resolve, reject) => {                              context.product = `mynewproduct';                             resolve(context);                  });             }, 

it show message using 'product' context key.

however, when try use on 2 messages, seems have lost context ( example, when asking multiple choice question, , handling response ).

if understand how it's working correctly, node-wit doesn't keep context beyond messages ( assumed @ first because i'm passing session key ).

a solution see store resulting context ( newcontext in case) in session/user specific way, , restore , pass again when user sending new message.

meaning, :

witcontext = getcontextfromsession();
this.witclient.runactions(customer._key, messagetext, witcontext).then((newcontext => { setcontextinsession(newcontext) } )).catch(reject);

would correct way of handling ?

off course have store context state, decide how store it. but, take account efficient way if you're gonna have lot of users, , reasources available.

as can see in official example nodejs, there's method named findorcreatesession on https://github.com/wit-ai/node-wit/blob/master/examples/messenger.js session before wit actions called.

in particular case, storing in database, session before action called, can send context, in actions query session again modify resulting context , store again, try best implementation needs.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -