Dynamically Reference SMS Accounts

When configuring the Send SMS handler you will need to define the SMS account to use. Instead of selecting a specific SMS account, you can choose to evaluate an expression to select the SMS account. This lets you dynamically reference which SMS account to use when sending the message.

You may want to do this, if:

  • You have multiple routing codes — for example, this might be a short code that use the same service, and you want an easy way to ensure the correct routing code is used in messages to your end users
  • You want to bill some users but not others (for example, bill your customers but not employees testing a service).

To dynamically reference an SMS account, you must create a "constant" variable for the SMS account. Constant variables can use either the service or servicecoll scope. To create one of these variables:

  1. In the service editor screen for a service, select either Variables or Collection Variables. This opens the edit page for variables.
  2. In the edit interface, select the Constants tab.
  3. Enter a Key for the variable, select SMS Account from the Type drop-down list, and then select the SMS account you want to reference.

Once you have created the constant variables for your SMS accounts, you can then use an expression in the Send SMS handler to reference the SMS account.

For example, if you had to choose between two accounts, you could use a conditional operator (A ? B : C) to select the right account:

${user.inFreeList == 'true' ? service.smsaccount[‘-free’] : service.smsaccount[‘-paid’]}

Where user.inFreeList is a custom variable created earlier in the service to check whether the end user is in a specific subscription.