from rasa_core.actions.action import Action from rasa_core.events import SlotSet import csv class ActionSearchBirthplace(Action): def name(self): return 'action_search_birthplace' def run(self, dispatcher, tracker, domain): dispatcher.utter_message("Searching for Birthplace") person = tracker.get_slot('physicist') actualBirthplace = None with open('birthplace.csv', newLine='') as csvfile: spamreader = csv.reader(csvfile, delimiter=',') for row in spamreader: if row['Name'] == person: actualBirthplace = row['Birthplace'] if actualBirthplace is None: dispatcher.utter_message("DIE SCHEIßE FUNKTIONIERT NICHT!") #dispatcher.utter_message(actualBirthplace) 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): dispatcher.utter_message("Here is the Birthplace I found:") dispatcher.utter_message(tracker.get_slot("matches")) return []