Exemplo n.º 1
0
    def run(self, dispatcher: CollectingDispatcher, tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        print("====Inside ActionSearchRestaurants Without Cuisine====")
        print()
        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")

        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)

        ##set the cuisine to any of the cuisine name or you leave it empyt
        cuisine_id = ""
        restaurants = zomatoApi.searchRestaurants(entity_id, entity_type,
                                                  cuisine_id, "")
        dispatcher.utter_message(
            "Here are the few restaurants I have found 😋!!!")
        dispatcher.utter_custom_json({
            "payload": "cardsCarousel",
            "data": restaurants
        })
Exemplo n.º 2
0
    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        print("====Inside ActionSearchRestaurants Without Cuisine====")
        print()
        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")

        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)
        
        ##set the cuisine to any of the cuisine name or you leave it empyt
        cuisine_id=""
        restaurants=zomatoApi.searchRestaurants(entity_id,entity_type, cuisine_id,"")
        
        ## check if restaurants found
        if(len(restaurants)>0):

            if(tracker.get_latest_input_channel()=="slack"):
                more_restaurants=[]
                if(len(restaurants)>5):
                    restData=getResto_Slack(restaurants[:5],show_more_results=True)
                    more_restaurants=restaurants[5:]
                else:
                    restData=getResto_Slack(restaurants,show_more_results=False)

                dispatcher.utter_message(text="Here are the few restaurants that matches your preferences 😋",json_message=restData)
                return [SlotSet("more_restaurants", more_restaurants)]    
            else:
                if(len(restaurants)>5):   
                    dispatcher.utter_message(text="Here are the few restaurants that matches your preferences 😋",json_message={"payload":"cardsCarousel","data":restaurants[:5]})
                    return [SlotSet("more_restaurants", restaurants[5:])]
                else:
                    dispatcher.utter_message(text="Here are the few restaurants that matches your preferences 😋",json_message={"payload":"cardsCarousel","data":restaurants})
                    return [SlotSet("more_restaurants", None)]    
        
        else:    
            dispatcher.utter_message("Sorry we couldn't find any restaurants that serves {} cuisine in {} 😞".format(cuisine,location))
            return [UserUtteranceReverted()] 
Exemplo n.º 3
0
    def run(self, dispatcher: CollectingDispatcher, tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        print()
        print("====Inside ActionSearchRestaurants====")
        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 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 restaurants by location name
        if (locationEntity):
            locationEntities = zomatoApi.getLocationDetailsbyName(
                locationEntity)
            if (locationEntities["restaurants_available"] == "no"):
                dispatcher.utter_message(
                    "Sorry I couldn't find any restaurants  😓")
                return []
            entity_id = locationEntities["entity_id"]
            entity_type = locationEntities["entity_type"]
            city_id = locationEntities["city_id"]
            SlotSet("location", locationEntities["title"])

        ##get the cuisine id for the cuisine name user provided
        cuisine_id = zomatoApi.getCuisineId(cuisine, city_id)

        print("Entities:  ", entity_id, " ", entity_type, " ", cuisine_id, " ",
              location, " ", cuisine)
        print()

        ## if we didn't find the restaurant for which user has provided the cuisine name
        if (cuisine_id == None):
            dispatcher.utter_message(
                "Sorry we couldn't find any restaurants that serves {} cuisine in {}"
                .format(cuisine, location))
            return [UserUtteranceReverted()]
        else:
            ## search the restaurts by calling zomatoApi api
            restaurants = zomatoApi.searchRestaurants(entity_id, entity_type,
                                                      cuisine_id, "")

            ## check if restaurants found
            if (len(restaurants) > 0):
                dispatcher.utter_message(
                    "Here are the few restaurants that matches your preferences 😋"
                )
                dispatcher.utter_custom_json({
                    "payload": "cardsCarousel",
                    "data": restaurants
                })
                return []

            dispatcher.utter_message(
                "Sorry we couldn't find any restaurants that serves {} cuisine in {} 😞"
                .format(cuisine, location))
            return [UserUtteranceReverted()]