Asterisk AMI didn't send callerID in the first call

I am using the Asterisk AMI to make 2 external calls using the same sip trunk, the problem is that in the first call the callerID didn’t was fixed, show a different number that I don’t know what is from.

For the second call the callerID it’s correct and it’s showing how I need.

I tried many things to correct that, last option how can say in the bold and italic line I made the Set of the variable CALLERID(num) but it’s didn’t work.

Contexts:
[clickoutcontext]
exten => _X.,1,NoOp(“Click In Context”)
> exten => _X.,n,Set(CALLERID(number)=1148369238)
exten => _X.,n,SIPAddHeader(Call-Info: sip:170.x.x.x;answer-after=0)
exten => _X.,n,Dial({OUT_2}/{EXTEN})

[clickincontext]
exten => _X.,1,NoOp(“Click Out Context”)
exten => _X.,n,SIPRemoveHeader(Call-Info)
exten => _X.,n,MixMonitor(/var/spool/asterisk/monitor/{varName}".gsm",b} exten => _X.,n,Dial({OUT_2}/${EXTEN})

The variable ${OUT_2} = my sip trunk that correspond “SIP/1010” and have a callerID already defined. The question is why in the second call send the callerId and in the first didn’t send.

This is the AMI settings:

$strChannel = 'local/'.$_REQUEST['telefone']."@clickoutcontext";

fputs($oSocket, "Action: login\r\n");
fputs($oSocket, "Events: off\r\n");
fputs($oSocket, "Username: $strUser\r\n");
fputs($oSocket, "Secret: $strSecret\r\n\r\n");
fputs($oSocket, "Action: originate\r\n");
fputs($oSocket, "Channel: $strChannel\r\n");
fputs($oSocket, "WaitTime: $strWaitTime\r\n");
fputs($oSocket, "CallerId: $strCallerId\r\n");
fputs($oSocket, "Exten: $customerNumber\r\n");
fputs($oSocket, "Context: $strContext\r\n");
fputs($oSocket, "Variable: varName=$filename\r\n");
fputs($oSocket, "Priority: $strPriority\r\n\r\n");
fputs($oSocket, "Action: Logoff\r\n\r\n");

I use the Local context to it work well with external number.

Asterisk version 11.25.3

There are several items of concern:

  • That is an older version of Asterisk (current is 16).
  • Parts of your posted dialplan are missing $ and contain odd " character placements.
  • The _X. pattern might catch dirty user data like 1234&Local/5551234@clickoutcontext which could result in unauthorized calling - please look into the FILTER dialplan function to sanitize your data and clean up the pattern.
sEXTEN=${FILTER(0-9,${EXTEN:0:10})}
  • You appear to be accessing AMI directly and not through an existing library.
    There are several libraries available which might help you to avoid re-inventing the wheel. Typically these libraries treat the events in a more atomic fashion:
    • Login.
    • Go back to event loop to read result of Login.
    • Originate.
    • Go back to event loop to read result of Originate.
    • Logout.
  • Maybe your carrier - or their upstream carrier - is doing things with the Caller ID number based on the destination. You could test this by spooling several calls to the same number and seeing if there is any lack of consistency in presentation, or if it is always the same Caller ID for the same destination.

Hi penguinpbx, thanks for your answer.

About your commentary with the pattern _X. the 2 contexts are created only for this feature, because it the _X. is not a problem.

In reference the libraries i will study its, thank for the informations and the link.

And about the last commentary my carrier is ok, the problem is not them because I made many tests with that.

Regards
Leandro