from rasa_core_sdk import Action from rasa_core_sdk.events import SlotSet class ActionSearchBirthplace(Action): def name(self): return 'action_search_birthplace' def run(self, dispatcher, tracker, domain): import csv #dispatcher.utter_message("Searching for Birthplace") person = tracker.get_slot('physicist') actualBirthplace = None with open('birthplace.csv') as csvfile: spamreader = csv.DictReader(csvfile, delimiter=',') for row in spamreader: if row['Name'] == person: actualBirthplace = row['Birthplace'] if actualBirthplace is None: dispatcher.utter_message("Error: Birthplace of " + person + "not known.") return[SlotSet('matches', [])] return [SlotSet('matches', actualBirthplace if actualBirthplace is not None else [])] class ActionSayBirthplace(Action): def name(self): return 'action_say_birthplace' def run(self, dispatcher, tracker, domain): person = tracker.get_slot('physicist') dispatcher.utter_message("The birthplace of " + person + " is " + tracker.get_slot('matches') + ".") return []