Conducting a phone poll (Voting)

Would it be possible to conduct a phone poll where a caller would press (for example) 1 for yes or 2 for no and have this entered into a file somewhere AND prevent the same caller from calling in again?

You can do this with Dynamic Routes; see guides linked from

Hi and thanks for your response.
I have had a look through the Dynamic Routes Module link and there really isn’t a use case that fits my purpose.
If using Dynamic Routes is the way to go can someone offer some syntax to place into this module, I would be most grateful.


The link provided literally says “How do I make an automated caller survey?” & “How do I direct all calls to X except when Y is true, then calls go to Z?”

You could have a survey family of Dynamic routes which prompts a question and uses a shell or AGI to put the result with the caller ID into a csv or txt file.

You could have a dynamic route before the survey that uses an agi or shell to check the caller id against the response csv file. if the caller id exists, go somewhere else, otherwise go to the survey.

You could do all this with custom dialplan but dynamic routes is nice in that it adds some guiderails and keeps more of what you are going visible in the FreePBX GUI.

Dynamic Routes Module - PBX GUI - Sangoma Documentation (

Dynamic Routes User Guide - PBX GUI - Sangoma Documentation (

Dynamic Routes - Working Examples - PBX GUI - Sangoma Documentation (

Read up, give it a go, and let us know if you have specific questions.

1 Like

I am having trouble getting the correct ASTERISK VARIABLE to lookup the call event log to see if a caller has already called; I am using $(CDR/${CALLER ID(number)}) ← this isn’t working,

Is your requirement that they have never call before? Or never completed a survey? I would use a MySQL select exists as truth query, using the CALLERID(num) variable, on the CDR database. YOu’ll need to look up the specific names.

MySQL EXISTS Operator (


This would return a 1 or 0 based on if the query found the CALLERID(num) in the database.table.field you were querying in. You would then route 1 or 0 to the different destinations.

This will always find a match because the database table is populated prior to the dynamic route query being executed. The good news is that a match is found.
So how do I make it look for say more that 1 entry?

check the suggestion where else you post

You are not being clear on your requirements.

So how do I make it look for say more that 1 entry?

You need to make a SQL query that counts the number of entries and wrap that in a statement that true/false if greater than two.

If you need help writing SQL, the previous link I sent you can help get you up to speed.

astdb.sqlite3 is a way quicker and more efficient database for this sort of stuff

Hi All, I really appreciate everyone’s input here but I have to admit that creating astdb.sqlite3 and other items outside of the FreePBX GUI is beyond me.
So basically all I want to do is not have the same caller come back to add another vote. I was hoping to use dynamic routes for this but got stuck at the SQL query field - hence this post.

So after some dabbling I have come up with the following which seems to work:


The interval can be changed to whatever SECOND or DAY etc.

So for me this seems like the simplest solution now that I have found the correct syntax for the SQL query.

astdb.sqlite3 does not need to be created, it is the database that drives the dynamic parts of asterisk, and as such probably basic to your needs, All you need to do is to hitch your ‘poll’ to it. in the asterisk cli , you can 'database query . . . ’ using standard sql statements look at the blacklist code/dialplan for inspiration.

It is unlikely that the FreePBX GUI will be useful to you in any way though

in your dialplan pseudo-code

database put yourvotingthing ${Callerid(number) } ok

later you can ‘get’ it

DATABASE PUT - Asterisk Documentation

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.