No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

actions.py 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # This files contains your custom actions which can be used to run
  2. # custom Python code.
  3. #
  4. # See this guide on how to implement these action:
  5. # https://rasa.com/docs/rasa/custom-actions
  6. # This is a simple example for a custom action which utters "Hello World!"
  7. import openpyxl
  8. from typing import Any, Text, Dict, List
  9. from rasa_sdk import Action, Tracker
  10. from rasa_sdk.executor import CollectingDispatcher
  11. from rasa_sdk.events import SlotSet
  12. class ActionSayData(Action):
  13. def name(self) -> Text:
  14. return "get_slot_data"
  15. def run(self, dispatcher: CollectingDispatcher,
  16. tracker: Tracker,
  17. domain: Dict[Text, Any]) -> List [Dict[Text, Any]]:
  18. first_name = tracker.get_slot("first_name")
  19. print(first_name)
  20. last_name = tracker.get_slot("last_name")
  21. print(last_name)
  22. phone_num= tracker.get_slot("phone_num")
  23. print(phone_num)
  24. email_id= tracker.get_slot("email_id")
  25. print(email_id)
  26. sender_id = tracker.sender_id
  27. def save_user_details_to_excel(details):
  28. try:
  29. workbook = openpyxl.load_workbook('user_details.xlsx')
  30. sheet = workbook.active
  31. except FileNotFoundError:
  32. workbook = openpyxl.Workbook()
  33. sheet = workbook.active
  34. sheet.append(['Name', 'Age', 'Email', 'Phone','recipient_id'])
  35. sheet.append(details)
  36. workbook.save('user_details.xlsx')
  37. details = [first_name, last_name, phone_num, email_id,sender_id]
  38. save_user_details_to_excel(details)
  39. dispatcher.utter_message()
  40. return []
  41. # Clear the desired slot by setting its value to None
  42. class ActionHelloWorld(Action):
  43. def name(self) -> Text:
  44. return "slots_to_clear"
  45. def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
  46. slots_to_clear = ["first_name", "last_name", "phone_num","email_id"]
  47. events = [SlotSet(slot_name, None) for slot_name in slots_to_clear]
  48. return events