I'm working on a chatbot project which fetches "delivery status" information from a database. I've defined a function (lets call it db_info) which will connect to my DB and then get the results.
I have a .json file which has different intents like "Greeting", "Status Check", "Closing" etc. The way the application works is - whenever the user types in something, the text is classified into an intent. For ex: when the user types "Hi" the application recognizes it is from the intent "Greeting" and then gives out one of the responses I hard coded in the .json file.
However, for the "Status Check" intent I don't want the application to give out some hard coded response from .json file. Instead, I'd like it to call the db_info function when the intent "Status Check" is identified.
I'm aware that a function map (dictionary) can be created in .py file and then its value can be called in the json file. But I'm not sure how this is done exactly.
def db_info(): --> lives in .py file
# connect to postgres and get some information
if intent == 'greetings':
# pick random statement from "responses" of tag "greeting" from json file
if intent == 'status_check':
# go to "responses" under tag "status_check" and run the func mentioned there
def db_info():
# instead of picking up a random statement from "response" this func needs to be called
My json file:
{"tag": "greetings",
"pattern": ["Hi", "How are you", "Hey", "Hello", "Good Day"],
"responses": ["Hello!", "Hey there", "Hi, how can I help you today?"]
},
{"tag": "status_check",
"pattern": ["Where's my shipment", "Track my shipment"],
"responses": ["GetDBInfo function"]
}