Answers for "rasa mysql connection custom actions example"

SQL
0

rasa mysql connection custom actions example

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 []
Posted by: Guest on May-08-2022

Code answers related to "rasa mysql connection custom actions example"

Code answers related to "SQL"

Browse Popular Code Answers by Language