def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: print() print("====Inside ActionAskCuisine====") print() location = tracker.get_slot("location") cuisine = tracker.get_slot("cuisine") lat = tracker.get_slot("latitude") lon = tracker.get_slot("longitude") locationEntity = next(tracker.get_latest_entity_values("location"), None) cuisineEntity = next(tracker.get_latest_entity_values("cuisine"), None) user_locationEntity = next( tracker.get_latest_entity_values("user_location"), None) latEntity = next(tracker.get_latest_entity_values("latitude"), None) lonEntity = next(tracker.get_latest_entity_values("longitude"), None) location = tracker.get_slot("location") cuisine = tracker.get_slot("cuisine") lat = tracker.get_slot("latitude") lon = tracker.get_slot("longitude") entity_id = tracker.get_slot("location_id") entity_type = tracker.get_slot("location_type") city_id = tracker.get_slot("city_id") if (latEntity and lonEntity): lat = latEntity lon = lonEntity if (user_locationEntity or (latEntity and lonEntity)): if (lat == None and lon == None): dispatcher.utter_message( "Sure, please allow me to access your location 🧐") dispatcher.utter_custom_json({"payload": "location"}) return [] else: locationEntities = zomatoApi.getLocationDetailsbyCoordinates( lat, lon) location = locationEntities["title"] city_id = locationEntities["city_id"] entity_id = locationEntities["entity_id"] entity_type = locationEntities["entity_type"] SlotSet("location", locationEntities["title"]) SlotSet("city_id", locationEntities["city_id"]) SlotSet("location_id", locationEntities["entity_id"]) SlotSet("location_type", locationEntities["entity_type"]) if (locationEntity): locationEntities = zomatoApi.getLocationDetailsbyName( locationEntity) entity_id = locationEntities["entity_id"] entity_type = locationEntities["entity_type"] city_id = locationEntities["city_id"] SlotSet("location", locationEntities["title"]) print("locationDetails: ", locationEntities) print() ## check if the restaurants are available in the user provided location if (locationEntities["restaurants_available"] == "no"): dispatcher.utter_message( "Sorry, No restaurants available in the location you have provided 🤯" ) return [UserUtteranceReverted()] else: locationDetails = zomatoApi.getLocationDetails( locationEntities["entity_id"], locationEntities["entity_type"]) dispatcher.utter_template("utter_ask_cuisine", tracker) dispatcher.utter_custom_json({ "payload": "quickReplies", "data": locationDetails["top_cuisines"] }) return [ SlotSet("city_id", locationEntities["city_id"]), SlotSet("location_id", locationEntities["entity_id"]), SlotSet("location_type", locationEntities["entity_type"]) ]
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: print() print("======Inside Action Search Best Restaurants====") print() ## extract the required slots location = tracker.get_slot("location") cuisine = tracker.get_slot("cuisine") lat = tracker.get_slot("latitude") lon = tracker.get_slot("longitude") entity_id = tracker.get_slot("location_id") entity_type = tracker.get_slot("location_type") city_id = tracker.get_slot("city_id") ## extract the entities locationEntity = next(tracker.get_latest_entity_values("location"), None) cuisineEntity = next(tracker.get_latest_entity_values("cuisine"), None) user_locationEntity = next( tracker.get_latest_entity_values("user_location"), None) latEntity = next(tracker.get_latest_entity_values("latitude"), None) lonEntity = next(tracker.get_latest_entity_values("longitude"), None) ## if we latitude & longitude entities are found, set it to slot if (latEntity and lonEntity): lat = latEntity lon = lonEntity ## if user wants to search the best restaurants in his current location if (user_locationEntity or (latEntity and lonEntity)): ##check if we already have the user location coordinates stoed in slots if (lat == None and lon == None): dispatcher.utter_message( "Sure, please allow me to access your location 🧐") dispatcher.utter_custom_json({"payload": "location"}) return [] else: locationEntities = zomatoApi.getLocationDetailsbyCoordinates( lat, lon) location = locationEntities["title"] city_id = locationEntities["city_id"] entity_id = locationEntities["entity_id"] entity_type = locationEntities["entity_type"] ## store the user provided details to slot SlotSet("location", locationEntities["title"]) SlotSet("city_id", locationEntities["city_id"]) SlotSet("location_id", locationEntities["entity_id"]) SlotSet("location_type", locationEntities["entity_type"]) ## if user wants to search best restaurants by location name if (locationEntity): locationEntities = zomatoApi.getLocationDetailsbyName( locationEntity) entity_id = locationEntities["entity_id"] entity_type = locationEntities["entity_type"] city_id = locationEntities["city_id"] print("Entities: ", entity_id, " ", entity_type, " ", city_id, " ", locationEntity) ## search the best restaurts by calling zomatoApi api restaurants = zomatoApi.getLocationDetails(entity_id, entity_type) ## check if restaurants details found if (len(restaurants) > 0): dispatcher.utter_message( "Here are few top rated restaurants that I have found 🤩") dispatcher.utter_custom_json({ "payload": "cardsCarousel", "data": restaurants["best_restaurants"] }) return [] dispatcher.utter_message( "Sorry we couldn't find any best restaurants ☹️".format( cuisine, location)) return [UserUtteranceReverted()]