-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathreplicate_action.txt
49 lines (45 loc) · 1.66 KB
/
replicate_action.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class <action_name>(Action):
def name(self):
return '<action_name>'
@staticmethod
def required_fields():
return [
]
def run(self, dispatcher, tracker, domain):
index = "<index_name>"
template = dispatcher.retrieve_template("utter_"+"<action_name>")
# Checking required parameters
intent = contain.index[index]
for entity in intent.entities:
if entity.required == True:
slot = entity.name
if slot!= None:
slot_val = tracker.get_slot(slot)
if slot_val is None:
logger.info("Uttering the required parameter")
dispatcher.utter_template(command_sanitizer("utter_{}_follow_up_{}".format(self.name(),slot)))
events = []
events.append(SlotSet("requested_slot", slot))
return events
text = template["text"]
modified_text = ""
i=0
while i < (len(text)):
if text[i]=='{':
j = i+1
slot = ""
while(text[j]!='}' and j<len(text)):
slot += text[j]
j += 1
modified_text += tracker.get_slot(slot)
i = j
else:
modified_text += text[i]
i += 1
dispatcher.utter_message(modified_text)
events = []
contexts = out_context_set(self.name)
for c in contexts:
events.append(SlotSet(c,1))
events.append(SlotSet("requested_slot", None))
return events