Voice directory dialplan

Hi, I’ve been setting up a dialplan which can store a voice directory. It essentially works as follows

use keys 2-9 then confirms which letter eh. 2 = a,b, or c
they then key the number eg. 0778128445321
they then record the persons name

I have a folder which has
B-0778128445321.gsm and so in it, one voice file for each phonebook entry

I’ve got that side of it working, I now want Asterisk to be able to playback (background) all the files beginning with the selected letter until the use presses a digit to confirm.

My question is can I get Asterisk to iterate through the sound files using a match such as B-*.gsm

Many thanks,

Mark

No. But you could use the shell to do so, and then parse the resulting string. (There may be string length limits.)

You can use AGI-BIN and your favourite scripting language to do that and much more.

thanks for the suggestions.

So if I did something like

ls V-* -1 > vfiles.txt

How do I get Asterisk to execute the script, and then read the file vfiles.txt in a loop within asterisk?

Mark

To execute it, run core show applications and look for the obvious one.

To read back in a loop, you will, in practice, need to use AGI (in which case you could shell from that). There should be a whole chapter, and Appendix, on AGI, at ateriskdocs.org/

In my view, though, AGI is often used when not needed. If the list is not too long, I would run core show functions and look for something that might return the complete list in a form in which you could assign it to a variable, and then look for one that could extract a delimited field from a string.

Solved it, here is the dialplan code so far:

[directory-lookup]
exten => s,1,Verbose(1,Want to list files in ${BOOK})
; set some initial values
exten => s,2,Set(x=1)
exten => s,3,Set(file=a)
; execute the shell command to list the files
exten => s,n,Set(result=${SHELL(echo ${BOOK}*)})
exten => s,n,NoOp(result from shell is = ${result})

; replace hyphen with an _ for now
exten => s,n,Set(tmp=${REPLACE(result,-,)})
; now filter out anything we don’t want like the path and silly cr/lf
; I only allow numbers, cap letters, dots and underscores
exten => s,n,Set(tmp2=${FILTER(0-9A-Z.
,${tmp})})
; now replace the _ with a - to put it back (I couldn’t figure to filter the -)
exten => s,n,Set(tmp3=${REPLACE(tmp2,_,-)})
; we will now use tmp3 to get each filename which should be delimited with a .
exten => s,n,NoOp(tmp3 = ${tmp3})
exten => s,n,Answer()

exten => s,n(loop),Set(file=${CUT(tmp3,".",${x})})
exten => s,n,NoOp(file is “${file}” and x is ${x})
exten => s,n,Set(x=$[${x}+1])
exten => s,n,Set(tmp=book/${file})
exten => s,n,NoOp(tmp = ${tmp})
exten => s,n,Playback(${tmp})
exten => s,n,GotoIf($["${file}" != “”]?loop)
exten => s,n,Hangup()

If anybody wants my dialplan for storing the number and then selecting the number please PM me (well leave it a few days because it’s not quite finished yet)