MEP Expression Language
Overview
This guide is intended primarily for developers and those familiar with using scripting languages. It provides detailed information about using the MEP Expression Language to perform a wide range of complex operations in MEP, including creating and updating dynamic values as part of a service.
What is Expression Language?
MEP Expression Language (EL) is a scripting language that enables you to perform a wide range of complex operations in MEP. The most common task of EL is to create and update dynamic values, often as part of a service. Simple uses of EL, used by many services, include storing an end user's details (e.g. name, age, and address) and counting the number of times the service has been triggered.
An individual instance of EL is called an expression. When MEP finds an expression in a service it calculates the expression’s value. Each expression results in one value. The types of values an expression can equal are:
- Boolean (either true or false).
- An integer (-4, -1, 0, 1, 4) or floating point (-2.1, 4.573) number.
If you include both integers and floating point numbers in an expression, any combined value becomes a floating point number. - An alphanumeric string (e.g. "5 blue cars")
You must restrict strings to characters in the US-ASCII character set. Note that if the grave accent ( ` ) character is sent via SMS then it may be replaced by an apostrophe ( ' ). - Null (no value).
You can use expressions in a wide variety of places in MEP including most of the editable fields in Services, such as the SMS Message, SMS To, and Originator fields. Values related to a specific end user can be referenced in the Services, Subscriptions and Broadcasts tabs within MEP.
Syntax basics
An EL expression is delimited by the dollar character and braces, for example:
${...expression...}
An expression is composed of one or more different elements. These elements are:
- Variables — these hold values that you can read and update.
- Functions — these perform complex tasks to return a value you need. (You might then store the value as a variable.)
- Text strings and digits
- Operators — these enable you to do arithmetic and logical calculations in the expression.
You can nest expressions using parentheses. Expressions inside a set of parentheses are resolved before the expression outside of it. For example, in the following, expressionB is resolved first:
${expressionA(expressionB)}
Why use Expression Language?
Expression Language, in conjunction with MEP’s sophisticated range of components, enables you to create services that are context and user sensitive, providing your end users with an enhanced user experience. For example, you can change a service’s behavior and the contents of its messages based on an end user’s details, an end user’s previous actions, or the service conditions (such as the time of day).
MEP contains many templates and handlers that enable you to set up a complex service quickly. You can use EL to either further enhance a template service, or create a new custom service from scratch. A few simple uses within a service include:
- Branching the service based on whether an end user has answered a question correctly
- Forwarding data, such as an end user’s mobile number, to an external platform or server
- Ensuring that an end user can only access a service once (such as for a voting or competition service)
For instance, using the above example uses, you can build a questionnaire service that uses EL to gather a series of answers from an end user over multiple SMS interactions, branch the service based on the responses, and forward the answers and the end user’s details to an external server via HTTP.
Common tasks you can perform with EL
Performing calculations on values (such as subtracting or multiplying)
For example: counting the total number of users who have used a service, counting the number of times a specific user has accessed your services, tallying a user's score in a quiz, calculating a value from user input.
Comparing one value with another value
For example: determining whether a PIN has already been used, determining whether a time or date is in the past or future, checking user responses to a quiz.
Searching for specific content within a text string or timestamp
For example: finding a user's post or zip code in an SMS, finding a user's date of birth, checking for a specific word in an SMS.
Forwarding data to an external platform
For example: referencing an end user's mobile number (or other data) then forwarding that to your own platform.
Retrieving data from an external platform
For example: retrieving a unique PIN or password for the user, or data like the current temperature, traffic conditions, or latest score in a sports game.
Interpreting and formatting content before it is sent to another platform or used by the service
For example: changing a US timestamp into a UK timestamp, removing the punctuation from an address or quiz answer.
Referencing end user details to include in broadcast messages
For example: the end user's name, birthday, or membership details for your business.
Branching a service based on the value of an expression
For example: branching based on whether they've answered a question correctly, whether they've chosen a specific option (e.g. nearest "dentist" or "doctor"), whether the current time and date is past a specified time and date (for example, if a competition has closed).