Custom Find Me using Dial() and Gosub via the U option

Hi Everybody,

Using Asterisk 18.x and PJSIP

We’re tweaking our custom Find Me dialplan and are using the U option to handle a simple “Press 1 to accept this call” for the called party.

I’m trying to figure out how to detect if the original channel still exists so as to play a friendly prompt after the called party presses 1 in cases where the caller has hungup.

I got excited when I saw the CHANNEL_EXISTS() function in the docs but it doesn’t appear to actually be in Asterisk any longer.

Any thoughts how to check for the status of another channel from within the dialplan?

Thanks for any insight.

Okay, not sure if this is elegant or terrible, but this is what I came up with:

exten => s,n,ImportVar(TEST=${CHANNEL(linkedid)},UNIQUEID)
exten => s,n,ExecIf($[${LEN(${TEST})}==0]?Playback(caller-hungup))

Thoughts?

I think the incoming channel will only have a soft hangup, so it will still exist. You’d have to check something about the state. Only the thread that currently owns the channel can actually remove it, and that is busy running your subroutine.

llinkedid won’t work in the general case, if the identity isn’t set by Dial, in a special variable, you would need have it copied into an inheritable variable before the Dial. Strictly speaking you should use the unique ID not the channel name, as transfers could change the latter.

Actually, I’m not certain that there is even a soft hangup at that stage. I think there may just be an AST_CONTROL_HANGUP frame stuck in the channel’s incoming queue. In which case you would have to try and identify the technology specific channel information. However there doesn’t seem to be access to the state of that.

Good Morning David!

My snippet works, but you gave me an idea with checking the state, that sounds like a less hackish way of doing it, looking into it now!

Thanks for the suggestion.

I got excited when I saw the CHANNEL_EXISTS() function in the docs but it doesn’t appear to actually be in Asterisk any longer.

What do you mean by this exactly? It was only recently added to Asterisk. You need to be more specific than “Asterisk 18.x”. This function only exists in the last couple minor versions of 16, 18, and 19.

exten => s,n,ImportVar(TEST=${CHANNEL(linkedid)},UNIQUEID)
exten => s,n,ExecIf($[${LEN(${TEST})}==0]?Playback(caller-hungup))

Thoughts?

Yes, don’t do this either. Use the IMPORT function, not ImportVar. ImportVar has long been deprecated and will probably be removed soon (hopefully next year).

It’s 18.7, 18.8 and 18.9 had a bug with queues that caused us some grief so we rolled back and haven’t updated to latest.

That bug has long been fixed (I believe I know which one you’re referring to).

CHANNEL_EXISTS appeared in 18.8, so I recommend you upgrade to the latest LTS, 18.13, which has that queue issue fixed and has the CHANNEL_EXISTS function.

What do you mean by this exactly? It was only recently added to Asterisk. You need to be more specific than “Asterisk 18.x”. This function only exists in the last couple minor versions of 16, 18, and 19.

It’s 18.7, 18.8 and 18.9 had a bug with queues that caused us some grief so we rolled back and haven’t updated to latest.

Roger that! Experimenting with the change now.

Agree and big thanks for the recommendations! I wish it was this easy, we have north of 60 high density asterisk servers and I’m not sure this would be a compelling enough reason but I’ve already started the internal political process to make that happen.

If you can’t risk a big change, you could always apply the patch from Gerrit manually.

Otherwise, I guess you’d have to wait until the next upgrade cycle before being able to use it.

I wrote CHANNEL_EXISTS to make it easier to explicitly see if a specific channel exists or not. Before that, the poor man’s hacky way of doing it was using the CHANNELS function with some convoluted regex that never worked perfectly (I think there was a \b in it), but that might work well enough in the meantime.

The way you’re doing it now works just as well though.

Thanks for all your hard work, it’s very much appreciated :fist:

I have 18.latest on our test servers now, I’m going to build out this update using both IMPORT and CHANNEL_EXISTS and see if I can get us over the hump while we argue endlessly.

I say that half joking, this is a wonderful place to work and everybody is awesome but a little gun shy to stack changes as things have been really stable for a long time.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.