Hi, I want to connect mysql db to bot rasa.
Rasa version:
Rasa Version : 2.8.1
Minimum Compatible Version: 2.8.0
Rasa SDK Version : 2.8.1
Rasa X Version : 0.39.3
Python Version : 3.8.13
I created a db_connect.py file in “actions” folder in this way:
import mysql.connector
def DataFetch(luogo, preferenza, dispatcher):
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="",
database="itourist"
)
mycursor = mydb.cursor()
sql = 'select Risultato from itourist.riscontro WHERE Luogo={"0"} && Preferenza={"1"} ordered by rand() limit 1;'.format(luogo, preferenza)
try:
#Execute the SQL Query
mycursor.execute(sql)
result = db.query(sql)
#Now print fetched data
dispatcher.utter_message(result)
except:
dispatcher.utter_message("Error : Unable to fetch data.")
and I added this action in actions.py file :
from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from db_connect import DataFetch
class ActionFetchData(Action):
def name(self):
return "action_match_events" # Be careful, did you mean action_fetch_data?
def run(self, dispatcher, tracker, domain):
DataFetch(tracker.get_slot("luogo"), tracker.get_slot("preferenza"), dispatcher)
return []
But I have a problem: rasa train → works rasa run actions → works rasa shell → works but when the bot has to do that action , a message in the terminal appers :
File “C:\Users\luigi\Desktop\esempi_rasa\provautf\actions\actions.py”, line 14, in import db_connect ModuleNotFoundError: No module named ‘db_connect’
can you help me please? The purpose of the query is to show a casual result after matching 2 slots (rasa) with 2 fields of table in db.