So my Alexa skill asks for an invoice amount.
The user is supposed to say "My invoice is for one hundred dollars."
My sample utterance is "my invoice is for {invoiceAmount} dollars" where {invoiceAmount} is an Amazon.NUMBER slot
If the user says a number everything works fine. However, if they don't then the code blows up and Alexa exits my skill. For example, if a user says "My invoice is for baseball dollars."
Here is my code that handles this intent:
def set_amount_in_session(intent, session):
card_title = "Set Invoice Amount"
should_end_session = False
if 'invoiceAmount' in intent['slots']:
if intent['slots']['invoiceAmount']['value'] is not None:
invoice_amount = intent['slots']['invoiceAmount']['value']
try:
val = int(invoice_amount)
except ValueError:
val = 0
if val != 0:
session['attributes']['invoiceAmount'] = int(invoice_amount)
speech_output = "The invoice amount is " + str(invoice_amount) + " dollars. "
card_output = "Invoice Amount $" + str(invoice_amount)
reprompt_text = "Please tell me the terms of the invoice."
else:
speech_output = "I'm not sure what the invoice amount is. " \
"Please try again."
card_output = "I'm not sure what the invoice amount is. " \
"Please try again."
reprompt_text = "I'm not sure what the invoice amount is. " \
"Please tell me the amount of the invoice you wish to factor by saying, for example, " \
"my invoice is for one hundred and fifty dollars."
else:
speech_output = "I'm not sure what the invoice amount is. " \
"Please try again."
card_output = "I'm not sure what the invoice amount is. " \
"Please try again."
reprompt_text = "I'm not sure what the invoice amount is. " \
"Please tell me the amount of the invoice you wish to factor by saying, for example, " \
"my invoice is for one hundred and fifty dollars."
else:
speech_output = "I'm not sure what the invoice amount is. " \
"Please try again."
card_output = "I'm not sure what the invoice amount is. " \
"Please try again."
reprompt_text = "I'm not sure what the invoice amount is. " \
"Please tell me the amount of the invoice you wish to factor by saying, for example, " \
"my invoice is for one hundred and fifty dollars."
return build_response(session['attributes'], build_speechlet_response(
card_title, speech_output, card_output, reprompt_text, should_end_session))
This code works perfectly fine when I test it in the Amazon Developer Console, but it fails on my Echo Dot.
If I say "My invoice is for one hundred baseball dollars" it is able to handle the response and say it isn't sure what the invoice amount is.
If I say "My invoice is for baseball one hundred dollars" it actually ignores the "baseball" and sets the invoice amount to $100, which I'm fine with.
However, if I say "My invoice is for baseball dollars" it fails and says "There was a problem with the requested skills response" and it closes the skill.