# Dialplan, read rows from textfile, then continue

**URL:** <https://community.asterisk.org/t/dialplan-read-rows-from-textfile-then-continue/43860>\
**Category:** Asterisk Support\
**Created:** [September 9, 2013, 9:19am UTC](https://community.asterisk.org/t/dialplan-read-rows-from-textfile-then-continue/43860 "2013-09-09T09:19:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![scorch](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/scorch/32/292_2.png) [@scorch](https://community.asterisk.org/u/scorch)\
**Post date:** [September 9, 2013, 9:19am UTC](https://community.asterisk.org/t/dialplan-read-rows-from-textfile-then-continue/43860/1 "2013-09-09T09:19:56Z")

</div>

Hi,

First, I’m new to Asterisk/dialplans etc so bear with me.

I have a webpage with checkboxes which triggers a perl script when submitted. The perl script then generates a textfile based on the checkbox values. The purpose of this is to generate a series of soundfiles to be played when someone calls. The order and number of these soundfiles can vary depending on the choices on the webpage.

Here’s an example of what the textfile can look like (the way it’s formatted right now):

[quote]exten =\> s,n,Playback(awav1)  
exten =\> s,n,Playback(pa)  
exten =\> s,n,Playback(20)  
exten =\> s,n,Playback(i)  
exten =\> s,n,Playback(1)  
exten =\> s,n,Playback(2)  
exten =\> s,n,Playback(4)  
exten =\> s,n,Playback(awav2)[/quote]  
I want the normal dialplan to read the rows from this file so it plays the sounds listed in the textfile and the continue on as normal (or just continue if all the checkboxes are empty and the script generated an empty file). Lets say the current dialplan looks like this:

[quote]exten =\> s,1,Answer  
exten =\> s,n,Playback(tt-weasels)  
exten =\> s,n,Hangup[/quote]  
I want to change it to this:

[quote]exten =\> s,1,Answer  
Read rows from textfile here!  
exten =\> s,n,Playback(tt-weasels)  
exten =\> s,n,Hangup[/quote]

Can this be done? If so, how?  
If not, any suggestions on how to do it?

---

<div class="post-metadata">

**Author:** ![abw1oim](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@abw1oim](https://community.asterisk.org/u/abw1oim)\
**Post date:** [September 9, 2013, 10:03am UTC](https://community.asterisk.org/t/dialplan-read-rows-from-textfile-then-continue/43860/2 "2013-09-09T10:03:36Z")

</div>

This way it won’t work.

But the good news comes here:

You may reach Your goal by using AGI which than just interprets the content from Your webservice and does the things You want it to do (eg Playbacks).

Another approach may be the following:  
Let the webpage store the result of the checkboxes in one line each checkbox-value separated from each other by a specific character. To stay in Your exmaple this may be:

```auto

```

(No carriage return / line feed at the end of the list!)  
We assume for the code snippet the filename of this file to be /etc/asterisk/list.txt.

In Your dialplan You may then do something like this

```auto
exten => s,1,Answer
exten => s,n,Set(result=${SHELL(test -f /etc/asterisk/list.txt && echo -n 1 || echo -n 0)})
exten => s,n,GotoIf($[${result}=1]?play:continue)
exten => s,n(play),Set(foo=${FILE(/etc/asterisk/list.txt)})
exten => s,n,MSet(x=$[0])
exten => s,n(next),GotoIf($[${x}<${FIELDQTY(foo,\;)}]?playfile:continue)
exten => s,n(payfile),Playback(${CUT(foo,;,$[${x}+1])})
exten => s,n,MSet(x=$[${x}+1])
exten => s,n,Goto(next)
exten => s,n(continue),Playback(tt-weasels)
exten => s,n,Hangup
```

---

<div class="post-metadata">

**Author:** ![scorch](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/scorch/32/292_2.png) [@scorch](https://community.asterisk.org/u/scorch)\
**Post date:** [September 10, 2013, 5:58am UTC](https://community.asterisk.org/t/dialplan-read-rows-from-textfile-then-continue/43860/3 "2013-09-10T05:58:11Z")

</div>

Hi thanks for the reply.  
Will try your second alternative

---

<div class="post-metadata">

**Author:** ![scorch](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/scorch/32/292_2.png) [@scorch](https://community.asterisk.org/u/scorch)\
**Post date:** [September 13, 2013, 2:46pm UTC](https://community.asterisk.org/t/dialplan-read-rows-from-textfile-then-continue/43860/4 "2013-09-13T14:46:16Z")

</div>

[quote=“abw1oim”]This way it won’t work.

But the good news comes here:

You may reach Your goal by using AGI which than just interprets the content from Your webservice and does the things You want it to do (eg Playbacks).

Another approach may be the following:  
Let the webpage store the result of the checkboxes in one line each checkbox-value separated from each other by a specific character. To stay in Your exmaple this may be:

```auto

```

(No carriage return / line feed at the end of the list!)  
We assume for the code snippet the filename of this file to be /etc/asterisk/list.txt.

In Your dialplan You may then do something like this

`
exten => s,1,Answer
exten => s,n,Set(result=${SHELL(test -f /etc/asterisk/list.txt && echo -n 1 || echo -n 0)})
exten => s,n,GotoIf($[${result}=1]?play:continue)
exten => s,n(play),Set(foo=${FILE(/etc/asterisk/list.txt)})
exten => s,n,MSet(x=$[0])
exten => s,n(next),GotoIf($[${x}<${FIELDQTY(foo,\;)}]?playfile:continue)
exten => s,n(payfile),Playback(${CUT(foo,;,$[${x}+1])})
exten => s,n,MSet(x=$[${x}+1])
exten => s,n,Goto(next)
exten => s,n(continue),Playback(tt-weasels)
exten => s,n,Hangup
`[/quote]

Hi!

Tested it and it works! Just had to add a \ before the delimiter in cut  
exten =\> s,n(payfile),Playback(${CUT(foo,;,$[${x}+1])})  
instead of  
exten =\> s,n(payfile),Playback(${CUT(foo,;,$[${x}+1])})

Thanks for the help!
