Integrating FreePBX with A2Billing

There are several reasons you may want to integrate FreePBX and A2Billing. Whether you’re just using FreePBX to setup trunks for your a2billing calling card system or you use FreePBX and want to route the outbound calls via a2billing to do least cost routing.

There are 2 things you need to do to integrate the two. The first is to add the following to extensions_custom.conf


/etc/asterisk/extensions_custom.conf

[a2billing]
exten => _X.,1,Answer
exten => _X.,n,Wait(1)
exten => _X.,n,DeadAGI(a2billing.php|1)
exten => _X.,n,Hangup

[a2billing-callback]
exten => _X.,1,DeadAGI(a2billing.php|1|callback)
exten => _X.,n,Hangup

[a2billing-cid-callback]
exten => _X.,1,Wait(1)
exten => _X.,n,DeadAGI(a2billing.php|1|cid-callback)
exten => _X.,n,Hangup

[a2billing-all-callback]
exten => _X.,1,DeadAGI(a2billing.php|1|all-callback|1) ;last parameter is the callback area code
exten => _X.,n,Hangup

[a2billing-predictivedialer]
exten => _X.,1,DeadAGI(a2billing.php|1|predictivedialer)
exten => _X.,n,Hangup

[a2billing-did]
exten => _X.,1,DeadAGI(a2billing.php|1|did)
exten => _X.,2,Hangup

[a2billing-voucher]
exten => _X.,1,DeadAGI(a2billing.php|1|voucher)
;exten => _X.,1,AGI(a2billing.php|1|voucher|1) ; will add 44 in front of the callerID for the CID authentication
exten => _X.,n,Hangup

[a2billing-sip]
exten => _X.,1,DeadAGI(a2billing.php|2)
exten => _X.,n,Hangup

The number after the a2billing.php| is the agi-conf in the a2billing.conf file that the call is passed to. This allows you to have different settings for certain types of calls such as whether the caller can chose the a2billing language or whether their balance is read to them. You will need to restart Asterisk or ‘reload sip’ to get the changes above to take effect.

You might not need all of the contexts above but it won’t hurt to put them in there.

The second thing to do is create the following Custom Destinations in FreePBX -

Custom Destination: a2billing,${EXTEN},1 Description: a2billing
Custom Destination: a2billing-callback,${EXTEN},1 Description: a2billing-callback
Custom Destination: a2billing-cid-callback,${EXTEN},1 Description: a2billing-cid-callback
Custom Destination: a2billing-did,${EXTEN},1 Description: a2billing-did
Custom Destination: a2billing-sip,${EXTEN},1 Description: a2billing-sip

Again, you might not need all of those or you might need extra ones but you get the idea.
So you should end up with something like this -

screenshot-4_22_2009-8_56_08-pm

These destinations can then be used in Inbound Routes, IVRs, etc in FreePBX to pass the call to A2Billing




Related posts:

  1. Using callwithus with Asterisk, FreePBX and A2Billing
  2. Getting started with FreePBX – Part 6 Cheap phone calls using DISA and Callback
  3. Getting started with FreePBX – Part 5 Setting up an IVR


13 Comments

  1. Ron:

    I implemented these two integration features but my AGI does not seem to work.

    It says it is executing
    — Executing [6465556666@custom-a2billing-did:1] DeadAGI(“SIP/174.36.235.155-00000001″, “a2billing.php|1|did”) in new stack
    but the call just keeps ringing and is never answered.

    Here’s the whole session:

    == Using SIP RTP CoS mark 5
    == Using SIP VRTP TOS bits 136
    == Using SIP VRTP CoS mark 6
    — Executing [6465556666@from-sip-external:1] NoOp(“SIP/174.36.235.155-00000001″, “Received incoming SIP connection from unknown peer to 6465556666″) in new stack
    — Executing [6465556666@from-sip-external:2] Set(“SIP/174.36.235.155-00000001″, “DID=6465556666″) in new stack
    — Executing [6465556666@from-sip-external:3] Goto(“SIP/174.36.235.155-00000001″, “s,1″) in new stack
    — Goto (from-sip-external,s,1)
    — Executing [s@from-sip-external:1] GotoIf(“SIP/174.36.235.155-00000001″, “1?checklang:noanonymous”) in new stack
    — Goto (from-sip-external,s,2)
    — Executing [s@from-sip-external:2] GotoIf(“SIP/174.36.235.155-00000001″, “0?setlanguage:from-trunk,6465556666,1″) in new stack
    — Goto (from-trunk,6465556666,1)
    — Executing [6465556666@from-trunk:1] Set(“SIP/174.36.235.155-00000001″, “__FROM_DID=6465556666″) in new stack
    — Executing [6465556666@from-trunk:2] Gosub(“SIP/174.36.235.155-00000001″, “cidlookup,cidlookup_1,1″) in new stack
    — Executing [cidlookup_1@cidlookup:1] Set(“SIP/174.36.235.155-00000001″, “CALLERID(name)=”) in new stack
    — Executing [cidlookup_1@cidlookup:2] Return(“SIP/174.36.235.155-00000001″, “”) in new stack
    — Executing [6465556666@from-trunk:3] ExecIf(“SIP/174.36.235.155-00000001″, “1 ?Set(CALLERID(name)=2015556666)”) in new stack
    — Executing [6465556666@from-trunk:4] Set(“SIP/174.36.235.155-00000001″, “__CALLINGPRES_SV=allowed_not_screened”) in new stack
    — Executing [6465556666@from-trunk:5] Set(“SIP/174.36.235.155-00000001″, “CALLERPRES()=allowed_not_screened”) in new stack
    — Executing [6465556666@from-trunk:6] Goto(“SIP/174.36.235.155-00000001″, “custom-a2billing-did,6465556666,1″) in new stack
    — Goto (custom-a2billing-did,6465556666,1)
    — Executing [6465556666@custom-a2billing-did:1] DeadAGI(“SIP/174.36.235.155-00000001″, “a2billing.php|1|did”) in new stack
    — Executing [6465556666@custom-a2billing-did:2] Hangup(“SIP/174.36.235.155-00000001″, “”) in new stack
    == Spawn extension (custom-a2billing-did, 6465556666, 2) exited non-zero on ‘SIP/174.36.235.155-00000001′

  2. matt:

    Hi, in a2billing, for the agi-conf1, have you got answer call set to yes?

  3. kkhan:

    I want to make calls from freepbx extension and route them to a2billing (on the same machine) for billing purposes. No matter what I do I couldn’t achieve it. Can someone point me to the right direction?

  4. matt:

    Hi kkhan, did you try doing the steps above? How far are you getting? What version of Asterisk and A2Billing are you running?

  5. Milton:

    Hi Mat, many thanks for this tutorial, it saved me from driving me mad, I followed this tutorial an got a2billing integrated with free pbx, the problem shows up when i dialed the custom destination through an IVR, as soon as i press the opt enable for that purpose the call hung up with the following errors msg, it works fine if I re-direct the DID to that custom destination by passing the IVR. any suggestion would be greatly appreciate.

    == CDR updated on SIP/Main-ISN-000000d8
    — Executing [9@ivr-3:1] DBdel(“SIP/Main-ISN-000000d8″, “”) in new stack
    — Executing [9@ivr-3:2] Set(“SIP/Main-ISN-000000d8″, “__NODEST=”) in new stack
    — Executing [9@ivr-3:3] Goto(“SIP/Main-ISN-000000d8″, “a2billing-sip|9|1″) in new stack
    — Goto (a2billing-sip,9,1)

    Regards.

  6. matt:

    Hi Milton,

    What does your entry for a2billing-sip look like in the Asterisk config files. Normally found in extensions_custom.conf if you’re running FreePBX.

    Also, that looks like it’s being passed to agi-conf9 in a2billing, is that correct? Is that agi-conf set to answer the call?

    Matt

  7. Cristhian:

    Hi, good material….seems to me like this should work for incoming calls.
    what about outgoing calls on the same machine???
    is there any additional configuration necessary to send the calls from FreePBX to A2Billing???

    Cristhian.

  8. matt:

    Hi Cristhian, I’ve written a walkthrough about routing FreePBX calls via A2Billing. It’s based on Elastix but the principals are you same. You can find it here – http://sysadminman.net/blog/2010/using-a2billing-to-account-for-extension-calls-in-elastix-1307

  9. Yunier:

    hello matt
    i am using freepbx 2.7 and a2billing 1.7, i have the custom destinations and the extensions_custom.conf configured to use a2billing-sip but in this version of a2billing the agi-conf are not in a2billing.conf and i really don’t know how to configure it. my problem is that the calls are beeing charged to the clients before they star talking, i mean when a client finish dialing the call star counting as connected before even ring. do you know how can i fix this, please help me.

    bye

    YUNIER

    MY [a2billing-sip] is like yours and so is my custom destination.

  10. matt:

    Hi Yunier, yes since version 1.4 all the settings (well, most) that were in a2billing.conf have been moved to the GUI so you can now edit the AGI-CONF settings there.

    How are your clients connecting to a2billing. Are the sip customers using their own soft/hard phones to connect to a2billing, or are they extensions in FreePBX?

    Matt

  11. yunier:

    hi matt

    thank you very much for your answer. it looks like the problem was in the carrier’s end they told me they made some changes and now everything is working fine so far. yes the most of my clients are sip customers using PAP2 to connect to a2billing.

    thanks again

  12. Thom:

    Hi Math,
    Thanks for this tut. it helped a lot. but I have the same problem as described above. my a2billing does not work. Please look below

    — Executing [7046064441@a2billing:1] Answer(“SIP/2000-00000032″, “”) in new stack
    — Executing [7046064441@a2billing:2] Wait(“SIP/2000-00000032″, “1″) in new stack
    — Executing [7046064441@a2billing:3] DeadAGI(“SIP/2000-00000032″, “a2billing.php|1″) in new stack
    — Executing [7046064441@a2billing:4] Hangup(“SIP/2000-00000032″, “”) in new stack
    == Spawn extension (a2billing, 7046064441, 4) exited non-zero on ‘SIP/2000-00000032′
    I checked ag conf and it is allowed to answered, I tried to go around it but without success. Would you have an idea. Is there a way to test that AGI is functionning properly?

    Thanks a million

  13. matt:

    Hi Thom, it looks like the a2billing.php is not even running. I would double check you have copied the php files to the correct place plus the lib folder.

Leave a comment