Skip to content

Logic and data

Reuse answers, send callers down different paths, show live data from your systems, and reuse other apps.

Saved answers (variables)

Every answer saved with Save the answer as, every value saved from an API, and a few built-in values can be used anywhere text is typed: screen text, API addresses, request bodies and conditions.

WriteBecomes
{{amount}}The answer saved as amount, e.g. 50
{{MobileNumber}}The caller’s phone number
{{SessionId}}The session’s unique id, handy for matching payments
Good to know: In screen text and web addresses, use double curly brackets: {{amount}}. In Smart Router conditions, write the plain name: amount > 100.

Smart Router

Sends the caller down different paths depending on a value, without showing them anything. For example: balances over GHS 100 go to one screen, everything else to another.

  1. Add a Smart Router

    Click Smart Router in the toolbox and connect the previous screen to it.
  2. Write a condition

    Open its Branches section and type a condition like balance > 100. The small buttons under the box insert operators for you.
  3. Add a fallback branch

    Add one more branch and turn on Use when nothing else matches. It catches every caller no other branch matched. Always add one: without it, a caller who matches nothing hits an error.
  4. Connect each branch

    Each branch gets its own dot on the router. Drag each one to the screen it should lead to.
OperatorExampleTrue when
== / !=network == MTNequal / not equal
> < >= <=amount >= 10comparing numbers
containsname contains Mensahthe text includes it
startsWith / endsWithphone startsWith 024the text begins / ends with it
AND / ORage >= 18 AND status == activeboth / either are true
  • Branches are checked in order; the first true one wins.
  • Write the saved answer's name first, then the operator, then the value, with spaces between: name contains Mensah. Quotes around the value are optional.
  • Text comparisons ignore upper and lower case.
  • Use either AND or OR in one condition, not both. For more complex rules, chain two Smart Routers.
  • A condition about an answer that was never saved is false, so that caller goes to the fallback branch.

Send Data

Calls your system (any web API) in the middle of a session, for example to look up a balance or register a customer, and saves values from the reply for later screens. The caller sees nothing while it runs.

  1. Add Send Data and open its settings

    Click Send Data in the toolbox, then open the Request section.
  2. Enter the address

    Choose the method (GET to fetch, POST to send; your API's documentation says which) and type the address. You can put saved answers in it:
    API URL
    https://api.example.com/customers/{{MobileNumber}}/balance
  3. Add a body (POST, PUT or PATCH)

    Type the JSON to send. Saved answers work here too:
    Request body
    { "phone": "{{MobileNumber}}", "amount": "{{amount}}" }
  4. Add headers if your API needs them

    For example an Authorization header with your API key.
  5. Save values from the reply

    Under Save From Response, press Add and pair a path in the reply with a name. If your API answers:
    Your API's reply
    { "data": { "balance": 125.50, "name": "Ama" } }
    then $.data.balance → balance lets a later screen say:
    Hi Ama, your balance is GHS 125.50.
Watch out: Your API must answer within 2 seconds, because the caller is waiting on a live USSD session. If it is slower or fails, the session carries on to the next screen without those values. To handle that, put a Smart Router after Send Data with a branch for the normal case (for example balance >= 0) and a Use when nothing else matches branch that leads to a friendly "Please try again later" screen.

For safety, Send Data only calls public internet addresses, never private or local network addresses.

Menus filled from your API

A Choice Menu can fetch its options from your system each time, for example a product list. Asterisks numbers them and splits long lists across pages, with 99. Next and 00. Back.

  1. Switch the options source

    In the menu's Menu options, choose Your API.
  2. Enter the address

    Type the address that returns your list (GET, or POST with a body).
  3. Tell Asterisks which fields to use

    Say your API returns:
    Your API's reply
    { "products": [
        { "id": 1, "title": "Rice 5kg" },
        { "id": 2, "title": "Cooking oil" }
    ] }
    Set Label field to title (what callers read), Value field to id (what gets saved), and Path to the list to products. Leave the path empty if your API returns a plain list.
  4. Name the choice

    Save the choice as: for example productId. The chosen item's value is saved there for later screens and API calls.
  5. Connect the menu

    An API menu has one dot; connect it to the screen that should follow any choice.

Sub-flow

Runs another of your published apps inside this one, then comes back. Build a common piece once, such as registration, and reuse it in several apps.

  1. Publish the app you want to reuse

    Only published apps can be used as sub-flows.
  2. Add a Sub-flow screen

    Click Sub-flow in the toolbox, open it, and choose the app under App to run.
  3. Pass values in and out (optional)

    Inputs passed in copies values into the sub-flow; Outputs passed back copies answers back out, for example the sub-flow's name into this app's memberName.
  4. Connect what comes next

    When the sub-flow reaches its end, the caller continues at the screen connected after the Sub-flow screen.

Example

A "Member hub" app runs your "Register" app as a sub-flow, then greets the caller by the name they just entered:

Back in the hub. Welcome, Akua Mensah!