On integrating Wit.ai into a website, is there some way to execute database queries because answers of user questions have to be fetched from the database and that can not be trained to Chatbot.
1 Answers
as you see in the tutorial you define actions in wit.ai, those actions can involve variables who can be send as a response to the users. So, you should make the query to the database in the actions defined by you, if you haven't defined them, then do it, because there is where you can make your logic happens. Also, take into account that you may handle non synchronized petitions to your database, then you should implement a block mechanism to return the context in each action just after you have done you're query.
I know you want to make an implementation in python, but I already have an implementation on node.js, so here is my sample code.
getFullName({sessionId, context, entities}) {
let session;
let fbid = sessionId.split("-")[0];
return fbTypingOn(fbid)
.then(() => {
return model.getSesion(fbid);
})
.then(sesion => {
session = sesion;
return callFbUserAPI(session);
})
.then(first_name => {
session.context.fullNameGreeting = utilsBot.buildGreeting(session);
return model.setSesion(session);
})
.then( sesion => {
return session.context;
})
.catch( error => {
console.log("Error in getFullName " + error);
session.context.fullNameGreeting = "Hola";
return context;
});
}
Make sure you read all documentation in the official page, because if there isn't something, then you should do it. Also, there's already an implementation in python 2, I guess.

- 134
- 1
- 12
-
you're welcome. As you see, my sessionId is compound of the user facebook id and another string, because when you restart the flow in wit.ai you should clear the context and generate a new sessionId. Also, I store more than the sessionId and context in my database. – sgelves Jun 09 '17 at 13:17