def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: trans_id = tracker.get_slot('trans_id') date = tracker.get_slot('date') state = tracker.get_slot('state') dispatcher.utter_message(trans_id) dispatcher.utter_message(state) dispatcher.utter_message(date) connection = mysql.connector.connect(host='localhost', database='chatbot', user='******', password='******') cursor = connection.cursor() sql_select_query = """select * from trade_ebills where Transaction_Date = %s and Transaction_state = %s and Transaction_ID = %s""" cursor.execute(sql_select_query, ( date, state, trans_id, )) records = cursor.fetchall() wb = xlwt.Workbook() ws = wb.add_sheet('Application Report') style = xlwt.easyxf( 'font: name Times New Roman, color-index red, bold on') for r, row in enumerate(records): if row: for c, col in enumerate(records[0]): ws.write(r, c, row[c], style) wb.save('app_report.xls') dispatcher.utter_attachment('app_report.xls') return []
def run( self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any], ) -> List[Dict]: desPlace = tracker.get_slot('loc_travel') if desPlace in self.location_travel().keys(): placeID = self.location_travel()[desPlace] else: # do something when not have desPlace in db placeID = None pass print(placeID) import yaml import requests import json #retrieve google api key with open("./ga_credentials.yml", 'r') as ymlfile: cfg = yaml.safe_load(ymlfile) key = cfg['credentials']['GOOGLE_KEY'] # get user's current location get_origin = requests.post( "https://www.googleapis.com/geolocation/v1/geolocate?key={}". format(key)).json() origin_lat = get_origin['location']['lat'] origin_lng = get_origin['location']['lng'] attachment = "https://www.google.com/maps/embed/v1/directions?origin={},{}&destination=place_id:{}&key={}".format( origin_lat, origin_lng, placeID, key) dispatcher.utter_attachment(attachment=attachment) return []
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: object_name = tracker.get_slot('object_name') object_color = tracker.get_slot('object_color') placement = tracker.get_slot('placement') if placement in valid_placements: placement_origin = placement else: placement_origin = "middle" # # dispatcher.utter_message(text="Hang on, I'll try to search in the {} area of the table for the object you want me to learn".format( # placement_origin # )) if ENABLE_ROS: nlp_node.send_command(action="show", object=object_name, obj_color=object_color, placement_origin=placement_origin, placement_destination=None) response = nlp_node.wait_for_response() try: msg, path_2dimg, path_3dimg = response except Exception: msg, path_2dimg = response if msg is not None: imgpath = path_2dimg print("Image saved at {}".format(imgpath)) print("Found object: {}".format(msg.desired_color, msg.found_obj)) imgurl = "http://localhost:8888/{}?time={}".format( imgpath, int(time.time())) dispatcher.utter_attachment(None, image=imgurl) if msg.found_obj: # dispatcher.utter_message(text="I found the {} {} in the {} area of the platform.".format( # msg.desired_color, # object_name, # placement_origin)) dispatcher.utter_message(template="utter_got_description") update_known_objects([object_name]) update_known_colors([object_color]) else: dispatcher.utter_message( text= "Sorry, I didn't find any object. Make sure the {} {} you want to show me is in the {} area of the platform." .format(msg.desired_color, object_name, placement_origin)) else: dispatcher.utter_message(template="utter_command_failed") # dispatcher.utter_message(text="Error: {}".format(info)) return [AllSlotsReset()] else: dispatcher.utter_message(template="utter_got_description") return [AllSlotsReset()]