- Newest
- Most votes
- Most comments
you can use a lambda function as a custom slot this function can modify the user input according to your requirements
for example you can complete the following
exports.handler = (event, context, callback) => {
var userMoney = event.currentIntent.slots.Currency; // get the user's response
userMoney = userMoney.replace('$', ''); // remove dollar sign
userMoney = userMoney.replace('k', '000'); // replace 'k' with '000'
userMoney = parseFloat(userMoney); // convert the result to a number
if (isNaN(userMoney)) {
Im not a developer but how about using a regex expression to only return numbers and ignore anything else
/\d+.\d+
Or use AMAZON.AlphaNumeric using a regular expression which allows you to define a validation
I tried it using a custom slot, and Slot value resolution > Restrict to slot values > adding that regex and it does not work. Amazon Lex throws an error "The slot value '/\d+' in slot type 'budget' isn't valid. The slot value cant contain "*" and """
I tried doing again with your updated regex, unfortunately, the slot doesn't allow it.
Could try without the first forward slash, so \d+.\d+ but I also like sdtslmn answer
Relevant content
- asked 3 months ago
- asked 9 months ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 4 months ago
Good shout
this is most likely what I will do which is validate the number being inserted into the slot. Like the first comment I thought there would be a way to do regex in the slot options in the lex dashboard rather than a codehook.
Can we use Amazon v1 slots, inside of v1 they had a slot value named AMAZON.US_DOLLAR but now is no longer there, is there a way to use that?
as i know AMAZON.US_DOLLAR from Amazon Lex v1 is not directly available in Amazon Lex v2 that us why i tried to give a workaround
https://docs.aws.amazon.com/lexv2/latest/dg/grammar-industry.html
I ended up manually validating the currency using regex in lambda, and re-inserting the value without symbols, and if the value had a lowercase and uppercase k, I multiplied it by 1000. So I will mark this your @sedat_salman as the correct answer! :)