MySQL query using slots

Hello @shena for mysql query you have to use my sql connector in your action.py file

import mysql.connector as mysql

class ActionAPI(Action):
    def name(self) -> Text:
        return "action_api"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        db = mysql.connect(
            host="localhost/host_url",
            user="user_name",
            passwd="password",
            database="database_name"
        )
        cursor = db.cursor()

        query = "SELECT name FROM student where id = 14"
        cursor.execute(query)
        records = cursor.fetchall()
        for record in records:
            print(record)
            records = """The detail is as follows {}.""".format(record)
        dispatcher.utter_message(records)
        return []

use above code in your example.

1 Like