|
- # This files contains your custom actions which can be used to run
- # custom Python code.
- #
- # See this guide on how to implement these action:
- # https://rasa.com/docs/rasa/custom-actions
-
-
- # This is a simple example for a custom action which utters "Hello World!"
-
- from typing import Any, Text, Dict, List
-
- from rasa_sdk import Action, Tracker
- from rasa_sdk.executor import CollectingDispatcher
- from connect_to_database import UpdateData
- import datetime
- #
- #
- # class ActionHelloWorld(Action):
- #
- # def name(self) -> Text:
- # return "action_hello_world"
- #
- # def run(self, dispatcher: CollectingDispatcher,
- # tracker: Tracker,
- # domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
- #
- # dispatcher.utter_message(text="Hello World!")
- #
- # return []
-
- #FOR GETTING THE USER'S BROWSER AND DEVICE INFORMATION THROUGH CUSTOM DATA.
- # class ActionGetData(Action):
-
- # def name(self) -> Text:
- # return "action_get_data"
-
- # def run(self, dispatcher: CollectingDispatcher,
- # tracker: Tracker,
- # domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
-
- # events = tracker.current_state()['events']
- # user_events = []
- # for e in events:
- # if e['event'] == 'user':
- # user_events.append(e)
-
- # custom_data = user_events[-1]['metadata']
- # print(custom_data)
-
- # return []
-
-
-
- #FOR DATABASE CONNECTIVITY AND UPDATION (NAME, EMAIL, DATE, SESSION ID).
- # class ActionSubmit(Action):
- # def name(self) -> Text:
- # return "action_submit"
-
- # def run(self, dispatcher: CollectingDispatcher,
- # tracker: Tracker,
- # domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
-
- # current_time = str(datetime.datetime.now())
- # current_time = current_time.split(":")
- # current_time = current_time[0] + ":" + current_time[1]
- # DataUpdate(tracker.get_slot("name"),tracker.get_slot("email"), current_time, tracker.sender_id)
-
-
- #GET THE USER'S BROWSER AND DEVICE INFORMATION THROUGH INIT PAYLOAD AND UPDATE THE TABLE USER_DEVICE_IMFORMATION.
- class ActionUpdateData(Action):
- def name(self) -> Text:
- return "action_update_data"
-
- def run(self, dispatcher: CollectingDispatcher,
- tracker: Tracker,
- domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
-
- device = tracker.get_slot("device_and_browser").split(",")[0].capitalize()
- browser = tracker.get_slot("device_and_browser").split(",")[1].capitalize()
-
- current_time = str(datetime.datetime.now())
- current_time = current_time.split(":")
- current_time = current_time[0] + ":" + current_time[1]
- current_time = datetime.datetime.strptime(current_time, "%Y-%m-%d %H:%M")
-
- UpdateData(device, browser, current_time, tracker.sender_id)
-
-
|