12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- # 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
|