This repository has been archived by the owner on Oct 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
actions.py
96 lines (75 loc) · 2.44 KB
/
actions.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# 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/core/actions/#custom-actions/
from typing import Any, Dict, List, Text
from rasa_sdk import Tracker, Action
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.events import UserUtteranceReverted
from rasa_sdk.forms import FormAction
class CovidForm(FormAction):
'''Collects information then queries from api'''
def name(self):
return 'covid_form'
@staticmethod
def required_slots(tracker):
return [
'country',
]
def slot_mappings(self) -> Dict[Text, Any]:
return {
'country': self.from_entity(
entity='country',
intent=[
'inform',
'ask_covid',
],
),
'case_type': self.from_entity(
entity='case_type',
intent=[
'inform',
'ask_covid',
],
),
'stat_type': self.from_entity(
entity='stat_type',
intent=[
'inform',
'ask_covid',
]
)
}
def submit(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> List[Dict]:
country = tracker.get_slot('country')
dispatcher.utter_message(
f'Looks like you\'re trying to ask about covid-19 in {country}'
)
return []
class ActionGreet(Action):
'''Revertible mapped action for utter_greet'''
def name(self):
return 'action_greet'
def run(self, dispatcher, tracker, domain):
dispatcher.utter_message(template='utter_greet')
return [UserUtteranceReverted()]
class ActionBye(Action):
'''Revertible mapped action for utter_bye'''
def name(self):
return 'action_bye'
def run(self, dispatcher, tracker, domain):
dispatcher.utter_message(template='utter_bye')
return [UserUtteranceReverted()]
class ActionThank(Action):
'''Revertible mapped action for utter_noworries'''
def name(self):
return 'action_thank'
def run(self, dispatcher, tracker, domain):
dispatcher.utter_message(template='utter_noworries')
return [UserUtteranceReverted()]