Manipulating string values to internationalize telephone numbers

This piece will just concentrate on the string manipulation for the automated SMS send, and not go into detail describing how the event should be configured within the call flow. Knowledge of application configuration, including for Input Readers, will be assumed.

During a call, information in the form of text or numbers becomes known to the babelforce platform. It could be automatically processed, for example call information such as the caller's phone number; or it could be entered as an input by the caller, for example a reference number. These 'strings' of letters and numbers can be used in other events in the same call flow.

Sometimes their form has to change in order for them to be used. In our example here, the string will be a mobile phone number and the event will be an automated SMS send. The business would like to send an support SMS to the mobile phone number if the caller chooses that option. 

Automated SMS send

There are 2 scenarios for the SMS send:

  1. The call is made from a mobile phone. If this is the case, the babelforce platform will automatically recognize it and have it ready to use for the automated SMS. It won't require any manipulation.
  2. The call is made from a landline and the customer enters a mobile number into an Input Reader. To make this as reliable as possible and optimize the caller's experience, they are asked to enter it in its simple local form, i.e. '01234567891'. 

So how do we deal with scenario 2? First we will need to set a trigger which recognizes that the input number (saved in the Input Reader as a variable called "mobileinput") is local, i.e. that it isn't prefixed with the country code but instead starts with the standard "0" for local mobile phone numbers:


 

Note that the 'Expression' used here is found under the 'Voice Application' section of the drop-down menu.

Now that we have a trigger to test this, the local event can be configured to run in the application which follows the Input Reader, which is just a simple Prompt Player informing the caller that the SMS has been sent:


 

There are a couple of things to note here before we dive into the expression used in the 'To' field. Firstly, the 'Position' of the action should be 'Before', because we want the event to be run as soon as we get to the confirmation message, and because setting it to run after the application has finished its work is unreliable: what if the caller hears the confirmation and hangs up before it has finished? 

The trigger should be the one we created above, which will ensure that the event will only send an SMS to a number prefixed with a 0. It is required to ensure that the 'To' expression is evaluated properly.  

Lets take a closer look at the expression then:

49{app.inputReader.mobileinput|substr:1} 

  • The bit inside the curly braces but before the vertical line - "app.inputReader.MobileInput" - designates the given string for our variable "MobileInput". It takes whatever is entered in the Input Reader for that call.
  • The next bit - "|substr:1" - takes the string declared in the first bit and performs a manipulation on it, removing the first character.
  • Finally the "49" is added to the beginning of the string. 

We have used "49" as an example (it is the German country code so you should know from which country your customers call you), but no matter which is used the end result will be a string which resembles a phone number with an international country code prefix, e.g. "491234567891". This is the format which babelforce requires to be able to send the SMS. 

When a caller reaches the Input Reader and enters a mobile number, the string is assigned to the variable "MobileInput". This string has to be entered correctly, so it is crucial that the Input Reader is configured correctly. An explanatory prompts must inform the caller of the format, and the 'Termination key' setting on the app must be a kind of special character like a "#" to prevent number confusion.

Further reading - more on string manipulation

As mentioned at the beginning of the piece, there could be more use cases for this kind of manipulation. A common one would be a business which makes use of customer reference numbers (CRN).

Let's say this business has 8-character customer reference numbers which take the following structure:

  • 87 - the first two numbers indicate the department
  • 65 - the second two indicate the department section
  • 4321 - the last 4 designate the customer's unique number

When a caller enters their number, the business wishes to manipulate the CRN and use the resulting sub-strings with their Helpdesk integration, updating the content of tickets. 

They require manipulations which isolate the different parts on the CRN. Let's take "custrefno" as our variable. The following expressions correspond to the sub-strings we are looking for:

  • {app.inputReader.custrefno|substr:0:2} - department
  • {app.inputReader.custrefno|substr:2:4} - section
  • {app.inputReader.custrefno|substr:4:7} - unique number 

The numbers after the "substr" expression refer to positions of characters in the variable. The first number designates which position to start with (beginning with the 0th position), and the second number is the non-inclusive endpoint. This means that the corresponding character is not included in the sub-string, only the one before it.

Think of the first expression above ("{app.inputReader.custrefno|substr:0:2}"), then, as saying: 'Select the sub-string which begins at position 0 [the first character] and runs up until, but not including, position 2 [the third character].'  

Have more questions? Submit a request