Running php or bash script in dialplan + push notification

mdriaz

New Member
Feb 11, 2024
19
0
1
25
I am in the local_extension dialplan, i wanted to run a script when any incoming call, however i am unable to execute anything.

tried many things like
action set result=${system(`/bin/echo 'System API Test'`)}
action set result=${usr/bin/php /path/bash.php}
 
and i want to run the script on every extension call, no matter call come from ring group, ext to ext or from call center module, if an invite is send to an extension, i want to execute a script, which dialplan should i target?
 
It will probbaly be something like this
Code:
action set result=${system(usr/bin/php /path/bash.php)}
I didn't test this myself but I'm pretty sure you need system to execute php scripts

You may have to play with the INLINE option, too.

However, Lua scripts integrate seamlessly with Diaplan, and you can likely achieve the same functionality in Lua as you are currently attempting with PHP.

Code:
<action application="lua" data="lua/wakeup_service.lua"/>

The above code is tested and works
 
lua script worked, i used lua to get session variable and execute php file,
but the main issue remains which dialplan to target for incoming call to extension,

there are many ways an incoming call will be going to extension, from ringgroup, ivr, callcenter or direct,
but i could find a dialplan to implement this incoming call trigger for push notification to mobile clients.

local_extension dialplan only executes when ext 2 ext call like from 101 to 102 calls.
 
@mdriaz This is correct. When it rings through the ring group or another similar dialplan, it will not execute the local_extension dialplan. I think you need to look into Freeswitch events. You will probably be able to catch an event where a particular extension rings and then execute your script.
 
  • Like
Reactions: mdriaz
So, I suppose when an incoming call arrives for an extension, i send a push notification to that device to reregister the extension, but how the call invite will be there again, like setting fail_on_single_reject=false should retry that extension until reject right?
 
Sounds like you are building an app. I've never done it, but from the perspective of using apps, I know that the push server is always registered even when the app is closed, and as far as FreeSwitch is concerned, it thinks the extension is online. Your push server then needs to wake up the app and send a call to it.
 
  • Like
Reactions: mdriaz
Sounds like you are building an app. I've never done it, but from the perspective of using apps, I know that the push server is always registered even when the app is closed, and as far as FreeSwitch is concerned, it thinks the extension is online. Your push server then needs to wake up the app and send a call to it.
The thing is that, I don't plan to use any push server, I want to just hold the call and send a push notifications before continue the call dialplan, but don't know how to do that
 
To be honest, I don't know if there is an answer to this. Maybe someone else knows something about it. It's possible that there is no solution and that's why all push servers exist separately.

However, fail_on_single_reject=false could do the trick if you manage to wake and reregister device and FreeSWITCH will attempt to send an INVITE again before the timeout occurs. You might be onto something here.
 
  • Like
Reactions: mdriaz
To be honest, I don't know if there is an answer to this. Maybe someone else knows something about it. It's possible that there is no solution and that's why all push servers exist separately.

However, fail_on_single_reject=false could do the trick if you manage to wake and reregister device and FreeSWITCH will attempt to send an INVITE again before the timeout occurs. You might be onto something here.
I also found that solution in some threads, but I suspect that fusionpbx does not send invite after sending the first one
 
FusionPBX takes security more seriously than some people realize or might want to admit. FusionPBX has many security improvements over the years and this is one of many.

For this reason, system and bgsystem are default disabled. You can enable it if you want to use it. Just keep in mind the system and bgsystem and other variants are both useful and a security risk.

You will find these in Advanced -> Variables
disable_system_api_commands
disable_system_app_commands

You will need to disable them or turn them off and then restart FreeSWITCH.
 
Last edited:
  • Like
Reactions: mdriaz
Thank you.
I don't mind, it's just that fusionpbx highlights system and bgsystem, but cannot use it.

Hey, can you tell me the https://github.com/sem32/freeswitch-PushNotificator
Config of section "Change your dial-string user's parameter for use endpoint app_wait" ?
I know that each extension has a dial-string field , but what about globally updating.
 
Also if fusionpbx has any alternative for sending push notifications before extension inviting to wake up mobile devices without any other push servers involved.

It is becoming a common nesesary as mobile phone are becoming is popular to receive incoming call.
 
Essentially your options really are to use a paid app that provides their own push service, whitelabel something like Acrobits Cloud Softphone, or use something like Flexisip: https://wiki.linphone.org/xwiki/wiki/public/view/Flexisip/HOWTOs/Push Gateway/

Something in the middle has to register with the phone system, handle the SIP requests, send the necessary push messages to Firebase/APNS/etc, wait for the phone to wake up, then progress with the call.

If you do roll your own, there's also a little administrative overhead and cost of signing up for the developer programs so you can sign the certificates required to register a push service
 
  • Like
Reactions: mdriaz
I think the mod_apn will do the job,

Buts needs proper setup.
I am unable to understand the dial-string part for extensions and how to configure such a way that it triggers when a call is made to an extension, from IVR, ring group or even from call center queue.

Any help from @markjcrane is appreciated.
 
If you need to modify the default dial string, it's in Default Settings and then Domain -> Dial String. You can override it on each extension under advanced, so something like this *might* work:

{sip_invite_domain=${domain_name},leg_timeout=${call_timeout},presence_id=${dialed_user}@${dialed_domain}}${sofia_contact(*/${dialed_user}@${dialed_domain}:_:apn_wait/${dialed_user}@${dialed_domain})}

I doubt anything will work though. As that module appears to be for people developing their own iOS application. I highly doubt any available application will be sending those custom contact params as described.

All it is doing is taking the custom contact params you define in your iOS application, storing them in the FreeSWITCH core database, then doing a POST to the defined route, for iOS something like: 'https://api.development.push.apple.com/3/device/UNIQUETOKENHERE', pausing until you get a response and then continuing with the normal SIP INVITE once a register is received.

You would still need to develop an application using PushKit, use a SIP Library to register and handle the entire SIP process using the custom contact params you pull from the APNS, sign the certificates to allow you to use APNS ($99 a year) and push your app to the App Store.
 
  • Like
Reactions: mdriaz
I have tried that by updating a single extension dial string, but not finding which freeswitch xml file to update for global setup. The module says to update a user.xml file or something like that.

And you are right, all it is doing is sending a post request to any config url that are set which could work like having an API endpoint to receive fcm tokens as parameters and send the push notifications from there.

I am a developer, I already setup an application with sip functionality but only works when app is opened and manually registered. Now the challenge is to wake up using push service.

I have tested it, it sends a post request to my defined url when a call is made extension to extension. But doesn't wait for any registration as I see going into voicemail just 1 sec after the post request and it is not triggering for other extension incoming call like if extension is setup in ring group or in call center queue.

I need the trigger to work for sending a url hit with fcm token, the rest pushkit part could be done from app developer.
 
The only unresolved part is the setup in fusionpbx to trigger a curl hit to my push endpoint just before invite of call, I thinks that is where the dial string comes to play, but not triggering if the extension is in a ring group or is an agent of call center queue.

The app part is not an issue
 
I suspect that when calls are distributed from ring group, the extension dial string is not used and nor any dialplan, what could be the cause