# Freepbx Survey

**URL:** <https://community.freepbx.org/t/freepbx-survey/48994>\
**Category:** Applications / Modules\
**Created:** [April 9, 2018, 4:02pm UTC](https://community.freepbx.org/t/freepbx-survey/48994 "2018-04-09T16:02:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![bajramia](https://community.freepbx.org/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@bajramia](https://community.freepbx.org/u/bajramia)\
**Post date:** [April 9, 2018, 4:02pm UTC](https://community.freepbx.org/t/freepbx-survey/48994/1 "2018-04-09T16:02:09Z")

</div>

Hi All,  
I’m looking to add a survey for post call, so the queue can send the calls after they spoke to agents so the costumer would have some option like press 1, press 2, press 3, thank you.

---

<div class="post-metadata">

**Author:** ![cynjut](https://community.freepbx.org/user_avatar/community.freepbx.org/cynjut/32/5840_2.png) [@cynjut](https://community.freepbx.org/u/cynjut)\
**Post date:** [April 9, 2018, 4:28pm UTC](https://community.freepbx.org/t/freepbx-survey/48994/2 "2018-04-09T16:28:19Z")

</div>

@Dickson did something like this a couple of months ago, IIRC. Of course, I’m old, so my memory may be failing and it could have all been a dream…

---

<div class="post-metadata">

**Author:** ![PitzKey](https://community.freepbx.org/user_avatar/community.freepbx.org/pitzkey/32/12500_2.png) [@PitzKey](https://community.freepbx.org/u/PitzKey)\
**Post date:** [April 9, 2018, 4:40pm UTC](https://community.freepbx.org/t/freepbx-survey/48994/3 "2018-04-09T16:40:47Z")

</div>

This is crying already for a supported module.

---

<div class="post-metadata">

**Author:** ![bajramia](https://community.freepbx.org/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@bajramia](https://community.freepbx.org/u/bajramia)\
**Post date:** [April 9, 2018, 4:53pm UTC](https://community.freepbx.org/t/freepbx-survey/48994/4 "2018-04-09T16:53:57Z")

</div>

So look like nothing is out there for this issue i know a lot of the companies are using this module so Freepbx should do a commercial module for this thank you.

---

<div class="post-metadata">

**Author:** ![PitzKey](https://community.freepbx.org/user_avatar/community.freepbx.org/pitzkey/32/12500_2.png) [@PitzKey](https://community.freepbx.org/u/PitzKey)\
**Post date:** [April 9, 2018, 5:10pm UTC](https://community.freepbx.org/t/freepbx-survey/48994/5 "2018-04-09T17:10:01Z")

</div>

As dave said, @dickson posted some custom code to accomplish something similar.

There are professionals which you can hire to complete a custom project.

---

<div class="post-metadata">

**Author:** ![cynjut](https://community.freepbx.org/user_avatar/community.freepbx.org/cynjut/32/5840_2.png) [@cynjut](https://community.freepbx.org/u/cynjut)\
**Post date:** [April 9, 2018, 5:18pm UTC](https://community.freepbx.org/t/freepbx-survey/48994/6 "2018-04-09T17:18:52Z")

</div>

> [@bajramia](#):
>
> … so Freepbx should do a commercial module for this …

I haven’t seen the market study you’re basing your conclusion on, but it comes up a couple of times a year, and the code to do it yourself is already out there.

FreePBX is an Open Source, community supported system that Sangoma has purchased the name rights to. They provide a lot of support for a lot of other commercial modules, but that’s part of their business model. If you want to support the business, I’m sure you could foot the bill of a few developers for a couple of weeks to turn this into a commercial package. Nothing keeping you from writing a check.

Stuff like this (small market, almost no User Interface required) is and should probably continue to be projects left to the users that build the system or the professionals that develop and install the code. If you want to buy support from @Dickson, I’m pretty sure he’s available. If you want to buy support from Sangoma, I’m pretty sure they’ll help you do the work yourself.

This isn’t a Panasonic PBX - it’s far more flexible and responsive to the savvy developer and integrator’s needs. As a community, we provide a lot of support for people that are willing to help themselves. This also isn’t a $25,000 PBX system with contract support. You got it for free and you are expected to do the work yourself. It’s all just part of the bargain.

---

<div class="post-metadata">

**Author:** ![bajramia](https://community.freepbx.org/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@bajramia](https://community.freepbx.org/u/bajramia)\
**Post date:** [April 10, 2018, 12:21am UTC](https://community.freepbx.org/t/freepbx-survey/48994/7 "2018-04-10T00:21:50Z")

</div>

HI Cynjut,  
I think you miss understood me, what i want to ask is if there is a user interface out there so customers can easy run a report on the outcom of the survey and i know the freePbx it is flexible that whay i did ask.

Thank you for you help as always.

---

<div class="post-metadata">

**Author:** ![dickson](https://community.freepbx.org/user_avatar/community.freepbx.org/dickson/32/12841_2.png) [@dickson](https://community.freepbx.org/u/dickson)\
**Post date:** [April 10, 2018, 1:18am UTC](https://community.freepbx.org/t/freepbx-survey/48994/8 "2018-04-10T01:18:26Z")

</div>

I wrote some code that allowed you to do surveys, kind of like what you are looking for I think (as mentioned by some major contributors to this forum!) And I think that I could make it run like a report with some modifications by using the account codes in the CDR table. You could run a CDR report with some selections i think and get the data you want (at least into excel or similar)

What exactly are you looking for? I can code up an example for you to try.  
Was it just one question you wanted to ask? Or multiple questions?

---

<div class="post-metadata">

**Author:** ![bajramia](https://community.freepbx.org/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@bajramia](https://community.freepbx.org/u/bajramia)\
**Post date:** [April 10, 2018, 1:48am UTC](https://community.freepbx.org/t/freepbx-survey/48994/9 "2018-04-10T01:48:07Z")

</div>

Hi Dickson,  
Thank you for responding i want to have multiple question like for example,

1. How was your call with agent?  
Press 1 for bad  
Press 2 for good  
Press 3 for excellent

2.How professional was the service you received?  
Press 1 for excellent  
Press 2 for good  
Press 3 bad

Somthing like this  
Thank you.

---

<div class="post-metadata">

**Author:** ![dickson](https://community.freepbx.org/user_avatar/community.freepbx.org/dickson/32/12841_2.png) [@dickson](https://community.freepbx.org/u/dickson)\
**Post date:** [April 10, 2018, 1:49am UTC](https://community.freepbx.org/t/freepbx-survey/48994/10 "2018-04-10T01:49:04Z")

</div>

Do you want this to happen automatically? or do you have your agents transfer customers to the survey.

---

<div class="post-metadata">

**Author:** ![bajramia](https://community.freepbx.org/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@bajramia](https://community.freepbx.org/u/bajramia)\
**Post date:** [April 10, 2018, 1:51am UTC](https://community.freepbx.org/t/freepbx-survey/48994/11 "2018-04-10T01:51:27Z")

</div>

If is it posible to send the automatically to ivr then give them option to take a survey press 1 or just hangup

Thank you.

---

<div class="post-metadata">

**Author:** ![dickson](https://community.freepbx.org/user_avatar/community.freepbx.org/dickson/32/12841_2.png) [@dickson](https://community.freepbx.org/u/dickson)\
**Post date:** [April 10, 2018, 1:52am UTC](https://community.freepbx.org/t/freepbx-survey/48994/12 "2018-04-10T01:52:26Z")

</div>

i’ll code something up tomorrow and post something for you to try

---

<div class="post-metadata">

**Author:** ![bajramia](https://community.freepbx.org/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@bajramia](https://community.freepbx.org/u/bajramia)\
**Post date:** [April 10, 2018, 1:52am UTC](https://community.freepbx.org/t/freepbx-survey/48994/13 "2018-04-10T01:52:58Z")

</div>

Thank you so much

---

<div class="post-metadata">

**Author:** ![dickson](https://community.freepbx.org/user_avatar/community.freepbx.org/dickson/32/12841_2.png) [@dickson](https://community.freepbx.org/u/dickson)\
**Post date:** [April 10, 2018, 10:08pm UTC](https://community.freepbx.org/t/freepbx-survey/48994/14 "2018-04-10T22:08:46Z")

</div>

Here’s a demo, let me know if this is what you are looking for? If so I’ll build in some more logic checks around wrong answers.  
Again, this code atm is DEMO for you to try out and see if it will do what you want:

**What this does:**  
When activated, it will ask a question, then allow the user to place an answer. This demo asks 2 questions.  
Once the caller answers the questions and hangs up, the values entered are written to the “USERFIELD” in the CDR table.

You can go to the CDR module in freepbx and see the values for each caller in this database.

**TODO**  
Some code around the values entered to make sure they are in range IE 1-3 valid, but user enter 5  
Having it automatically triggered at end of agent call.

**INSTALLATION**  
create your ‘questions’ in system recordings. I called mine “question1” and “question2”  
Create a thank you message. My file was saved as “thankyouforyourtime”.

open up /etc/asterisk/extensions\_custom.conf  
Go to the bottom of the file, paste in the following: (noted the portion /custom/questionX the last bit is your file name, so if you saved them differently, you’ll need to update the filename name in the code)

```
[macro-survey]
exten => s,1,answer()

;this asks the first question (based on your recording) and stores them in variable
exten => s,n(question1),Read(answer1,/var/lib/asterisk/sounds/en/custom/question1,1,,1,2)
exten => s,n,GotoIf($[${answer1} < 4]?question2:question1)

;this asks the first question (based on your recording) and stores them in variable
exten => s,n(question2),Read(answer2,/var/lib/asterisk/sounds/en/custom/question2,1,,1,2)
exten => s,n,GotoIf($[${answer2} < 4]?finish:question1)

;this line puts the two answers together and separates them with a | symbol.
exten => s,n(finish),set(answer=${answer1}|${answer2})

;this saves the answers into the CDR field of "userfield"
exten => s,n,Set(CDR(userfield)=${answer})

;This line will send an email with the subject saying "Survey John Smith 555-123-4455 3|2"
exten => s,n,system(mail -s "Survey ${CALLERID(name)} ${CALLERID(number)} ${answer}" EMAIL@ADDRESS.COM < /dev/null)

;play a thankyou message. you can just remove this line for anyone who doesn't want the thankyou.
exten => s,n,playback(/var/lib/asterisk/sounds/en/custom/thankyouforyourtime)

exten => s,n,hangup() 

```

SAVE changes

In FreePBX goto CUSTOM DESTINATIONS and create a new custom destination  
TARGET= macro-survey,s,1  
Description=enter something so you know what this dos. “ **queuesurvey** ” for example

Save Changes

Create a ring group number  
(we’ll use a ring group failover destination as a way to trigger this code)  
Extension list = put in a dummy number that doesnt’ exist in your pbx. I usually put in “1”.  
go down to “Destination if no answer” and select CUSTOM DESTINATION -\> queuesurvey

save your changes and apply them with the red button.

**TEST CODE**  
Call your ring group.  
You should hear your first question. Press “2”  
You should now hear your second question, Press “3”  
Call will hang up

Go to CDR reports and run a report (usually can just hit SEARCH) and it will show the most recent calls. You should see your call, and in “USERFIELD” you’ll see “2|3”

2 is the first answer, “|” (pipe) is a delimiter, and 3 is the second answer.

---

<div class="post-metadata">

**Author:** ![bajramia](https://community.freepbx.org/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@bajramia](https://community.freepbx.org/u/bajramia)\
**Post date:** [April 10, 2018, 10:17pm UTC](https://community.freepbx.org/t/freepbx-survey/48994/15 "2018-04-10T22:17:40Z")

</div>

Hi Dickson, thank you so much I will give a try and I will let you know how it worked and again thank you so much

---

<div class="post-metadata">

**Author:** ![bajramia](https://community.freepbx.org/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@bajramia](https://community.freepbx.org/u/bajramia)\
**Post date:** [April 11, 2018, 1:50pm UTC](https://community.freepbx.org/t/freepbx-survey/48994/16 "2018-04-11T13:50:16Z")

</div>

Hi Dickson,  
I did test it and it did worked good i have the output to CDR  
Hangup s [macro-survey] ANSWERED 00:20 1|3  
I have 2 question.  
1 I would like when the question 2 is answered to go and read thank you recording saying " thank you for participation on the survey goodbye" then hangup.

2 how i would know for which Agent was this survey entered  
example.  
I have 2 queues with 3 to 5 agents per each queue if I’m a costumer and i spoke to agent A and I take the survey how i know what survey was for Agent A

Thank you For your help

---

<div class="post-metadata">

**Author:** ![PitzKey](https://community.freepbx.org/user_avatar/community.freepbx.org/pitzkey/32/12500_2.png) [@PitzKey](https://community.freepbx.org/u/PitzKey)\
**Post date:** [April 11, 2018, 1:57pm UTC](https://community.freepbx.org/t/freepbx-survey/48994/17 "2018-04-11T13:57:05Z")

</div>

Also, is there a possibility to email the results?

---

<div class="post-metadata">

**Author:** ![dickson](https://community.freepbx.org/user_avatar/community.freepbx.org/dickson/32/12841_2.png) [@dickson](https://community.freepbx.org/u/dickson)\
**Post date:** [April 11, 2018, 2:34pm UTC](https://community.freepbx.org/t/freepbx-survey/48994/18 "2018-04-11T14:34:48Z")

</div>

I added a line in the code example above for the “thankyou” message.  
just record a file and call it “thankyouforyourtime”. give it a test.

Insert the “playback” line below in between the existing lines show below.

exten =\> s,n,Set(CDR(userfield)=${answer})

```
;play a thank you message. you can just remove this line for anyone who doesn't want the thank you.
exten => s,n,playback(/var/lib/asterisk/sounds/en/custom/thankyouforyourtime)

```

exten =\> s,n,hangup()

Save your changes and from the CLI type in

**asterisk -rx 'core reload’**

I’ll work on the agent bit now

@PitzKey

Add the line in the box below under neath the code in bold to get the system to send an email after the entry.  
**exten =\> s,n,Set(CDR(userfield)=${answer})**

```
;This line will send an email with the subject saying "Survey John Smith 555-123-4455 3|2"
exten => s,n,system(mail -s "Survey ${CALLERID(name)} ${CALLERID(number)} ${answer}" EMAIL@ADDRESS.COM < /dev/null)

```

The code in my original post has been updated with these above entries if you just want to copy/paste the whole thing again.

---

<div class="post-metadata">

**Author:** ![bajramia](https://community.freepbx.org/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@bajramia](https://community.freepbx.org/u/bajramia)\
**Post date:** [April 11, 2018, 8:54pm UTC](https://community.freepbx.org/t/freepbx-survey/48994/19 "2018-04-11T20:54:10Z")

</div>

Thank you Dickson that worked i did a test works grate thank you.

---

<div class="post-metadata">

**Author:** ![Offer](https://community.freepbx.org/letter_avatar_proxy/v4/letter/o/bc79bd/32.png) [@Offer](https://community.freepbx.org/u/Offer)\
**Post date:** [April 13, 2018, 1:44pm UTC](https://community.freepbx.org/t/freepbx-survey/48994/20 "2018-04-13T13:44:22Z")

</div>

Dear Dickson.

It’s so touching to see your effort to help with this important project.

Just a little thing, please:  
I get the idea of demo testing using the ring-group failover option.  
But in real life - my big difficulty is how to automatically forward the customer to this destination when the agent hang-up.  
I think the main issue here is how to catch the call before hang-up after the destination cannel is not there already.

Would you please clarify or demonstrate this?

Many thanks for this!

[Next page](https://community.freepbx.org/t/freepbx-survey/48994.md?page=2)
