pvanand commited on
Commit
26763bc
·
1 Parent(s): 3d62acb

Update actions/actions.py

Browse files
Files changed (1) hide show
  1. actions/actions.py +56 -19
actions/actions.py CHANGED
@@ -4,24 +4,61 @@
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
 
10
- # from typing import Any, Text, Dict, List
11
- #
12
- # from rasa_sdk import Action, Tracker
13
- # from rasa_sdk.executor import CollectingDispatcher
14
- #
15
- #
16
- # class ActionHelloWorld(Action):
17
- #
18
- # def name(self) -> Text:
19
- # return "action_hello_world"
20
- #
21
- # def run(self, dispatcher: CollectingDispatcher,
22
- # tracker: Tracker,
23
- # domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
24
- #
25
- # dispatcher.utter_message(text="Hello World!")
26
- #
27
- # return []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  # See this guide on how to implement these action:
5
  # https://rasa.com/docs/rasa/custom-actions
6
 
7
+ from typing import Any, Text, Dict, List
8
+ from rasa_sdk import Action, Tracker
9
+ from rasa_sdk.events import SlotSet, FollowupAction
10
+ from rasa_sdk.executor import CollectingDispatcher
11
+ import random
12
 
13
+ class GeneralHelp(Action):
14
+ def name(self) -> Text:
15
+ return "action_general_help"
16
 
17
+ def run(self, dispatcher: CollectingDispatcher,
18
+ tracker: Tracker,
19
+ domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
20
+
21
+ user_role = tracker.slots.get("user_role", None)
22
+
23
+ if user_role is None:
24
+ dispatcher.utter_message(text="Sure! Are you a developer or a client representing an organization?")
25
+ else:
26
+ return [FollowupAction("action_help_with_role")]
27
+
28
+ # Modified from @Rohit Garg's code https://github.com/rohitkg83/Omdena/blob/master/actions/actions.py
29
+ class ActionHelpWithRole(Action):
30
+
31
+ def name(self) -> Text:
32
+ return "action_help_with_role"
33
+
34
+ def run(self,
35
+ dispatcher: CollectingDispatcher,
36
+ tracker: Tracker,
37
+ domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
38
+
39
+ # Get the value of the first_occurrence_user_type slot
40
+ current_user_type = tracker.slots.get("user_role", None)
41
+
42
+ if current_user_type == 'developer':
43
+ msg = "Thanks a lot for providing the details. You can join one of our local chapter and collaborate on " \
44
+ "various projects and challenges to Develop Your Skills, Get Recognized, and Make an Impact. Please " \
45
+ "visit https://omdena.com/community for more details. Do you have any other questions? "
46
+
47
+ elif current_user_type == 'client':
48
+ msg = "Thanks a lot for providing the details. With us you can Innovate, Deploy and Scale " \
49
+ "AI Solutions in Record Time. For more details please visit https://omdena.com/offerings. Do you have any other questions? "
50
+ else:
51
+ msg = "Please enter either developer or client"
52
+
53
+ dispatcher.utter_message(text=msg)
54
+
55
+ class ResetSlotsAction(Action):
56
+ def name(self) -> Text:
57
+ return "action_reset_slots"
58
+
59
+ def run(self, dispatcher: CollectingDispatcher,
60
+ tracker: Tracker,
61
+ domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
62
+ slots_to_reset = ["user_role"] # Add the names of the slots you want to reset
63
+ events = [SlotSet(slot, None) for slot in slots_to_reset]
64
+ return events