Determining if call went to voice mail

Is there a way to determine whether a call went to voicemail from within a hangup handler?

https://wiki.asterisk.org/wiki/display/AST/Hangup+Handlers

(Searching has turned up nothing. Not surprising as I don’t know what terms to search “for” :wink:

The first few lines of [email protected] looks like this:

exten => vmx,1,Set(MEXTEN=${ARG1})
exten => vmx,n,Set(MMODE=${ARG2})
exten => vmx,n,Set(RETVM=${ARG3})

Checking the value of the channel variable ${MEXTEN} looks like it might be a good way to check. I have not done any testing, so you want to make sure this variable is set under all conditions. Also this variable will be set regardless of whether a message is left or not.

Thanks for the response. I checked and the value is blank. Are those variables supposed to be accessible from outside the hang-up handler context? I thought they were some sort of context “local” variable (for lack of a better term).

VERBOSE[26270][C-0000051d] pbx.c: -- Executing [[email protected]:5] Verbose("xxxxx", "3, MEXTEN=") in new stack
[2014-05-21 13:49:43] VERBOSE[26270][C-0000051d] app_verbose.c: -- MEXTEN=

from outside the hang-up handler context?
Sorry meant to say “from within the hangup handler”.

Not sure what to tell you. I just tested my solution, and confirmed that if a call first goes to voicemail and then to the hangup handler, the MEXTEN channel variable is set. How are you calling the hangup handler?

My setup is a little different, which probably explains it. I’m using FollowMe to redirect incoming calls to an external number. Here’s an overview:

  1. Caller dials into FreePBX. FollowMe attempts to forward the call to an external number
  2. Inside [macro-dialout-trunk-predial-hook] I add a hangup handler:
same => n,Set(CHANNEL(hangup_handler_push)=hangup-handler,s,1)
  1. If the call is not answered, voice mail kicks in
  2. Hangup Handler Fires
  3. Voicemail Process completes

Looking at the logs, the voicemail process seems to start before the hangup handler kicks in, but … seems to continue on after the handler has finished. Not sure if that’s what’s supposed to happen here …

....
VERBOSE[16967][C-0000051c] pbx.c: -- Executing [[email protected]:2] VoiceMail("SIP/fpbx-xxxxxxxx", "[email protected],u") in new stack
VERBOSE[16971][C-0000051c] pbx.c: -- Executing [[email protected]:8] Return("Local/[email protected];2", "") in new stack
VERBOSE[16971][C-0000051c] app_stack.c: == Spawn extension (from-internal, h, 1) exited non-zero on 'Local/[email protected];2'
...
VERBOSE[16967][C-0000051c] app_voicemail.c: -- Recording the message

Yeah, I think it’s definitely the FollowMe stuff. It creates a separate Local channel for the outgoing call. I think that’s why I can’t read the variable, because it was created on a different channel.

I think you are probably correct. I think the solution is to call the hangup handler before the follow me channel is set up.

Not sure I follow you. Are you suggesting I attach the hangup handler to the original channel, rather than the Local channel created by FollowMe? Where would that be done? Currently, I’m using [macro-dialout-trunk-predial-hook] in extensions_custom.conf to add a handler for outgoing calls, but obviously that won’t work for incoming.

Incoming calls that arrive on any of the traditional trunk contexts can be caught with the context [from-pstn-custom]. However, if it was me and if this hangup handler is only meant to check vm status, I might be tempted to alter the [macro-vm] context slightly by copying the relevant section from extensions_additional.conf and adding lines to /etc/asterisk/extensions_override_freepbx.conf like this:

[macro-vm]
include => macro-vm-custom
exten => s,1,Macro(user-callerid,SKIPTTL)
exten => s,n,noop(entering [macro-vm] override context defined in /etc/asterisk/extensions_override_freepbx.conf)
exten => s,n,Set(CHANNEL(hangup_handler_push)=hangup-handler,s,1)
exten => s,n,Set(VMGAIN=${IF($[“foo${VM_GAIN}”!=“foo”]?“g(${VM_GAIN})”: )})
exten => s,n,Macro(blkvm-check,)
exten => s,n,GotoIf($["${GOSUB_RETVAL}" != “TRUE”]?vmx,1)
exten => s,n,Hangup

This above is a bit of a hack because there is always the possibility that it will conflict with some future update. I always add a noop line when using override because a year from now if funny things happen, it is easy to forget it is there.

Great. I was doing some more research after I posted, and just read about [from-pstn-custom]. I tried it out and it works perfectly.

I have to run out, but for my own edification I’ll give macro-vm-custom a try too. (Understood about the caveats).

Thanks a lot for your help!