How to get queue agent's channel name when using local channels

I use local channels with queues in Asterisk 16. I have a need to get the channel name of the PJSIP extension that answered the call from the queue in my dial plan, NOT the local channel name.

Using the ${CHANNEL} var after the agent answers I get something like:

What I want is something like this:

Is there is variable I can use to get the actual PJSIP channel name like PJSIP/305-0003c4cf ??

Thanks in advance for any help, I have googled my head off but no luck.

I need this channel name so I can do an Attended Transfer using the AMI.

This command:
pjsip show channels

Assuming that the call has actually been set up to the PJSIP endpoint, you can use IMPORT() and the BRIDGEPEER variable, commbined with some text manipulation to derive the name of the ;2 side of the local channel.

can you describe your use case
as there are several different ways you can do this

one way is on the original channel so a Set(__ORG_CHANNEL=${CHANNEL})
and then on the last Dial(PJSIP/XXX,b(Dial_Handler^${EXTEN}^1))

I have a queue that dials the agent using local channels. I can get local channels no problem, I can’t remember how I’m getting both sides but I’m getting one side of the local channel with the ${CHANNEL} var by firing a Sub when the agent answers, something like this.

My call to the queue:
exten => s,n,Queue(Queue4,subVtasMemberMacro)

The line above fires the subVtasMemberMacro shown below when one of the agents answers the call.

;This runs when agent answers call from queue
exten => s,1,NoOp(${CHANNEL})
exten => s,n,AGI(queuecalls.php,AgentAnswered,${CHANNEL})
exten => s,n,Return

I use this AGI to do some logging, including knowing which agent handled this particular call. I also use it to send details to my web application so I can do other things like put the call on hold from the web app etc, in order to do that I need to know the channel once it’s answered by the operator etc…

I need to now know what the agent channel is that looks more like PJSIP/305-0003c4cf instead of the channels that look like this Local/305@agent-ext-0003c7d9;1 or Local/305@agent-ext-0003c7d9;2.

I need the PJSIP/305-0003c4cf style channel because this seems to be the one I need in order to do an attended transfer AttXfer initiated by a button on my web application using the AMI. Right now, I’m doing a blind transfer only using what I get from the ${CHANNEL} var. Trying to do an attended transfer using that same channel var doesn’t work, it only works when I transfer the PJSIP/305-0003c4cf style variable.

I guess I was hoping there would be some other handy variable like ${CHANNEL} to access the channel name I need for attended transfer so I can grab it in the same Sub (which is where I need to grab it).

Thanks for any additional help you can provide, this has been a thorn in my side for literally 10 years or more. I need to get this attended transfer working and I’m super close.

If I show my channels at the command line, find the correct channel, then plug it in manually to a test form, my attended transfer works fine, obviously this won’t work in production.

The forum software removed a bunch of commas in the call to the queue in my last post but, you get the idea I think.

same => n,Set(__QueueCall=b(subVtasMemberMacro^s^1))
same => n,Queue(QueueName)

exten => _X!,Dial(${EXTEN},,${QueueCall})

Thank you for your response. I played with this a bit but didn’t have any luck.

I don’t completely understand all of it. I see that on the first line you are setting a variable with inheritance but I don’t know what it is exactly that you’re setting. Don’t understand what the b, the parens or the reference to the sub is for. I am also not familiar with using the ^symbols but I’m guessing this is just referencing the first line of the Sub. Again though, I don’t understand what’s happening here as the variable is being set. I think if I understood that I would understand what to do with it later.

I need the channel name inside the subVTASMemberMacro so I can send it into the AGI there. Hitting the AGI inside that sub is the sole reason I hit that sub. I hit the AGI for various reasons but mostly for things like logging which operator answered the call etc.

I see that you are recommending that I send the variable after it’s created within the dial command. I haven’t done that before so I will dig in a little more to the dial command as to how I can send a variable with the dial command but, honestly I don’t need it in the dial command I need it when I fire the subVTASMemberMacro as mentioned above.

Thanks again for your responses and Happy New Year.

He has syntax errors, in that he has put an option where the timeout should be (this is one of the reasons I don’t like giving worked examples; I may get them wrong). Also, the use of the ! form of patterns is not a good idea here. However, b is intended to be an option on Dial, which has the effect of running the named subroutine immediately after the outgoing channel structure has been created, but before anything has been done with it.

Note that this subroutine, even though you have, confusingly, included Macro in the name.

I assume there is an unstated reason why all the processing can’t be done with hard coded dialplan, on the local channel, in which case this approach may well not work, or may involve passing extra variables.

Yeah, the Sub name has the word Macro in it because before I moved to a newer version of Asterisk, Macros were all I had to work with :slight_smile: I just changed the names by adding sub in front when I converted them from Macros to subs, bad choice maybe.

I’m not sure I completely understand all of your response just yet but thank you for this and your previous responses. I’m going to look it all over and do some testing based on your answers.

I’m certain there is a better way to do all this and I’m always looking to improve.

OK so I think I understand what you are saying and I think I get the idea of what The Mark was trying to say now.

But, with that being said, can’t I just call the sub directly from the dial like this, without having to set it in a variable first, then retrieve it? The Sub name is always the same, it’s not dynamic or anything so I think I can just do something like this? No?

Dial(${EXTEN},b(someSub^s^1)) or something similar?

I’m guessing that I can then have the Sub grab the channel name using ${channel} and feed it into my AGI, solving my issue… ??

I don’t know, I guess I made my explanation confusing but it makes perfect sense in my brain. Please feel free to let me know where I went wrong here or just plain wrecked into a wall and got it all wrong.

Now I’m thinking this just simplifies down to using either b, B or U options on the dial command when I dial the operator using PJSIP/Ext. I’m researching now which of the three options is best suited for my use case. This sort of complicates things a bit because I will have to hit a second AGI to accomplish what I need to but, if this all works out, maybe I can move the other call to the dial command as well instead of calling it from the Queue command.

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