Trigger a script on every call (in- and outbound)

Hello,

as the topic describes, i want to trigger a script on every call. The goal i want to achieve is to send APNs (push) to my phone app.

Right now i manage this with “Custom Target” and select this in the extension (Busy, No Answer) and call my script with

[push]
exten => s,1,System(/usr/bin/push.php "${CALLERID(num)} ${CALLERID(dnid)} ${CALLERID(all)}")
exten => s,n,Return

in “extensions_custom.conf”.

But while i have to do configure it on every extension, i want it for all extensions for in- and outbound calls, never mind on status of the extension.

Can anybody point me to the right path to configure it?

Thanks i advance.

Thomas

Best way is with a dialplan hook. Hooking for fun and income

Thanx,

will read (and try to understand) it :slight_smile:

Regards
Thomas

Hi @kingarthur

hooking the dialplan seems the right way, but do you (or anybody) know how to solve this:

When my iPhone-App goes to background, it’s derigistered on freepbx. In this case the callers seen “call ended” immediately. So, it seems freepbx means there is no endpoint registered, and quit the call.

I tried to hook the dialplan with this

[default]
exten => _X.,1,Answer() 
exten => _X.,n,AGI(my_script.sh) 
exten => _X.,n,Hangup() 

But the script it’s never called.

Asterisk should not drop an ongoing call because the other party unregisters. REGISTER should only apply to new calls in the reverse direction to the registration. Please provide the full log with protocol debugging on (e.g. pjsip set logger on) demonstrating that Asterisk closes the call in response to the un-REGISTER, and not in response to a BYE, or session timer or RTP timeout.

Hi @david55

thanks for reply. I tried to investigate as good as i can. With sngrep i can see an INVITE from my extension 15 to 7 (7 is the mobile device). After this i’ll get an TRYING and then a “503 Service unavailable” back to ext. 15 (as i wrote “call ended”).

In the Logs i have this:

OPTIONS sip:[email protected]:62166;pn-prid=B0A9AE68135C1882-STRIPPED-DEVICE-ID-BD51D3B2CC6C4BAE045AA00062B:voip;pn-provider=apns.dev;pn-param=ABCD1234.com.company.esilphone.voip;pn-silent=1;pn-timeout=0;pn-msg-str=IM_MSG;pn-call-str=IC_MSG;pn-groupchat-str=GC_MSG;pn-call-snd=notes_of_the_optimistic.caf;pn-msg-snd=msg.caf SIP/2.0	
From: <sip:[email protected]>;tag=22f5c4d8-d182-4a02-9d3f-d9eb793cde5f
To: <sip:[email protected];pn-prid=B0A9AE68135C1882-STRIPPED-DEVICE-ID-BD51D3B2CC6C4BAE045AA00062B:voip;pn-provider=apns.dev;pn-param=ABCD1234.com.company.esilphone.voip;pn-silent=1;pn-timeout=0;pn-msg-str=IM_MSG;pn-call-str=IC_MSG;pn-groupchat-str=GC_MSG;pn-call-snd=notes_of_the_optimistic.caf;pn-msg-snd=msg.caf>

I don’t know what asterisk is trying here every 2 seconds. But what i see is, asterisk knows my App (com.company.esilphone.voip : esilphone is the name of the App) and has a knowledge about the device token of my App

B0A9AE68135C1882-STRIPPED-DEVICE-ID-BD51D3B2CC6C4BAE045AA00062B

also it seems that asterisk knows what to do with this device:

pn-provider=apns.dev

apns = ApplePushNotificationService

Both, device token and apns.dev comes from linphone sdk which handles the registering to push.

I don’t if it’s relevant to this topic, but the question is why the caller gets a “Service unavailable” ?

BTW: My script i told about above is running now.

Regards
Thomas

The mobile has aborted the call, independently of any un-REGISTER. That’s not within Asterisk’s control.

The call is unanswered, at this stage, so I wouldn’t describe it as having started. When I talked about BYE, I was assuming it had started. (been answered).

As I think all apps have to be approved by Apple, and have to come from their store, the app implementor may have no choice other than abort the call set up, without violating the conditions for being available through their store. However, I’m an Android user and haven’t investigate Apple’s rules for apps in their store.

What is the callee doing that is causing the app to go into the background during an incoming call set up?

Asterisk has no implementation of push services or knowledge of it. Those can be in the Contact header, but Asterisk won’t do a thing with them itself. They’ll just get sent to whatever Asterisk is sending the SIP request to.

Hi @david55

As I think all apps have to be approved by Apple, and have to come from their store

If you are in development stage it should work.

The mobile has aborted the call, independently of any un-REGISTER

In the beginning it was my fault, because i did an unregister when the App goes in background mode, but i’d change it.

What is the callee doing that is causing the app to go into the background during an incoming call set up?

It’s like the normal telephony app, it’s not always in foreground. It’s a normal state for a telephony app, i guess :wink:

Hi @jcolp

Asterisk has no implementation of push services or knowledge of it

Yes, i know. Thats why i have a script that triggers a push via APNS to the mobile on an incoming call. But because of “Service unavailable” immediately there is no chance to bring that call up.

I will check the peers after a time my App goes in background. There must be a reason why it’s not registered anymore or, like @david55 guessed, the mobile cancel the call.

Regards

Thomas

I just investigate it a bit, and it seems because of app backgrounding the connection to asterisk is gone after a short time. Seems for me normal, because of battery drain. Here is the state of the peer:

To establish a call i have to send a push notification to the phone (type: voip). If i do so, my peer becomes available again, but it will not work as long asterisk shows the extension is not available for the caller…

Am i right so far?