Reputation: 47
Having some challenges with collecting monetary amounts in Autopilot. I have a task called GIVE where people are texting "Give" and then autopilot replies with "How much?" using a collect action with type = Twilio.NUMBER. The following is happening:
Person: Give
Autopilot: How much?
Person: .99
Value ends up being 99 (wrong)
Person: Give
Autopilot: How much?
Person: 1.99
Value ends up being 1.99 (correct)
Person: Give
Autopilot: How much?
Person: $1.99
Value ends up being 199 (wrong)
So it seems if the decimal is first it gets dropped, and if a dollar sign is first it and the decimal gets dropped. It only works properly if it starts with a number. I sorta get the logic in that, but it makes it really hard to collect monetary amounts.
Here is the relevant code in the task:
"collect": {
"name": "gift_amount",
"questions": [
{
"question": "How much would you like to give?",
"name": "gift_amount",
"type": "Twilio.Number"
}
],
"on_complete": {
"redirect": {
"method": "POST",
"uri": "https://blah.blah"
}
}
Any thoughts? Ideally there would be a field type of Twilio.CURRENCY or something like that.
Upvotes: 1
Views: 91
Reputation: 3300
Twilio developer evangelist here.
Currently the Twilio.CURRENCY field type is for the money type ie. USD.
You could collect it as the alphanumeric field type and then break it down like with a validator function to avoid having the user give letters or non-numbers, but also break down the input based on tokens like the decimal or even whitespace.
"$1.99" won't work because the number normalizer doesn't recognize the dollar sign, causing the normalization to fail. Then if it fails, Autopilot justs filter digits out, generating "199". Generally speaking, Twilio.NUMBER works best when there are only numbers. $ 1.99 should work though, but not $1.99.
Let me know if this helps at all!
Upvotes: 2