def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: try: entities = tracker.latest_message['entities'] intent = tracker.latest_message['intent']['name'] table = get_table(intent) primary_key = final_pk[table][0] if(len(entities) == 0): if(tracker.get_slot('Account_ID') is not None): dispatcher.utter_message(template = 'utter_Paid_Amount') else: dispatcher.utter_message(text = "Please enter a valid transaction ID !") return [] if(containsEntity(primary_key, entities)): val = '*' else: val = intent allrecords, features = getData(query_formation(entities, "*", final_table[table],table), table) records, features = getData(query_formation(entities, val, final_table[table],table), table) if val == "*": allrecords = records saveRecords(table, allrecords) if len(records) == 0: raise ValueError("No record for this query !!!") elif len(records) == 1: features = {tup[0]:val for tup,val in zip(features,allrecords[0])} print(allrecords, features) dispatcher.utter_message(text="The paid amount is "+ str(features[intent.lower()]) + " for the given record with id "+ str(features[primary_key.lower()]) ) return [SlotSet("{}".format(slot), features[slot.lower()]) for slot in final_table[table]] else: records = [rec[0] for rec in records] records = list(set(records)) dispatcher.utter_message(text="The amounts are {}.".format(', '.join(records))) return [] except: dispatcher.utter_message(text = str(sys.exc_info()[1])) return []
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: try: entities = tracker.latest_message['entities'] intent = tracker.latest_message['intent']['name'] table = get_table(intent) primary_key = final_pk[table][0] if(len(entities) == 0): dispatcher.utter_message(template = 'utter_ipo_year') return [] if(containsEntity(primary_key, entities)): val = '*' else: val = intent allrecords, features = getData(query_formation_dynamic(entities, "*", final_table[table],table), table) records, features = getData(query_formation_dynamic(entities, val, final_table[table], table), table) if val == "*": allrecords = records saveRecords(table, allrecords) if len(records) == 0: raise ValueError("No record for this query !!!") elif len(records) == 1: features = {tup[0]:val for tup,val in zip(features,records[0])} print(records, features) features['Source'] = features.pop('source') dispatcher.utter_message(text="The ipo year is "+ str(features[intent.lower()]) + " for the given record with id "+ str(features[primary_key.lower()]) ) return [SlotSet("{}".format(slot), features[slot]) for slot in features.keys()] else: print(records) return [] except: dispatcher.utter_message(text = str(sys.exc_info()[1])) return []