A single AWS Lambda function which provides a set of basic math and text tools to help manipulate data in contact flows. Included operations are:
- freeform_math = performs basic evaluation of a mathematical expression. For example: 2+2
- random_number + returns a random number between a provided upper and lower limit
- increment_1 = increments a provided number by 1
- increment_n = increments a provided number by a provided amount
- random_choice = returns a random selection from a provided list of options
- replace_text = replaces defined string within a text string with a provided string
- split_text = splits a defined string at a defined point
- strip_text = strips text from the start/end of a defined string
- lower_text = returns the lowercase version of a string
- upper_text = returns the uppercase version of a string
NOTE: No special IAM roles are required for this function.
When invoked, the function looks at the operation
parameter to determine which operation to exectute. Based on the operation
parameter provided, there are additional required fields.
The freeform_math operation simply evaluates a provided expression and returns the result as a string. For example, providing 2+2 with return a response of "4". This can be useful for things like calculating payments or balances, creating estimated wait times, or calculating other metrics.
The freeform_math operation requires the following parameters:
- function = the operation to exectute, which should be set to
freeform_math
- expression = the mathematical expression to be evaluated
"Parameters": {
"operation": "freeform_math",
"expression": "254.36-54.36"
}
Which will result in the following response from Lambda:
{
"result": "success",
"answer": "200.0"
}
The random_number operation returns a rounded random number from a provided range. This can be useful for created randomized PINs for authentication purposes.
The random_number operation requires the following parameters:
- function = the operation to exectute, which should be set to
random_number
- start = the lower limit of the number range
- end = the upper limit of the number range
"Parameters": {
"operation": "random_number",
"start": "1000",
"end": "9999"
}
Which will result in from Lambda similar to:
{
"answer": "6517",
"result": "success"
}
The increment_1 operation simply increments a provided number by 1 and returns the resulting string. For example, providing 24 will return a response of "25". This can be used to provide a loop counter that can be relayed to a customer or used to evaluate conditions based on current loop iteration.
The increment_1 operation requires the following parameters:
- function = the operation to exectute, which should be set to
increment_1
- base = the number to increment
"Parameters": {
"operation": "increment_1",
"base": "24"
}
Which will result in the following response from Lambda:
{
"answer": "25",
"result": "success"
}
The increment_n operation simply increments a provided base number by the provided increment value and returns the resulting string. For example, providing a base of 24 and an increment of 6 will return a response of "30". This can be used to provide a loop counter that can be relayed to a customer or used to evaluate conditions based on current loop iteration.
The increment_n operation requires the following parameters:
- function = the operation to exectute, which should be set to
increment_n
- base = the number to increment
- increment = the amount to increment the base by
"Parameters": {
"operation": "increment_n",
"base": "24",
"increment": "6"
}
Which will result in the following response from Lambda:
{
"answer": "30",
"result": "success"
}
The random_choice operation returns a random selection from a provided list of options. For example, from the provided list of "hi,hello,yo,howdy,wassup" the function will select and return one option. This allows for randomization in messaging or options.
The random_choice operation requires the following parameters:
- function = the operation to exectute, which should be set to
random_choice
- list = the list of values you want to choose from. This should be a comma seperated list with no spaces.
"Parameters": {
"operation": "random_choice",
"list": "hi,hello,yo,howdy,wassup"
}
Which will result in from Lambda similar to:
{
"result": "success",
"answer": "hello"
}
The replace_text replaces specified text in an existing string with the supplied replacement. This can be used to alter formatting of recieved variables. For example, if one queried system provides a number formatted with hyphens, but the destination system requires underscores instead.
The replace_text operation requires the following parameters:
- function = the operation to exectute, which should be set to
replace_text
- text_string = the text you are working with
- replace_this = the string in that text that you want to replace
- with_this = the string the you want to replace it with
"Parameters": {
"operation": "replace_text",
"text_string": "GHKS-KKKLOE-23423-GGS",
"replace_this": "-",
"with_this": "_"
}
Which will result in the following response from Lambda:
{
"result": "success",
"answer": "GHKS_KKKLOE_23423_GGS"
}
The split_text splits a provided string based on a provided split point. Also returns the number of segments identified. This can be used to isolate parts of text retrieved from a query. One example would be in cases where a query returns a customer name as "Doe, John". You could then split and use the result to address the customer by first name only.
The split_text operation requires the following parameters:
- function = the operation to exectute, which should be set to
split_text
- text_string = the text you are working with
- split_at = the string of text that you want to use as your split point
Optionally, you may also specify a maximum split value. The default behavior is to provide all splits in the string, however you can specify the maximum numbwer of splits. Please remember that this is python, so when setting the split_max value, the numbering begins at 0. With this in mind, you would define only one split by setting the split_max value to 0.
- split_max = maximum number of splits. Unless otherwise specified, the operation defaults split_max to -1, which is to return all splits possible.
"Parameters": {
"operation": "split_text",
"text_string": "Doe, John",
"split_at": ", ",
"split_max": "-1"
}
Which will result in the following response from Lambda:
{
"result": "success",
"segment1": "Doe",
"segment2": "John",
"total_segments": "2"
}
The strip_text strips text from the start, end, or from both sides of a string. It has three mode options: trim = strips text from the start and end of a string, left = strips only from the start of a string, right = strips only from the end of a string. This can be used to remove unnecessary characters around a given value. For example, if a customer's driver's license is stored in a DB with the state + license number, you could strip the state and return only the number.
The strip_text operation requires the following parameters:
- function = the operation to exectute, which should be set to
strip_text
- mode = the mode you want to use. Options are: trim,left,right
- text_string = the text you are working with
- strip_this = the characters that you want to strip
"Parameters": {
"operation": "strip_text",
"mode": "left",
"text_string": "WA987654321",
"strip_this": "WA"
}
Which will result in the following response from Lambda:
{
"result": "success",
"answer": "987654321"
}
The lower_text returns the lowercase version of a string. This is helpful when you need data cretrieved from a database to be evaluated in a standardized format.
The lower_text operation requires the following parameters:
- function = the operation to exectute, which should be set to
lower_text
- text_string = the text you are working with
"Parameters": {
"operation": "lower_text",
"text_string": "This tEXt HAS a MIX of CaSeS"
}
Which will result in the following response from Lambda:
{
"answer": "this text has a mix of cases",
"result": "success"
}
The upper_text returns the lowercase version of a string. This is helpful when you need data cretrieved from a database to be evaluated in a standardized format.
The upper_text operation requires the following parameters:
- function = the operation to exectute, which should be set to
upper_text
- text_string = the text you are working with
"Parameters": {
"operation": "upper_text",
"text_string": "This tEXt HAS a MIX of CaSeS"
}
Which will result in the following response from Lambda:
{
"answer": "THIS TEXT HAS A MIX OF CASES",
"result": "success"
}