in src/lambda/meaningful-conversations-lex-lambda.py [0:0]
def get_details(intent_request):
bill = ""
billsum = []
result = ""
y = True
session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
inr = intent_request['currentIntent']['slots']['invoicenr']
r = 0
i = 0
for file in input_bucket.objects.all():
i += 1
selected_phrases = ""
input_bucket_text_file = s3.Object(bucket, file.key)
text_file_contents = str(input_bucket_text_file.get()['Body'].read().decode('utf-8'))
#Comprehend Entity Detection
detected_entities = comprehend.detect_entities(
Text=text_file_contents,
LanguageCode="en"
)
print(detected_entities)
selected_entity_types = ["DATE", "QUANTITY"]
for x in detected_entities['Entities']:
if x['Type'] in "OTHER":
detnr = x['Text']
if detnr == inr:
htmlstring = "Invoice Details for " + detnr + ": "
for x in detected_entities['Entities']:
if x['Type'] in selected_entity_types and x['EndOffset'] > 40 and x['EndOffset'] <= 337:
r += 1
if r == 1:
htmlstring += "On " + x['Text'] + " "
elif r == 2:
htmlstring += "for the item " + x['Text'] + " "
else:
htmlstring += " there is a charge of " + str(x['Text'].split()[0]) + ". "
r = 0
print("HTMLString is: " + htmlstring)
result = htmlstring + " You can request me for invoice notes or simply close this chat."
else:
result = 'Sorry I could not find a match for that Invoice Number. Please request for invoice details with a valid Invoice Number.'
return close(
session_attributes,
'Fulfilled',
{
'contentType': 'PlainText',
'content': result
}
)