Skip to content

Tutorial: a poll

A one-question poll, start to finish: save the choice, post it with the caller’s phone number, and handle a repeat vote.

What you will build

A one-question poll. The caller picks an answer, and your API receives the choice with the caller's phone number, so each number counts once. It takes about fifteen minutes and uses four kinds of step: a menu, Send Data, a Smart Router and End Session.

Which road should be fixed first?
1. Spintex Road
2. Kaneshie-Mallam
3. Adenta-Dodowa
The question
Thank you. Your vote is recorded.
After a first vote
StepTypeWhat it does
WelcomeEntry PointSays what the poll is and offers Vote or Exit.
QuestionChoice MenuSaves the choice as road.
Submit voteSend DataPosts road and the caller's number to your API.
Already voted?Smart RouterReads your API’s answer and picks the closing screen.
Three closing screensEnd SessionRecorded, already voted, and try again later.

What your API needs

One address that accepts a vote and says whether it was new. Asterisks will send:

POST https://api.example.com/polls/roads-2026/votes
{
  "phone": "233241234567",
  "choice": "spintex"
}

and expects one of these back, within 2 seconds:

Reply
{ "status": "recorded" }
{ "status": "duplicate" }
Tip: Let your API decide what a duplicate is: keep one vote per phone number and answer duplicate for the second. A caller whose network drops may dial and vote again, and your count stays right.

Build it

Create an app with New app and Start from a blank canvas, as in the Quickstart. Then add the steps.

  1. Set up the welcome screen

    Open the Entry Point. In What the phone shows type Accra Roads Poll. Under Menu options, name the options Vote and Exit.
  2. Add the question

    Click Choice Menu in the toolbox. Set What the phone shows to Which road should be fixed first? and add three options. Give each a label and a Value, the short code your API will receive:
    LabelValue
    Spintex Roadspintex
    Kaneshie-Mallamkaneshie_mallam
    Adenta-Dodowaadenta_dodowa
    In Save the choice as, type road.
  3. Send the vote to your API

    Click Send Data. In its Request section choose POST and enter your address. Then fill in the body:
    Request body
    {
      "phone": "{{MobileNumber}}",
      "choice": "{{road}}"
    }
    Under Save From Response, press Add and pair $.status with voteStatus.
  4. Branch on the answer

    Click Smart Router. In Branches, set the first branch to voteStatus == duplicate. Everything else will leave by ELSE.
  5. Add the closing screens

    Click End Session three times and set the text of each:
    • Thank you. Your vote is recorded.
    • You have already voted. Thank you.
    • We could not record your vote. Please try again later.
    Add one more End Session with Goodbye. for the Exit option.

Join the steps

Drag from the dot on the left-hand step to the top of the right-hand one:

FromTo
Welcome, option VoteThe question
Welcome, option ExitGoodbye.
The question (each option)Submit vote
Submit vote, bottom dotThe Smart Router
Submit vote, FAILWe could not record your vote.
Router, first branchYou have already voted.
Router, ELSEThank you. Your vote is recorded.
Watch out: Connect FAIL on every Send Data step. Without it, a caller whose vote never reached your API would carry on and be thanked for a vote you do not have.

Press Check flow, fix anything it names, then Save.

Test it

  1. Open the phone preview

    Press Test in the top bar. In Dial from, type the number the test should call from, such as 0241234567. Your app receives it as {{MobileNumber}}.
  2. Vote once

    Reply 1, then 2. You should see the recorded message.
  3. Vote again from the same number

    Press Dial again and repeat. Your API answers duplicate and you see the already-voted message. The Smart Router never appears: it picks the branch and moves on.
  4. Vote from another number

    Change Dial from to a different number and dial again. The vote is recorded.
  5. Break it on purpose

    Put a typo in the Send Data address and dial again. You should land on the try-again screen, by the FAIL route. Fix the address afterwards.
Good to know: In the preview, Send Data calls your API from your browser, so the API must be on https:// and allow requests from the dashboard (CORS). On a real phone the call comes from Asterisks' servers and CORS does not apply. Testing against your laptop? An ngrok address works: the preview adds the header ngrok asks for.

Make it yours

  • More than one question: add another Choice Menu after the first, save it under its own name, and add it to the request body.
  • A typed answer: use Ask a Question in place of the menu and send {{comment}}.
  • Options from your system: switch the menu's Options come from to Your API. See Logic and data.
  • Show the tally: have your API return it, save it with Save From Response, and write {{tally}} on the closing screen.