def get_template_data()

in lambda/classify-emails-lambda/lambda_function.py [0:0]


def get_template_data(email, intent):

   if(intent == 'MONEYTRANSFER'):
      
      response = comprehend_client.detect_entities(
       Text=email['body'],
       EndpointArn=ner_endpoint_name
      )
      
      logger.info("Reponse received from NER endpoint is : [{}]".format(response))
      
      transactions = filter(lambda entity: entity['Type'] == 'MTNID', response['Entities'])
      
      best_transactions = sorted(transactions, key=lambda entity: entity['Score'], reverse=True)
      
      if(len(best_transactions) > 0):
         best_transation_id = best_transactions[0]['Text']
         logger.info("Transaction id identitied is : [{}] with score : [{}]".format(best_transation_id, best_transactions[0]['Score']))
         status = mock.get_trasfer_status(best_transation_id)
         temaplte_data = "{ \"Sub\":\"" + email['subject'] + "\", \"MTNID\":\"" + best_transation_id + "\" , \"STATUS\":\"" + status + "\" }"
         logger.info("Temaplte data are : [{}]".format(temaplte_data))
         return temaplte_data
      else:
         logger.info("No valid mtn id found in the request.")
         return None
   else :
      return "{ \"Sub\":\"" + email['subject'] + "\" }"