Originate call from php and play sound and return

I have the following scenario: I used the alarmreceiver module to get the messages from my alarm system, it works great, it calls a php file and saves the event to mysql. I want that if there is an alarm, call multiple external numbers ans play a sound after hang up the phone and calls the second number etc. I successfully called a number and played a sound with callfiles, but how can I know when the call is finished and call the second number? I also defined the waitTime which works great, but I also need to know that the call was answered. IS there any solution for this?

This was also asked on Originate call from php, play sounds, and receive dtmf - Development - FreePBX Community Forums and received some replies there, but, as I don’t know the constraints imposed on the design, by FreePBX, I’ll take it here.

Do you mean the alarm receiver application?

It’s not clear to me whether your multiple numbers refers to the two stages of call (ring first number, and send tone, then ring second number) or whether multiple numbers are being called in the first stage. Also, in the second case, it isn’t clear whether success is getting through to one number, or getting through to another.

In any case, if you want to originate a call dependent on the success of a preceding call, you will need to include code in the dialplan for the first call to originate the second call, either with originate or by creating a call file.

I suppose, as no through connections are ever made, you could also originate from a dummy channel (Local to wait application, say, and have the dialplan dial the first number and use a post answer subroutine to confirm to confirm the answer and do the tone handshake, then arrange the dialplan to fall through (e.g. g option on Dial) to calling the second number, or looping round, based on the normal fall through for failed Dials.

I tried to manage it with dialplan, but I cannot, because I don’t know how. I need the following: from php code I originate a call to an outbound number from example 1234567 if the call was answered play a sound with playback, and call the second number, if answer play sound etc. If there was no answer in x time step forward to the next number, but I need to know in the php code that the call failed with no answer.
My idea was to create a context, place the call with a callfile with that cotext, and in the context call an agi script(php) with parameter and this file originates the second call(recursion).
Something like this:
exten => s,1,Goto(s-${DIALSTATUS},1)
exten => s-ANSWER,1,Wait(1)
exten => s-ANSWER,n,Playback(hello-world)
exten => s-ANSWER,n,AGI(call.php, success)
exten => s-ANSWER,n,Hangup
exten => s-NOANSWER,1,AGI(call.php, fail)

I think you are really asking for a full analysis and design job, which isn’t what you will get on a forum like this. You an really only get research hints.

In particular, I think there is a significant amount of analysis work needed here to really understand the details of the requirements, and the constraints on implementation techniques.

Although my normal position on ARI is that it is often used for the wrong reasons and makes things difficult to support, if you really require tight synchronization with your PHP code, this might be a case where it is the best solution.

Okay, I successfully created the contexts, it works now. But I have another problem. I need to execute a long run php script from the context, but until the script runs the call is not hang up. Now I have this in that context:
exten => s,1,NoOp(Pager hang lejátszása)
exten => s,n,Wait(1)
exten => s,n,Playback(${HANG})
exten => s,n,AGI(/var/www/html/teszt/call.php,siker)
exten => s,n,Hangup
Is there any method to run the script in background or to execute it after hangup?

See the Note box in Asterisk 18 Application_AGI - Asterisk Project - Asterisk Project Wiki

Note running for extended periods in the h extension will stop the technology specific channel data structure from being destroyed and you will get periodic warnings about trying to destroy with the owner in place.

In principle fork the process and close the standard file descriptors in the fork. You might need to to fully detach with setsid, but probably not. I haven’t done this myself.

Does your script need to interact with Asterisk or could it be a shell script with parameters on the command line?

If not, maybe like:

system(do-long-thing --cid=x --call-status=${DIALSTATUS} &)

would suffice.

You can put hangup handle in dialplan.

When call hangup, you push update to your database , your script know that 1st call hangup, it will make new call

I tried it with sytem() and it also paused the dialplan for the execution, does the & does something at the end?

The & puts the script into the background.

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