def run(self, dispatcher, tracker, domain): dispatcher.utter_message(template="utter_greet") return [UserUtteranceReverted()]
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()]
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"])]
async def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: dispatcher.utter_message(template="utter_please_rephrase") return [UserUtteranceReverted()]
async def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict) -> List[EventType]: """Executes the custom action""" account_type = tracker.get_slot("account_type") if account_type == "credit": # show credit card balance credit_card = tracker.get_slot("credit_card") available_cards = profile_db.list_credit_cards(tracker.sender_id) if credit_card and credit_card.lower() in available_cards: current_balance = profile_db.get_credit_card_balance( tracker.sender_id, credit_card) dispatcher.utter_message( response="utter_credit_card_balance", **{ "credit_card": credit_card.title(), "credit_card_balance": f"{current_balance:.2f}", }, ) else: for credit_card in profile_db.list_credit_cards( tracker.sender_id): current_balance = profile_db.get_credit_card_balance( tracker.sender_id, credit_card) dispatcher.utter_message( response="utter_credit_card_balance", **{ "credit_card": credit_card.title(), "credit_card_balance": f"{current_balance:.2f}", }, ) else: # show bank account balance account_balance = profile_db.get_account_balance(tracker.sender_id) amount = tracker.get_slot("amount_transferred") if amount: amount = float(tracker.get_slot("amount_transferred")) init_account_balance = account_balance + amount dispatcher.utter_message( response="utter_changed_account_balance", init_account_balance=f"{init_account_balance:.2f}", account_balance=f"{account_balance:.2f}", ) else: dispatcher.utter_message( response="utter_account_balance", init_account_balance=f"{account_balance:.2f}", ) events = [] active_form_name = tracker.active_form.get("name") if active_form_name: # keep the tracker clean for the predictions with form switch stories events.append(UserUtteranceReverted()) # trigger utter_ask_{form}_AA_CONTINUE_FORM, by making it the requested_slot events.append(SlotSet("AA_CONTINUE_FORM", None)) # avoid that bot goes in listen mode after UserUtteranceReverted events.append(FollowupAction(active_form_name)) return events
def run(self, dispatcher, tracker, domain): # what your action should do food = tracker.get_slot('food') house= tracker.get_slot('house') add = tracker.get_slot('address') mobile = tracker.get_slot('mobile') mydb = mysql.connector.connect( host="172.18.0.1", user="******", port='32000', password="******", database="rasa_db" ) cur = mydb.cursor() if house == None or add == None or mobile == None: message5 = 'Please enter the complete address and the mobile number' dispatcher.utter_message(message5) return [UserUtteranceReverted()] else: u = house.split() l = len(u) # x= list(house) k = '#' in house if k == True: if u[0] == '#': n = '#' + u[1] print(n) else: n = u[0] print(n) elif l == 1: n = '#' + house print(n) else: n = '#' + u[l - 1] print(n) origins = "sec-23,chandigarh" print(house) print(add) print(mobile) #con = sqlite3.connect('chatbot.db') cur.execute('SELECT * FROM restuarant') rows = cur.fetchall() for i in range(8): # print(rows[i][1]) a = rows[i][1] seq = difflib.SequenceMatcher(None, a, food) d = seq.ratio() * 100 if d >= 60.0: item = rows[i][1] price = rows[i][2] # print(d) key = 'AIzaSyC1PaCkmpMXcJygTZPByALiE8dCiqNwVo4' units = 'imperial' api = 'https://maps.googleapis.com/maps/api/distancematrix/json?units=' + units + '&origins=' + origins + '&destinations=' + add + '&key=' + key request = json.loads(requests.get(api).text) # req = requests.get(api).text distance = request['rows'][0]['elements'][0]['distance']['text'] Add = request['destination_addresses'] Address = Add[0] # print(req) x = distance.split() y = float(x[0]) if (y <= 3): message1 = "Selected item: {}".format(item) message2 = "Address: {}, {}".format(n, Address) message3= "Mobile no: {}".format(mobile) message4 = "Amount to be paid: Rs {}. To confirm click on 'yes', otherwise click on 'no'.".format(price) button = [{'title': 'Yes', 'payload': '/user_affirm'}, {'title': 'No', 'payload': '/user_deny'}] dispatcher.utter_message(message1) dispatcher.utter_message(message2) dispatcher.utter_message(message3) dispatcher.utter_button_message(message4, buttons=button) return [] else: dispatcher.utter_message( 'I am very sorry. I can not place order for travelling distance more than 5 Km.') dispatcher.utter_message('Please enter address and mobile number within distance range.') return [UserUtteranceReverted()]
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: dispatcher.utter_message(text="抱歉,您可以再重复一遍吗?") return [UserUtteranceReverted()]
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: print(tracker.latest_message) dispatcher.utter_message( text="Please Contact Huawei Customer Care: URL") return [UserUtteranceReverted()]
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: dispatcher.utter_message(text="Yes, it looks good.") return [UserUtteranceReverted()]
def run(self, dispatcher:CollectingDispatcher, tracker:Tracker, domain:Dict[Text, Any]) -> List: dispatcher.utter_template('utter_chat', tracker) return [UserUtteranceReverted()]
def run(self, dispatcher, tracker, domain): dispatcher.utter_template("utter_default", tracker, silent_fail=True) return [UserUtteranceReverted()]
def run(self, dispatcher, tracker, domain): dispatcher.utter_message(template="utter_tank_explanation") dispatcher.utter_message(template="utter_concentrator_explanation") return [UserUtteranceReverted()]
def run(self, dispatcher, tracker, domain): dispatcher.utter_message(template="utter_oxygen_explanation") return [UserUtteranceReverted()]
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: dispatcher.utter_message(template="utter_skip_to_activity_fb") return [UserUtteranceReverted()]
def run(self, dispatcher, tracker, domain): dispatcher.utter_template("utter_time_restaurant", tracker) repeat(tracker, dispatcher) return [UserUtteranceReverted()]
def run(self, dispatcher, tracker, domain): joke = self.get_joke() dispatcher.utter_message(text=joke) return [UserUtteranceReverted()]
def run(self, dispatcher, tracker, domain): dispatcher.utter_template("utter_fallback_message", tracker) # repeat(tracker, dispatcher) return [UserUtteranceReverted()]
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: # Checking for 2 fallback, if bot didn't understand final message is uttered. bot_msg = "" count = 0 templates_temp = {} for key, message in templates.items(): templates_temp[key] = message for event in reversed(tracker.events): if event.get("event") == "bot": #logger.debug("Inside Fallback : text is : "+event.get("text")) if templates["utter_fallback"] in event.get("text"): count += 1 if count >= 2: dispatcher.utter_message( templates["utter_bot_not_understand"]) return [Restarted()] # Call is Ended EOC else: count += 1 bot_msg = event.get("text") for template_key, template_message in templates_temp.items( ): if event.get("text") == template_message: short_key = template_key + "_short" if short_key in templates_temp: bot_msg = templates_temp[short_key] break else: bot_msg = templates_temp[template_key] break #bot_msg = last_bot_message break elif event.get("text") in templates_temp.values(): # replace bot message here\ bot_msg = event.get("text") #logger.debug(" Bot message in the elif block of fallback is : "+str(bot_msg)) for template_key, template_message in templates_temp.items( ): #logger.debug("Template message in the elif block of fallback is : "+str(template_message)) if event.get("text") == template_message: short_key = template_key + "_short" if short_key in templates_temp: bot_msg = templates_temp[short_key] break else: bot_msg = templates_temp[template_key] break break else: bot_msg = event.get("text") #logger.debug("Bot message in the else block of fallback is : "+str(bot_msg)) for template_key, template_message in templates_temp.items( ): #logger.debug("Template message in the else block of fallback is : "+str(template_message)) if event.get("text") == template_message: short_key = template_key + "_short" if short_key in templates_temp: bot_msg = templates_temp[short_key] break else: bot_msg = templates_temp[template_key] break #bot_msg = last_bot_message count += 1 break if bot_msg == "": dispatcher.utter_message(templates["initial_message"]) else: if templates["utter_fallback"] in bot_msg: dispatcher.utter_message(bot_msg) else: dispatcher.utter_message(templates["utter_fallback"] + '. ' + bot_msg) return [UserUtteranceReverted()]
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: dispatcher.utter_message(template="utter_residence") return [UserUtteranceReverted(), FollowupAction(tracker.active_form.get('name'))]
def run(self, dispatcher, tracker, domain): dispatcher.utter_message( "I did not understand the previous response, please be more specific.") return [UserUtteranceReverted()]
def run(self, dispatcher, tracker, domain): dispatcher.utter_message('我不理解您的意思呢') return [UserUtteranceReverted()]
def run(self, dispatcher, tracker, domain) -> List[EventType]: logger.debug(tracker.current_slot_values()) dispatcher.utter_message(template="utter_advisor_callback") return [UserUtteranceReverted()]
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: dispatcher.utter_message(template="utter_ask_affirmation") return [UserUtteranceReverted()]
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: message = {"payload": "GIF"} dispatcher.utter_message(image="https://media.tenor.com/images/6691ce39e02f80cb5d2c62416a0d36a2/tenor.gif") return [UserUtteranceReverted()]
def run(self, dispatcher, tracker, domain): dispatcher.utter_template("utter_greet", tracker) return [UserUtteranceReverted()]
def run(self, dispatcher, tracker, domain): dispatcher.utter_template("utter_cancellation_policy", tracker) repeat(tracker, dispatcher) return [UserUtteranceReverted()]
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: dispatcher.utter_template("utter_greet_user", tracker) return [UserUtteranceReverted()]
def run(self, dispatcher, tracker, domain): dispatcher.utter_template("utter_check_breakfast", tracker) repeat(tracker, dispatcher) return [UserUtteranceReverted()]
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()]
def run(self, dispatcher, tracker, domain): print('action_greet......') dispatcher.utter_template("utter_goodbye", tracker) return [UserUtteranceReverted()]