Dynamically Reference Subscriptions

When editing the Subscribe or Unsubscribe handlers, you can choose to select the subscription by evaluating an expression. This lets you dynamically reference the subscription from which to subscribe or unsubscribe the user.

You may want to do this if you want to use the same service to subscribe users to separate subscriptions. This could occur if you have multiple services or campaigns, or if a campaign needs to separate uses based on user input. For example, you might want to add a user to a subscription based on the keyword they sent in.

To dynamically reference a subscription, you must create a "constant" variable for the subscription. Constant variables can use either the Service or Service Collection scope.

To create a constant variable:

  1. In the service editor screen for a service, click either Variables or Collection Variables.

    The Edit Variables dialog box appears for the applicable variable type selected.

  2. In the Edit Variable dialog box, click the Constants tab.
  3. Click Create new constant.
  4. Enter a Key for the variable, select Subscription from the Type drop-down list, and then from the Value drop-down list select the subscription you want to reference.
  5. Click Save.

Once you have created the constant variables for your subscriptions, you can then use an expression in the Subscribe or Unsubscribe handler to reference the subscription.

For example, you could set the key for each variable to a keyword for your short code:

  • Keywords for the short code: cat, dog, cow
  • Constant variables created: service.cat, service.dog, service.cow

Then use the following expression in the Subscribe handler:

${service.subscriptions[request.keyword.name]}

So, if an end user texted in the keyword "cat", the expression would add them to the subscription referenced by the variable service.cat.