Calling a custom function in Rasa Actions

rasa-core

(Sivaram) #1

I am facing a problem in developing a chatbot using rasa .

I am trying to call a custom function in rasa action file. But i am getting an error saying “name ‘areThereAnyErrors’ is not defined”

here is my action class. I want to call areThereAnyErrors function from run method. Could someone please help how to resolve this?

class ActionDayStatus(Action):

def areThereAnyErrors(procid):
    errormessagecursor = connection.cursor()
    errormessagecursor.execute(u"select  count(*) from MT_PROSS_MEAGE where pro_id = :procid and msg_T =    :messageT",{"procid": procid, "messageT": 'E'})
    counts = errormessagecursor.fetchone()
    errorCount = counts[0]
    print("error count is {}".format(errorCount))
    if errorCount == 0:
        return False
    else:
        return True

def name(self):
    return 'action_day_status'

def run(self, dispatcher, tracker, domain):
    import cx_Oracle
    import datetime
        # Connect as user "hr" with password "welcome" to the "oraclepdb" service running on this computer.
    conn_str = dbconnection
    connection = cx_Oracle.connect(conn_str)
    cursor = connection.cursor()
    dateIndicator = tracker.get_slot('requiredDate')
    delta = datetime.timedelta(days = 1)
    now = datetime.datetime.now()
    currentDate = (now - delta).strftime('%Y-%m-%d')
    print(currentDate)
    cursor = connection.cursor()

    cursor.execute(u"select  * from M_POCESS_FILE where CREATE_DATE >= TO_DATE(:createDate,'YYYY/MM/DD') fetch first 50 rows only",{"createDate":currentDate})

    all_files = cursor.fetchall()
    total_number_of_files = len(all_files)

    print("total_number_of_files are {}".format(total_number_of_files))

(Deepak Shetty) #2

https://realpython.com/instance-class-and-static-methods-demystified/ Decide whether you want a static method or class method or instance method and call it appropriately . Also when you are using connection within the function it should be a member variable or passed to the method You dont have self as aparameter so you may be intending it as a static method - but you dont have it created as such