Unclear how to use return values from application calls

Code snippet from my dial plan…

exten => 21,1,Wait,1
exten => 21,2,Dial(Zap/1,20)
exten => 21,n,Wait,1 ; No answer, leave message
exten => 21,n,Playback(BNP/In/Eric/notavail)
exten => 21,n,Record(BNP/In/Eric/inmessage:wav,10,600)
exten => … Do some stuff to process the received voicemail message …

This is basically an implementation of an ULTRA-simple voicemail system that doesn’t use the Voicemail application (because I haven’t gotten around to figuring out the Voicemail application yet). Basically, the “stuff to process the received voicemail message” includes uuencoding it and emailing it as a file attachment to the owner of the voicemail box.

That all works fine IF the caller hits the pound (#) key after leaving the message.

If the caller just hangs up without hitting the # key, none of the post-processing happens.

I know that the Record application returns -1 if the caller hangs up (I guess that means it returns 0 if the caller hits the # key). What I don’t understand, and can’t find, is how to make use of the -1 return to make the dialplan do the normal post-processing of the voicemail message if the caller just hangs up.

I have looked through the sample dialplans and have seen things like…

exten => s,1,Dial(${ARG2},20|p)
exten => s,2,Goto(s-${DIALSTATUS},1)
exten => s-NOANSWER,1,Voicemail(u${ARG1})
exten => s-NOANSWER,2,Goto(default,s,1)
exten => s-BUSY,1,Voicemail(b${ARG1})
exten => s-BUSY,2,Goto(default,s,1)
exten => s-DONTCALL,1,Goto(${ARG3},s,1)
exten => s-TORTURE,1,Goto(${ARG4},s,1)

… where I guess Dial returns DIALSTATUS and one can jump based on that. So, if there were a variable called RECORDSTATUS I suppose I could do something like the above. But, there isn’t, at least not that I can find, so how do I get at that -1 value and do useful things with it?

well, you could set and unset variables as the thing goes along, then use the h extension in that context to check which variables are set, and if they are set in such a way taht suggests they hung up while leaving a message, do the (other stuff)

That said, voicemail() is not hard at all to figure out.

in voicemail.conf make a very simple extension, ignore all the crap at the top. Fill in the email address, and add attach=yes to the line.
then
exten => 21,n,Voicemail(1234@context)

to check it-
exten => whatever,1,VoiceMailMain(@context)

That said, voicemail() is not hard at all to figure out.

Good evening, IronHelix.

I’m certain that it is probably relatively easy.

However, I’m rather on the hook to take a minimally-functional version of this thing live by the close of business tomorrow, and I won’t have time to implement “real” voicemail using Voicemail for probably another week.

Meanwhile, my entire voicemail capability consists of the following:

exten => 101,n,Playback(leavemsg) ; Tell caller to leave a message
exten => 101,n,Record(inmessage:wav,10,600) ; Record message, returns -1 if the caller hangs up
exten => 101,n,System(uuencode inmessage.wav inmessage.wav | mail -s “New Voicemail” recip@email.addr.com)
exten => 101,n,System(mv inmessage.wav inmessage.${TIMESTAMP}.wav)

It records the voicemail message and sends it to the recipient via email, which is all I need to be able to do … I don’t need people to be able to call in and get their voicemail, don’t need to administer passwords, none of that… the only requirement I have is to send peole their voicemails as attached .wav files in an email message.

And, all of that is working great (as of about four hours ago) EXCEPT for the fact that if someone hangs up after recording the message, rather than pressing the # key first, none of the rest of the dialplan works.

So, again, I need to figure out how to handle that minus-1 that Record returns if the caller hangs up. Once I can do that I am golden, and then I can implement Voicemail at my leisure (if in fact I ever need to do that.).

Thanks…

Eric

let’s be frank here … in the time it’s taken you to post this thread, you could have implemented VoiceMail !

but, if you’re going to continue what you have, i’ll requote IronHelix and tell you to look at the ‘h’ extension. once a hangup is rec’d, it’s the only way you can continue with dialplan processing

ok, then the easiest thing to do-
in the context you are in (assuming it does nothing but voicemail), make an ‘h’ extension which first checks to see if the voicemail record file exists, and if it does, do the rest of the stuff to it same as normal.
One major flaw of this system is that you can only leave one voice message at a time for each user as the file name is hardcoded. One way around this would be to first use Set() to set a variable to be something like message-${EXTEN}-${DATETIME}. Then use that variable as the file name later…

If you have figured out this much htis fast, I guarantee you can figure out voicemail in under a day, if not in under an hour. Read voicemail.conf, and at the CLI do show application voicemail. IT IS VERY STRAIGHT FORWARD.
If you setup the user in voicemail.conf with attach=yes and delete=yes, then asterisk will do nothing other than email the guy his message (and then delete it out of his mailbox).
only thing to keep in mind is that voicemail has contexts just like everythign else. use @default for everything (and default context in voicemail.conf) and you will be all set.

baconbuttie wrote:

let’s be frank here … in the time it’s taken you to post this
thread, you could have implemented VoiceMail !

Yeah, probably. :smile:

But, I should probably know how to handle return values from application calls anyway, shouldn’t I?

i’ll requote IronHelix and tell you to look at the ‘h’ extension

IronHelix wrote:

in the context you are in (assuming it does nothing but voicemail),
make an ‘h’ extension which first checks to see if the voicemail
record file exists, and if it does, do the rest of the stuff to it same
as normal.

OK, I can try that. I’ll dig into the docs and the wiki and see if I can figure out what an “h” extension is. But in any case, the record file WILL exist … the caller will record the file and then will usually hang up rather than pressing the # key first. So, taking action based on the presence or absence of the record file won’t work, I don’t think.

One major flaw of this system is that you can only leave one
voice message at a time for each user as the file name is
hardcoded. One way around this would be to first use Set() to
set a variable to be something like message-${EXTEN}-${DATETIME}.

Right, I knew that would be a problem and figured out how to use variables and Set() a couple of hours ago, to get around it.

If you have figured out this much this fast, I guarantee you can
figure out voicemail in under a day, if not in under an hour.

Yeah, I actually started off with this yesterday morning with absolutely ZERO knowledge of Asterisk in particular and not much more knowledge than that about PBXs in general. As of about an hour ago I have a functional PBX that will respond to a voice menu “Press 21 for Eric, press 22 for Bill, pres… (etc.)” and when Eric or Bill don’t answer their extensions. they get the voicemail prompt. It has really been pretty easy. If I can get past this issue, and the other issue I posted about here regarding failure to timeout when dialing an outside number, that’s all I need to make my end-of-tomorrow (actually, by now, “end-of-later-today”) deadline. I can even live without the failure to timeout if I have to (and from what I’m reading in the other thread, it looks like I’ll have to).

I guess I’ll dig into Voicemail later this morning if I can free up the time … although, shouldn’t I still learn how to handle return values from application calls like Record returning minus-1?

IMHO you should know how to use VoiceMail() more than you need to learn how to handle return calls. It is a much more valuable skill and is far easier to learn :smile:

What i meant by check if file exists was assuming you have an entire context dedicated to this voicemail thing, it will run exten ‘h’ if a call is hung up anywhere inside the context (including during the greeting)

so your h exten should:

  1. check if the voicemail file exists (if not, then stop because there is no file to process)
  2. if it does, (optionally) qualify it to make sure it’s above a certain size (to avoid half second hangup voicemails).
  3. do whatever else it was going to do (format, recode, email, etc).

Many thanks to you folks for helping me and encouraging me to get Voicemail running. You were right … I didn’t do it in under an hour :wink: but I did do it in under a day. Voicemail now is able to email .wav files to the recipient which is all I need it to do.

Our new PBX went live about a half hour ago.

Now to move on to the next thing, which is figuring out how to get it to receive faxes… :smile:

Thanks… :smile: