-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactions.py
More file actions
39 lines (26 loc) · 1.03 KB
/
actions.py
File metadata and controls
39 lines (26 loc) · 1.03 KB
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
# 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/
# This is a simple example for a custom action which utters "Hello World!"
from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
timezones = {
"London": "UTC+1:00"
}
class ActionFindAndShowTimeZone(Action):
def name(self) -> Text:
return "action_find_and_show_time_zone"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
city = tracker.get_slot("city")
timezone = timezones.get(city)
if timezone is None:
output = "Could not find the time zone for {}".format(city)
else:
output = "The time zone for {} is {}".format(city, timezone)
dispatcher.utter_message(text=output)
return []