How to understand this custom function in action.py

If I need to write any function like for example “Date and Time” then how should I write custom function and how to match details in all the files like nlu,domain and stories.

I know how to write normal functions but I didn’t get clarity how write functions and link the function with different files. I tried it but I’m getting error.

class DateTime(Action):

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

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

        date = datetime.now().date()
        time = datetime.now().time()
        print("Today's Date: ",date,"and Time: ",time)


        dispatcher.utter_message(template='utter_datetime')

        return []

Hello @skjainmiah

I am not sure what you mean by “link the function with different files”. Your domain file should list action_date_time as an action, and you should use that action in some stories. Also, I suspect you actually want your bot to utter the text that you currently print out? Then you should use dispatcher.utter_message(text=f"Today's Date: {date} and Time: {time}").