Way to query if an extension is on a call and to what external number

Does anyone know if there’s a way either with AMI or something to programmatically obtain the number that an extension is on the phone with? So basically I want to make a php script where I will pass the parameter as the extension number and for that extension number I want to determine what number that extension is on call with? If that extension is not on the phone to anyone then ofcourse it shouldn’t return anything.

Thank you

I think you can just do this with core show channels in asterisk, I would start there.

hi @johnr,

You can use this bash command to parse your channels:

bash -lc ‘rasterisk -x"core show channels concise"’ | awk -F’!’ ‘{split($1, a, “/”);split(a[2], b, “-”); ext=b[1];split($7, c, “/”);split(c[length(c)], d, “,”); dst=d[1]; printf “extension=%s,destination=%s\n”, ext, dst}’

it will show you this output:

extension=2005,destination=037119000

if you need to show just the extensions, let me know.

Thank you,

Daniel Friedman

Trixton LTD

The extension will not always be the source. Outgoing calls to the extension will list it as the destination.

Hi @BlazeStudios ,

Thank you for your comment, but obviously, you can filter down the extensions you want to present. I shared an example of how he can achieve a list of calling channels.

Thank you,

Daniel Friedman
Trixton LTD