RASA MySQL Connection Connection Actions Przykład

from typing import Any, Text, Dict, List

from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.events import Form, AllSlotsReset, Restarted
import config
import mysql.connector as sql

class ActionPasswordReset(Action):

    def name(self) -> Text:
        return "action_password_reset"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:


        connection = sql.connect(
        host=config.host,
        user=config.user,
        password=config.password,
        database=config.database
        )
        cursor = connection.cursor()
        email = str(tracker.get_slot("email")).lower()
        cursor.execute("Select * from {} where Email='{}' ".format(config.LOGIN_TABLE_NAME, email))
        result = cursor.fetchall()
        if len(result) == 0:
            dispatcher.utter_message("Sorry we couldn't find Email in our database")
        else:
            dispatcher.utter_message("Here is your details: email : {} password: {}".format(result[0][0], result[0][1]))
        # dispatcher.utter_message(text="Hello World!")

        return []
Frantic Fly