Rasa stack using utter_response


(Sanka) #1

Below code is custom action file

from future import absolute_import from future import division from future import unicode_literals from rasa_core_sdk import Action from rasa_core_sdk.events import SlotSet from rasa_core.actions import Action from rasa_core.events import SlotSet import typing from typing import Text, List, Dict, Any class ActionCheckColleges(Action): def name(self): # type: () -> Text return “action_check_restaurants”

def run(self, dispatcher, tracker, domain): # type: (Dispatcher, DialogueStateTracker, Domain) -> List[Event] colleges_loc = tracker.get_slot(‘location’) college_dict = { “list_hyd” : “JNTUH”, “list_vzg” : [‘GITAM’,‘RVR’] } response = “Hyderabad” #colleges_loc = tracker.latest_message.text()

if(colleges_loc == ‘Hyderabad’):

# for i in list_hyd:

dispatcher.utter_response(college_dict[“list_hyd”]) #return [SlotSet(“location”, colleges_loc)]

response = " {}".format(list_hyd)

******** I want to return list of values of a key to the user For eg: I want to return “list_vzg” values.But I got error like below: ERROR:rasa_core.processor:Encountered an exception while running action ‘action_check_restaurants’. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code. ERROR:rasa_core.processor:‘str’ object has no attribute ‘get’ Traceback (most recent call last): File “C:\Program Files\Python36\lib\site-packages\rasa_core\processor.py”, line 302, in _run_action events = action.run(dispatcher, tracker, self.domain) File “C:\weatherbot\actions.py”, line 24, in run dispatcher.utter_response(college_dict[“list_hyd”]) File “C:\Program Files\Python36\lib\site-packages\rasa_core\dispatcher.py”, line 54, in utter_response if message.get(“elements”): AttributeError: ‘str’ object has no attribute ‘get’

Please resolve the above issue