Generate Call PHP sending to the wrong context

Hello,

I have a problem with my dialplan. I`m guessing that the PHP its not sending to the right context. When i use it with the US phone number, it generate calls to US, EU and AUS. But when i change the SIP with the number from AUS, it sends in US, but in Australia it gives me an error.

– PJSIP/signalwire-00000000 is making progress
– PJSIP/signalwire-00000000 answered
[Nov 28 04:34:10] WARNING[2220][C-00000001]: pbx.c:4510 __ast_pbx_run: Channel ‘PJSIP/signalwire-00000000’ sent to invalid extension but no invalid handler: context,exten,priority=ivrsystem,+61730406348,1
[Nov 28 04:34:10] NOTICE[2220][C-00000001]: pbx_spool.c:463 attempt_thread: Call completed to PJSIP/+61730406348@signalwire
[Nov 28 04:40:47] NOTICE[2338]: res_pjsip/pjsip_distributor.c:676 log_failed_request: Request ‘INVITE’ from ‘sip:1000001001620224100:5060@162.0.224.100’ failed for ‘89.163.241.34:56435’ (callid: 1804508809-368541849-1353322689) - No matching endpoint found

Who made the PHP made it for USA, but i`m trying to call AUS and Europa.
When i call from US number, it takes the dialplan perfectly.

I will upload the PHP here, maybe someone can help me fix it. I would appreciate it.

Thank you.

<?php $handle = fopen("./leads.txt", "r"); $channelname="signalwire"; //$channelname="voiceplus5"; // remove double slash if you want to use voiceplus5 and add double slash infront of above line $nextcallinseconds=10; $callerid="+61280034164"; if ($handle) { while (($buffer = fgets($handle)) !== false) { $phonenumber = rtrim($buffer); $contents = "Channel: PJSIP/".$phonenumber."@".$channelname."".PHP_EOL."Callerid: ".$callerid.PHP_EOL."MaxRetries: 0".PHP_EOL."RetryTime: 300".PHP_EOL."WaitTime: 18".PHP_EOL."Context:ivrsystem".PHP_EOL."Extension: ".$phonenumber.PHP_EOL."Priority: 1".PHP_EOL; //print_r($txt); $callfile = $phonenumber.".call"; if(!is_file($callfile)){ file_put_contents($callfile, $contents); shell_exec("mv ".$phonenumber.".call /var/spool/asterisk/outgoing/"); echo "--- Calling " .$phonenumber ; echo "\r\n"; sleep($nextcallinseconds); } } if (!feof($handle)) { echo "Error: unexpected fgets() fail\n"; } fclose($handle); } ?>
  1. There is no PHP in Asterisk. Wherever this script came from, that’s a good place to ask.
  2. When you post code snippets, please wrap them in preformatted text tags or as a code block so the forum does not eat all the formatting and special characters.
  3. IIRC, the outgoing leg (channel: PJSIP/…) does not touch the dialplan unless a local channel is used. This PHP script just reads a line from leads.txt, trims trailing spaces, and constructs the channel request for the call file. There is nothing ‘country specific.’
  4. A console log (with debug and verbosity bumped up, wrapped in preformatted text tags), may be clueful.

Looking at the console log fragment you included shows Asterisk tried to send the call to ‘ivrsystem,+61730406348,1’ but it does not exist and there is no ‘i’ extension in the context.

Entering ‘dialplan show +61730406348@ivrsystem’ may yield clues.

Code wrapped as preformatted text (but you should have edited your original posting, yourself):

<?php
$handle = fopen("./leads.txt", "r");

$channelname="signalwire";
//$channelname="voiceplus5";   // remove double slash if you want to use voiceplus5 and add double slash infront of above line
$nextcallinseconds=10;
$callerid="+61280034164";


if ($handle) {
    while (($buffer = fgets($handle)) !== false) {
        $phonenumber = rtrim($buffer);
        $contents = "Channel: PJSIP/".$phonenumber."@".$channelname."".PHP_EOL."Callerid: ".$callerid.PHP_EOL."MaxRetries: 0".PHP_EOL."RetryTime: 300".PHP_EOL."WaitTime: 18".PHP_EOL."Context:ivrsystem".PHP_EOL."Extension: ".$phonenumber.PHP_EOL."Priority: 1".PHP_EOL;
//print_r($txt);
        $callfile = $phonenumber.".call";
        if(!is_file($callfile)){
         file_put_contents($callfile, $contents);
         shell_exec("mv ".$phonenumber.".call    /var/spool/asterisk/outgoing/");
         echo "--- Calling  " .$phonenumber ;
         echo "\r\n";
         sleep($nextcallinseconds);
}

}
    if (!feof($handle)) {
        echo "Error: unexpected fgets() fail\n";
    }
    fclose($handle);
}
?>
1 Like

The PHP sends the call to the context ivrsystem, which is hard coded. Whether that is sensible or not is impossible to tell without your specific dialplan.

I am sorry, but i am a newbie in both php and asterisk. that is why i`m trying to educate myself. A lot of trial and error.

I`m sorry David, but like i said, a newbie here. I barely can hold my PHP and asterisk, but learning something new everyday.

Did this yield any clues?

How about ‘dialplan show ivrsystem’?

Not every provider (or country) will allow you to set the caller ID.

it said that there is no dialplan ivrsystem. If i delete the callerid ? maybe that will work?

The first question is where should the calls go? The dialplan and the PHP have to agree :slight_smile:

Is ‘ivrsystem’ correct? Why isn’t ivrsystem present?

dialplan show

will show you your entire dialplan. Maybe there are some clues there.

My main issue is that on the US incoming, php on outgoing works great, takes the dialplan perfectly. On AU only incoming, when i try to php calls, it says that no invalid extension but no invalid handler, so i`m thinking the SIP or php should be the problem, since it works on US.

Also, i should`ve mentioned, its an IVR system, so…survey type

I don’t understand this. The PHP script creates call files that originate outbound calls. What does incoming calls have to do with this?

I suspect most of your problems are in your dialplan. You say the ivrsystem context does not exist. Doesn’t that need to be resolved first?

Once you get the context correct, you’ll have to have extension patterns to handle the number formats used in leads.txt. Wildcard pattern matching may prove key here.

1 Like

The PHP script assumes you do have an ivrsystem context. The lack of ivrsystem is nothing to do with the caller ID. If you don’t have an ivrsystem context, the PHP isn’t going to work for any country.

Im sorry, like i said, im new to this.
I can only provide the details. And i will. The php is the one already listed. The Dial plan Looks like this :

[ivrsystem]
exten => _X.,1,Answer
exten => _X.,n,Background(ivr/choice_1)
exten => _X.,n,WaitExten(30)
exten => _X.,n,Goto(s,1)
exten => 1,1,Noop(user pressed 1)
exten => 1,n,Playback(ivr/welcome)
exten => 1,n,Set(phone=${CALLERID(num)})
exten => 1,n,NoOp(Promo pin received in the email)
exten => 1,n,Read(promopin,ivr/promopin,8,8,7)
exten => 1,n,Set($[LEN(${promopin}) != ]?69:8)
exten => 1,n,Playback(ivr/thank_you)
exten => 1,n,Hangup()
exten => 2,1,Noop(user pressed 2)
exten => 2,n,Playback(ivr/choice_2)
exten => 2,n,Hangup()

And on the Extensions i have the redirect to IVR text :

[from-signalwire]
exten => s,1,Goto(ivrsystem,${CALLERID(num):1},1)
exten => s,2,Hangup()
exten => X.,1,Goto(ivrsystem,${CALLERID(num):1},1)
exten => X.,2,Hangup()
#include ivrsystem.conf

My main issue is this : With the US phone number, incoming, outgoing on US numbers works great, the dialplan connects, on the incoming from Australian numbers, the dialplan connects, only the outgoing from the US number to an Australian number gives me the error that the context is wrong.

if anyone can figure it out, I dont understand why.

Hi Kathy,

With error message:
"
‘PJSIP/signalwire-00000000’ sent to invalid extension but no invalid handler: context,exten,priority=ivrsystem,+61730406348,1
"

I see that problem is your context “ivrsystem” not process extensions like “+…”

so you should change as below and it will work
exten => _X.,
to
exten => _. ,

Note that context match “any” maybe have security risk

What I’m not seeing is the part of the dialplan that actually calls the PHP script.

Calls come in…and I assume they’re sent to the [from-signalwire] context. Okay…except if they’re being sent directly to the [from-signalwire] context then that should fail right there since you don’t have a valid pattern match to accept any number. That X. should be _X.. But maybe that’s neither here or there.

What the PHP script is doing doesn’t make sense. It looks like it’s generating a call file. This is the point where I get confused.

It’s generating a call using PJSIP/phonenumber@signalwire…which…okay…maybe there’s something signalwire is doing that it uses dynamic resource naming this way.

It specifies a caller ID, MaxRetries, RetryTime, and a wait time.

What I don’t understand is why is it then sending that to ivrsystem,phonenumber,1 - a valid match for that, according to your dialplan, plays ivr/choice_1 while waiting for user input for 30 seconds.

There’s a part of this I feel like we’re not seeing. As it stands…I don’t know how any of this could work. If the goal is to place a call to a number…then there’s no place I see this occuring.

That being said…I have to wonder if the error you’re seeing is somehow related to the fact it’s trying to call an extension that starts with a +.

Maybe change the _X. in [ivrsystem] to _+X.?

After that the Goto(s,1) makes no sense; there’s no s extension in [ivrsystem].

1 Like

That would really confuse it since there are single digit extensions. It would pretty much always match the _. pattern for any entry.

This is bad practice, as it matches various special values, which can legitimately arise during a call. In particular h and i.

I’d also note that this dialplan throws away the called number, so it is not clear what purpose there is in including it in the PHP script, rather than say s.

Also, it looks as though it was originally written to have s, rather than X., as it now goes to an undefined extension (s), when I think the intent was to go back to the start. (. will match s, so if that was the intention, that change will fix that part.)

1 Like

`_+X. This was the answer, in the dialplan. Thank you all for all the information you provided. I learn something everyday.

Hope you have a great day !!!