From 37bdc55319e9786c85f520423d5e644590f7c335 Mon Sep 17 00:00:00 2001 From: SadhulaSaiKumar Date: Wed, 30 Aug 2023 05:03:50 +0000 Subject: [PATCH] Upload files to 'chatbot/userdetails/actions' --- chatbot/userdetails/actions/__init__.py | Bin 0 -> 1024 bytes chatbot/userdetails/actions/actions.py | 61 ++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 chatbot/userdetails/actions/__init__.py create mode 100644 chatbot/userdetails/actions/actions.py diff --git a/chatbot/userdetails/actions/__init__.py b/chatbot/userdetails/actions/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..06d7405020018ddf3cacee90fd4af10487da3d20 GIT binary patch literal 1024 ScmZQz7zLvtFd70QH3R?z00031 literal 0 HcmV?d00001 diff --git a/chatbot/userdetails/actions/actions.py b/chatbot/userdetails/actions/actions.py new file mode 100644 index 0000000..f222124 --- /dev/null +++ b/chatbot/userdetails/actions/actions.py @@ -0,0 +1,61 @@ +# 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!" +import openpyxl +from typing import Any, Text, Dict, List +from rasa_sdk import Action, Tracker +from rasa_sdk.executor import CollectingDispatcher +from rasa_sdk.events import SlotSet + +class ActionSayData(Action): + def name(self) -> Text: + return "get_slot_data" + def run(self, dispatcher: CollectingDispatcher, + tracker: Tracker, + domain: Dict[Text, Any]) -> List [Dict[Text, Any]]: + first_name = tracker.get_slot("first_name") + print(first_name) + last_name = tracker.get_slot("last_name") + print(last_name) + phone_num= tracker.get_slot("phone_num") + print(phone_num) + email_id= tracker.get_slot("email_id") + print(email_id) + sender_id = tracker.sender_id + + + def save_user_details_to_excel(details): + try: + workbook = openpyxl.load_workbook('user_details.xlsx') + sheet = workbook.active + except FileNotFoundError: + workbook = openpyxl.Workbook() + sheet = workbook.active + sheet.append(['Name', 'Age', 'Email', 'Phone','recipient_id']) + sheet.append(details) + workbook.save('user_details.xlsx') + + details = [first_name, last_name, phone_num, email_id,sender_id] + save_user_details_to_excel(details) + + + dispatcher.utter_message() + + + return [] + + # Clear the desired slot by setting its value to None +class ActionHelloWorld(Action): + + def name(self) -> Text: + return "slots_to_clear" + + def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: + slots_to_clear = ["first_name", "last_name", "phone_num","email_id"] + events = [SlotSet(slot_name, None) for slot_name in slots_to_clear] + return events \ No newline at end of file