Limit call length based on user's account balance

Hello community!

My Asterisk gets an ARI request to make a call, but I want limit max call length based on account balance of user (user name will be in ARI request).

Need that Asterisk after receive an ARI request but before actually make a call, will go to database, based on user name get his account balance, based on account balance calculate max call length, set max call length for Dial application (by use parameters “S” or “L”) and eventually make a call.

Do not realized where this additional layer (simple billing) should be added. Is this should be in Stasis or in dialplan?

Thanks in advance.

This depends upon what exactly you are doing with ARI. For example, ARI doesn’t have that functionality or access to Dial. It’s up to you to implement. What exactly are you doing with ARI/hoping to achieve with it?

1 Like

We use ARI instead of call files, with purpose call 2 users from asterisk via SIP trunk (multichannel) and let them talk. And for this we use ARI request:

POST /channels?endpoint=PJSIP/user1&exten=user2&context=outgoing

After user1 pick up the phone - bill sec will be started and Asterisk will go to dialplan to context “outgoing” with exten “user2”. But I need also limit call for this user1, while he is waiting user2.

If setup the “S” option in dialplan Dial app, it will be a timeout started after user2 answered and calls placed into bridge. It’s ok for user2, as his billsec started after enter the bridge, but user1 billsec started early and user1 timeout should be somehow started early. How?

I see in cel records that user1’s “ANSWER” event has “AppDial2” in “appname” column, and “Outgoing Line” in “appdata”. Not sure there is a way setup timeout for this app (looks like Asterisk has “AppDial” and “Dial” applications), as you said ARI do not have deal with Dial app.

Regarding “achieve with ARI”. Is it possible some how track maybe via Stasis when answer user1 and user2 and interrupt the call on timeout by another ARI request?

So, rely on 3rd party script for interrupt the call instead of Asterisk Dial() “S”, “L” options.

If you subscribe to the channels then you receive events in regards to what happens with them, and can call hangup on them. If you don’t want to do that but instead use Dial() then you’d need to calculate the value before originating, and pass in such information as dialplan variables.

1 Like

I prefer a way calculate value before originating.

But in this case, if I pass duration as dialplan variable. I can setup timeout started only “ENTER BRIDGE” event, when both participants entered the bridge, correct?

Somehow start timeout started from “ANSWERED” event is possible only by subscribing to the channels?

Thanks in advance.

My comment about dialplan variables was for using Dial() where you don’t have to keep track of anything in ARI. You pass in what you want as the timeout, and then when that channel in the dialplan calls Dial() you can use the dialplan variable. This is the easiest and simplest option.

For ARI you don’t need a dialplan variable, as you can keep track of the information in your ARI application. For an ARI application to receive events for a channel it has to be subscribed to receive them. It’s up to you to use the information, using bridge entered and answered may work for your scenario.

1 Like

Oh yes, I understand that Dial() will take care of timeout. But using Dial, the timeout will started when both channels will be bridged, right?

But in my case, USER1 and USER2 are external users called via PJSIP trunk and while USER1 is waiting for USER2 (and listen beeps) it is billing seconds also. And I am want setup timeout not for bridged call where Dial() can help, but for channels:
USER1 <-> Asterisk
USER2 <-> Asterisk

Let me know if I somewhere not clear, maybe I am thinking in wrong direction.

Thanks.

The TIMEOUT dialplan function[1] also provides timeouts.

[1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Function_TIMEOUT

1 Like

Oh thank you, @jcolp

Looks like it should help! Your suggestions always help me)

Only need now realize how to setup timeout for another channel.

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