Template Variables Reference
Template Variables
Template variables enable dynamic content in your USSD applications. Use double curly braces {{...}} to insert values from session data, API responses, configuration, and secrets.
Variable Scopes
| Scope | Syntax | Description |
|---|---|---|
| Session | {{session.*}} | Current session data and user input |
| Response | {{response.*}} | Data from the most recent API call |
| Environment | {{env.*}} | Application environment variables |
| Options | {{options.*}} | Application configuration options |
| Secrets | {{secrets.*}} | Tenant-scoped secrets (requires secrets engine) |
| Organization | {{org.*}} | Current tenant/organization info |
| Application | {{app.*}} | Application metadata |
Session Variables
Session variables contain data about the current USSD session and user interactions.
Built-in Session Variables
| Variable | Description | Example |
|---|---|---|
{{session.msisdn}} | User's phone number | +231886123456 |
{{session.id}} | Unique session identifier | sess_abc123xyz |
{{session.shortcode}} | USSD shortcode dialed | *123# |
{{session.input}} | User's most recent input | 1 |
{{session.networkid}} | Mobile network identifier | orange-lr |
{{session.provider}} | Network provider name | Orange |
Custom Session Data
Actions can store data in the session using target or response_map:
Code
Custom session data is accessible via {{session.data.*}} or the shorthand {{variable}}.
Nested Data Access
Access nested objects using dot notation:
Code
Response Variables
Response variables provide access to the most recent API call's response body.
Code
JSONPath Response Mapping
Map specific response fields to session variables:
Code
Environment Variables
Define application-specific configuration in the env block:
Code
Referencing Secrets in Environment
Combine with secrets for secure configuration:
Code
Options Variables
Access global application options:
Code
| Variable | Description |
|---|---|
{{options.http_base_url}} | Global HTTP base URL |
Secrets Variables
Access tenant-scoped secrets securely. Requires a configured secrets engine.
Code
Secrets are resolved at runtime and are never exposed in logs or error messages. Always use secrets for sensitive data like API keys, passwords, and tokens.
Organization Variables
Access information about the current tenant:
| Variable | Description | Example |
|---|---|---|
{{org.id}} | Tenant/organization ID | org_abc123 |
Application Variables
Access metadata about the current application:
| Variable | Description | Example |
|---|---|---|
{{app.name}} | Application name | MyBankingApp |
{{app.version}} | Application version | 1.0.0 |
{{app.shortcode}} | Application shortcode | *123# |
Template Syntax
Basic Substitution
Code
Nested Object Access
Code
In URLs and Headers
Code
In Request Bodies
Code
Variable Resolution Order
When a variable name doesn't include a scope prefix, it's resolved in this order:
session.data.*(custom session data)session.*(built-in session variables)response.*(most recent API response)
Code
Default Values
Currently, templates do not support inline default values. Use conditional actions or the env action with fallback for defaults:
Code
Best Practices
-
Use explicit scopes - Prefer
{{session.data.amount}}over{{amount}}for clarity. -
Validate before using - Ensure variables exist before referencing them in critical paths.
-
Secure sensitive data - Always use
{{secrets.*}}for credentials, never{{env.*}}with hardcoded values. -
Document custom variables - Comment your DSL to indicate where custom session variables are set.
Code
- Handle missing data gracefully - Use
error_targetin action chains to catch API failures.