|
@@ -0,0 +1,61 @@
|
|
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
|
+
|
|
7
|
+
|
|
8
|
+# This is a simple example for a custom action which utters "Hello World!"
|
|
9
|
+import openpyxl
|
|
10
|
+from typing import Any, Text, Dict, List
|
|
11
|
+from rasa_sdk import Action, Tracker
|
|
12
|
+from rasa_sdk.executor import CollectingDispatcher
|
|
13
|
+from rasa_sdk.events import SlotSet
|
|
14
|
+
|
|
15
|
+class ActionSayData(Action):
|
|
16
|
+ def name(self) -> Text:
|
|
17
|
+ return "get_slot_data"
|
|
18
|
+ def run(self, dispatcher: CollectingDispatcher,
|
|
19
|
+ tracker: Tracker,
|
|
20
|
+ domain: Dict[Text, Any]) -> List [Dict[Text, Any]]:
|
|
21
|
+ first_name = tracker.get_slot("first_name")
|
|
22
|
+ print(first_name)
|
|
23
|
+ last_name = tracker.get_slot("last_name")
|
|
24
|
+ print(last_name)
|
|
25
|
+ phone_num= tracker.get_slot("phone_num")
|
|
26
|
+ print(phone_num)
|
|
27
|
+ email_id= tracker.get_slot("email_id")
|
|
28
|
+ print(email_id)
|
|
29
|
+ sender_id = tracker.sender_id
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+ def save_user_details_to_excel(details):
|
|
33
|
+ try:
|
|
34
|
+ workbook = openpyxl.load_workbook('user_details.xlsx')
|
|
35
|
+ sheet = workbook.active
|
|
36
|
+ except FileNotFoundError:
|
|
37
|
+ workbook = openpyxl.Workbook()
|
|
38
|
+ sheet = workbook.active
|
|
39
|
+ sheet.append(['Name', 'Age', 'Email', 'Phone','recipient_id'])
|
|
40
|
+ sheet.append(details)
|
|
41
|
+ workbook.save('user_details.xlsx')
|
|
42
|
+
|
|
43
|
+ details = [first_name, last_name, phone_num, email_id,sender_id]
|
|
44
|
+ save_user_details_to_excel(details)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+ dispatcher.utter_message()
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+ return []
|
|
51
|
+
|
|
52
|
+ # Clear the desired slot by setting its value to None
|
|
53
|
+class ActionHelloWorld(Action):
|
|
54
|
+
|
|
55
|
+ def name(self) -> Text:
|
|
56
|
+ return "slots_to_clear"
|
|
57
|
+
|
|
58
|
+ def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
|
|
59
|
+ slots_to_clear = ["first_name", "last_name", "phone_num","email_id"]
|
|
60
|
+ events = [SlotSet(slot_name, None) for slot_name in slots_to_clear]
|
|
61
|
+ return events
|