Get the caller number after call is answered

I have a php script that run when call is answered it’s in [macro-blkvm-clr] macro. the php get 3 parms the first param should be the caller number this is my line

exten => s,n,AGI(/var/lib/asterisk/agi-bin/alertcalls.php,${CALLERID(num)},1,${MASTER_CHANNEL(CONNECTEDLINE(num))})

I don’t know why but when it asterisk send the parameter to php it set it to the answered phone. for example ext 300 call to ext 200 and in the log that what I see
Executing [s@macro-blkvm-clr:2] AGI(“PJSIP/200-00000253”, “/var/lib/asterisk/agi-bin/alertcalls.php,200,1,200”) in new stack

why is that. and how can I send the real ext that call (in this case 300)
thks for all helper and sorry for my English I hope I was clear

Macro [macro-blkvm-clr] it is FreePBX dialplan, it is hard to debug FreePBX diaplan, Anyway you can save the caller’s CallerID number in a global variable and pass it as parameter to your macro. But I will suggest you write your own diaplan from scratch or try the FreePBX forum