Hi! I have a problem with the custom action in Rasa. I want to do a custom action can recognize more entities at the same time and from there use a sql server (with pyodbc) to search this “information” . My problem is to set the multiple entities, do you know if is possible? this is my action.py:
class SearchContratti(Action):
def name(self):
return "search_contratti"
def run(self, dispatcher, tracker, domain):
db = pyodbc.connect(
"DRIVER={SQL Server};"
"SERVER=tcp:###;"
"DATABASE=###;"
"UID=###;PWD=###;")
cursor = db.cursor()
contract = tracker.get_slot('tipo_contratto')
query = "SELECT TOP 5 * FROM ### WHERE ### like '{0}%'".format(contract)
try:
cursor.execute(query)
results = cursor.fetchall()
for row in results:
dispatcher.utter_message("contratto :{}".format(row))
except:
print("Error fetching data.")
finally:
db.close()
return
class SearchFromAList(Action):
def name(self):
return "search_specify"
def run(self, dispatcher, tracker, domain):
db = pyodbc.connect(
"DRIVER={SQL Server};"
"SERVER=tcp:###;"
"DATABASE=###;"
"UID=###;PWD=###;")
cursor = db.cursor()
contract= tracker.get_slot('tipo_contratto')
specify =tracker.get_slot('specifico')
query = "SELECT TOP 5 * FROM ### WHERE### like '{0}%'".format(contract,specify)
try:
cursor.execute(query)
results = cursor.fetchall()
for row in results:
dispatcher.utter_message("contratto :{}".format(row))
except:
print("Error fetching data.")
finally:
db.close()
return
The first action run perfectly but the second not. If it’s possible I want that the user after a list of contract can specify which type he/she choose. But I think that the only way is to do a new request to sql server with two parameters. I don’t know if there is a solution, I also tried other way but the answer is always the same, the request doesn’t return nothing or there is an error to fetch data. I hope that my request is clear, thank you very much! Daniela