Integrating FreePBX with A2Billing

Please note that if using Asterisk 1.6 or later the pipe (|) symbols below need changing to commas (,)

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


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

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

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

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

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

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

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

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 –


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

123 thoughts on “Integrating FreePBX with A2Billing

  1. Ron

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

    It says it is executing
    — Executing [[email protected]:1] DeadAGI(“SIP/”, “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 [[email protected]:1] NoOp(“SIP/”, “Received incoming SIP connection from unknown peer to 6465556666”) in new stack
    — Executing [[email protected]:2] Set(“SIP/”, “DID=6465556666”) in new stack
    — Executing [[email protected]:3] Goto(“SIP/”, “s,1”) in new stack
    — Goto (from-sip-external,s,1)
    — Executing [[email protected]:1] GotoIf(“SIP/”, “1?checklang:noanonymous”) in new stack
    — Goto (from-sip-external,s,2)
    — Executing [[email protected]:2] GotoIf(“SIP/”, “0?setlanguage:from-trunk,6465556666,1”) in new stack
    — Goto (from-trunk,6465556666,1)
    — Executing [[email protected]:1] Set(“SIP/”, “__FROM_DID=6465556666”) in new stack
    — Executing [[email protected]:2] Gosub(“SIP/”, “cidlookup,cidlookup_1,1”) in new stack
    — Executing [[email protected]:1] Set(“SIP/”, “CALLERID(name)=”) in new stack
    — Executing [[email protected]:2] Return(“SIP/”, “”) in new stack
    — Executing [[email protected]:3] ExecIf(“SIP/”, “1 ?Set(CALLERID(name)=2015556666)”) in new stack
    — Executing [[email protected]:4] Set(“SIP/”, “__CALLINGPRES_SV=allowed_not_screened”) in new stack
    — Executing [[email protected]:5] Set(“SIP/”, “CALLERPRES()=allowed_not_screened”) in new stack
    — Executing [[email protected]:6] Goto(“SIP/”, “custom-a2billing-did,6465556666,1”) in new stack
    — Goto (custom-a2billing-did,6465556666,1)
    — Executing [[email protected]:1] DeadAGI(“SIP/”, “a2billing.php|1|did”) in new stack
    — Executing [[email protected]:2] Hangup(“SIP/”, “”) in new stack
    == Spawn extension (custom-a2billing-did, 6465556666, 2) exited non-zero on ‘SIP/’

  2. 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?

  3. matt Post author

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

  4. 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 [[email protected]:1] DBdel(“SIP/Main-ISN-000000d8”, “”) in new stack
    — Executing [[email protected]:2] Set(“SIP/Main-ISN-000000d8”, “__NODEST=”) in new stack
    — Executing [[email protected]:3] Goto(“SIP/Main-ISN-000000d8”, “a2billing-sip|9|1”) in new stack
    — Goto (a2billing-sip,9,1)


  5. matt Post author

    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?


  6. 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???


  7. 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.



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

  8. matt Post author

    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?


  9. 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

  10. 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 [[email protected]:1] Answer(“SIP/2000-00000032”, “”) in new stack
    — Executing [[email protected]:2] Wait(“SIP/2000-00000032”, “1”) in new stack
    — Executing [[email protected]:3] DeadAGI(“SIP/2000-00000032”, “a2billing.php|1”) in new stack
    — Executing [[email protected]: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

  11. matt Post author

    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.

  12. KaizerSoze

    To Thom and maybe others this line: exten => _X.,n,DeadAGI(a2billing.php|1) in a new 1.7 version of a2bill should be: exten => _X.,n,DeadAGI(a2billing.php,1) I think
    I spent a lot of time on errors like yours try it and say helps or not 🙂

  13. Pingback: Integración FreePBX y A2Billing | Manual A2Billing | Tutorial A2Billing

  14. Rodo

    Hi Matt,

    My Asterisk : 1.6.2, FreePBX : 2.7 and A2Billing : 1.3.0.

    I have configured the follow me extension 2000 with Custom Destinations “a2billing”. When i try to call extension 2000 from extension 2005 the call hangup. Shouldn´t I be asked by a2billing to “Please enter your card number”?.

  15. Rodo

    I don´t have an access number. I just want that 2005 extension make an external call and transfer it to a2billing and it ask “Please enter your card number”. Is this posible?

  16. Christina

    Hi. I’m trying to access feature codes in FreePBX from a A2Billing. So I have a inbound route setup to a2billing custom destination. Great. I have this exact configuration. What would I need to do to accomplish this? Thanks! How would I be able to call the features codes from A2Billing? Thanks!

  17. matt Post author

    What feature code/s was it you wanted to use?

    One option would be to add the feature code you wanted to the context of your a2billing clients. For example if your SIP clients where in a context called a2billing-sip that normally looked like this –

    exten => _X.,1,DeadAGI(a2billing.php,2)
    exten => _X.,n,Hangup

    you could add the echo test feature code to it like this –

    exten => *43,1,Answer
    exten => *43,n,Wait(1)
    exten => *43,n,Playback(demo-echotest)
    exten => *43,n,Echo()
    exten => *43,n,Playback(demo-echodone)
    exten => *43,n,Hangup

    exten => _X.,1,DeadAGI(a2billing.php,2)
    exten => _X.,n,Hangup

    Your customers in the a2billing-sip context would then be able to dial the echo test. You can find the feature code contexts in here – /etc/asterisk/extensions_additional.conf

  18. Christina

    Thanks for the response… Is there supposed to be a space between the two entries. I want to have them be able to access the My Voicemail (*97) voicemail feature code Here’s what I’m going to put in:

    exten => *43,1,Answer
    exten => *43,n,Wait(1)
    exten => *43,n,Playback(demo-echotest)
    exten => *43,n,Echo()
    exten => *43,n,Playback(demo-echodone)
    exten => *43,n,Hangup
    exten => _X.,1,DeadAGI(a2billing.php|3)
    exten => _X.,n,Hangup

    Is this correction

    This is the error I’m getting

    [Jan 20 16:52:57] NOTICE[1537]: chan_sip.c:14847 handle_request_invite: Call from ‘694200275387894’ to extension ‘*43’ rejected because extension not found.

    Please help! Thanks!

  19. matt Post author

    It should work with or without the space.

    From the Asterisk prompt you should be able to see the new entries for that context –

    *CLI> dialplan show wholesale-eldan

    If that still doesn’t work your calls can’t be originating from that context.

    Not sure implementing voicemail is going to be as easy as making access available though.

  20. matt Post author

    The above should give your customers access to the voicemail system, but then you are going to have to setup mailboxes, etc.

    Also, you’ll need to get incoming DIDs to forward to voicemail on no answer so they can be left a voicemail.

  21. Christina

    Now I’m having issues: when I do that, I can get voicemail, but I can’t dialout…

    exten => *97,1,Answer
    exten => *97,2,VoiceMailMain()
    exten => _X.,1,DeadAGI(a2billing.php|3)
    exten => _X.,n,Hangup

  22. Christina

    Hi Matt.

    This is the context that I used to get it working:

    exten => *97,1,Answer
    exten => *97,n,VoiceMailMain()
    exten => _X.,1,DeadAGI(a2billing.php|3)
    exten => _X.,n,Hangup

    Now, I need to edit it to get it to not ask for the mailbox! Do you have any ideas on how that would work?

    Thanks so much for everything!

  23. Christina

    the voicemail feature has been added since a2billing 1.4, so i didn’t really need to make any core adjustments. what i did though was create an extension in freepbx with the same accountcode as the sip friend, and enabled voicemail. this way, when i use the $CDR(accountcode) variable, it picks that up, transfers it to ask for a password and done! i also setup the second destination of the inbound did to the voicemailboz created in freepbx @from-internal, so after 20-30 seconds, it goes to voicemail. the client can now dial *98 and retrive voicemail. thanks so much for your help!

  24. eftekhar

    I install asterisk 1.8 and a2billing 1.7.
    extensions_custom.conf here:
    exten => _X.,1,Answer(1)
    exten => _X.,n,Agi(a2billing.php,1)
    exten => h,1,Hangup
    i also add a trunk in a2billing which peer information is put in sip.conf

    when i dial a number shows the following:
    == Using SIP RTP CoS mark 5
    — Executing [[email protected]:1] Answer(“SIP/08588-0000000c”, “1”) in new stack
    — Executing [[email protected]:2] AGI(“SIP/08588-0000000c”, “a2billing.php,1”) in new stack
    — Launched AGI Script /var/lib/asterisk/agi-bin/a2billing.php
    AGI Tx >> agi_request: a2billing.php
    AGI Tx >> agi_channel: SIP/08588-0000000c
    AGI Tx >> agi_language: en
    AGI Tx >> agi_type: SIP
    AGI Tx >> agi_uniqueid: 1296159906.12
    AGI Tx >> agi_version:
    AGI Tx >> agi_callerid: 08588
    AGI Tx >> agi_calleridname: unknown
    AGI Tx >> agi_callingpres: 0
    AGI Tx >> agi_callingani2: 0
    AGI Tx >> agi_callington: 0
    AGI Tx >> agi_callingtns: 0
    AGI Tx >> agi_dnid: 8801925180640
    AGI Tx >> agi_rdnis: unknown
    AGI Tx >> agi_context: a2billing
    AGI Tx >> agi_extension: 8801925180640
    AGI Tx >> agi_priority: 2
    AGI Tx >> agi_enhanced: 0.0
    AGI Tx >> agi_accountcode: 08588
    AGI Tx >> agi_threadid: -1275430000
    AGI Tx >> agi_arg_1: 1
    AGI Tx >>
    AGI Tx >> 200 result=0
    AGI Rx << ANSWER
    AGI Tx >> 200 result=0
    AGI Rx << STREAM FILE 0 "#" 0
    AGI Tx >> 200 result=0 endpos=0
    AGI Rx << SET VARIABLE CHANNEL(language) "en"
    AGI Tx >> 200 result=1
    AGI Rx << STREAM FILE prepaid-you-have "#" 0
    — Playing 'prepaid-you-have' (escape_digits=#) (sample_offset 0)
    AGI Tx >> 200 result=0 endpos=9440
    AGI Rx << SAY NUMBER 5 ""
    — Playing ‘digits/5.gsm’ (language ‘en’)
    AGI Tx >> 200 result=0
    AGI Rx << STREAM FILE dollars "#" 0
    — Playing 'dollars' (escape_digits=#) (sample_offset 0)
    AGI Tx >> 200 result=0 endpos=7200
    AGI Rx << STREAM FILE vm-and "#" 0
    — Playing 'vm-and' (escape_digits=#) (sample_offset 0)
    AGI Tx >> 200 result=0 endpos=4800
    AGI Rx << SAY NUMBER 75 ""
    — Playing ‘digits/70.gsm’ (language ‘en’)
    — Playing ‘digits/5.gsm’ (language ‘en’)
    AGI Tx >> 200 result=0
    AGI Rx << STREAM FILE prepaid-cents "#" 0
    — Playing 'prepaid-cents' (escape_digits=#) (sample_offset 0)
    AGI Tx >> 200 result=0 endpos=5600
    AGI Rx << SET CALLERID 08588
    AGI Tx >> 200 result=1
    AGI Rx << CHANNEL STATUS SIP/08588-0000000c
    AGI Tx >> 200 result=6
    AGI Rx << GET DATA prepaid-press4-info 5000 1 #
    — Playing ‘prepaid-press4-info.slin’ (language ‘en’)
    AGI Tx >> 200 result= (timeout)
    AGI Rx << GET DATA prepaid-press9-new-speeddial 5000 1
    — Playing ‘prepaid-press9-new-speeddial.gsm’ (language ‘en’)
    AGI Tx >> 200 result= (timeout)
    AGI Rx << STREAM FILE prepaid-you-have "#" 0
    — Playing 'prepaid-you-have' (escape_digits=#) (sample_offset 0)
    AGI Tx >> 200 result=0 endpos=9440
    AGI Rx << SAY NUMBER 185 ""
    — Playing ‘digits/1.gsm’ (language ‘en’)
    — Playing ‘digits/hundred.gsm’ (language ‘en’)
    — Playing ‘digits/80.gsm’ (language ‘en’)
    — Playing ‘digits/5.gsm’ (language ‘en’)
    AGI Tx >> 200 result=0
    AGI Rx << STREAM FILE prepaid-minutes "#" 0
    — Playing 'prepaid-minutes' (escape_digits=#) (sample_offset 0)
    AGI Tx >> 200 result=0 endpos=6240
    AGI Rx << STREAM FILE vm-and "#" 0
    — Playing 'vm-and' (escape_digits=#) (sample_offset 0)
    AGI Tx >> 200 result=0 endpos=4800
    AGI Rx << SAY NUMBER 20 ""
    — Playing ‘digits/20.gsm’ (language ‘en’)
    AGI Tx >> 200 result=0
    AGI Rx << STREAM FILE prepaid-seconds "#" 0
    — Playing 'prepaid-seconds' (escape_digits=#) (sample_offset 0)
    AGI Tx >> 200 result=0 endpos=6400
    AGI Rx << SET CALLERID 11001
    AGI Tx >> 200 result=1
    AGI Rx << EXEC DIAL sip/[email protected]|60|HCL(11120000:61000:30000)
    — AGI Script Executing Application: (DIAL) Options: (sip/[email protected]|60|HCL(11120000:61000:30000))
    == Using SIP RTP CoS mark 5
    — Called [email protected]|60|HCL(11120000:61000:30000)
    — SIP/Novotel|60|HCL(11120000:61000:30000)-0000000d is circuit-busy
    == Everyone is busy/congested at this time (1:0/1/0)
    AGI Tx >> 200 result=0
    AGI Tx >> 200 result=1 ()
    AGI Tx >> 200 result=1 (CONGESTION)
    AGI Rx << STREAM FILE prepaid-dest-unreachable "#" 0
    — Playing 'prepaid-dest-unreachable' (escape_digits=#) (sample_offset 0)
    AGI Tx >> 200 result=0 endpos=25760
    — AGI Script a2billing.php completed, returning 0
    — Executing [[email protected]:1] Hangup(“SIP/08588-0000000c”, “”) in new stack
    == Spawn extension (a2billing, h, 1) exited non-zero on ‘SIP/08588-0000000c’

    I also try with IP address insteade of trunk name Novotel.

    Plz suggest me.

  25. Christina

    hi eftekhar, i’m not really famililar with asterisk 1.8, but is your configuration for the trunk correction

    DIAL sip/[email protected]|60|HCL(11120000:61000:30000)
    — AGI Script Executing Application: (DIAL) Options: (sip/[email protected]|60|HCL(11120000:61000:30000))
    == Using SIP RTP CoS mark 5
    — Called [email protected]|60|HCL(11120000:61000:30000)
    — SIP/Novotel|60|HCL(11120000:61000:30000)-0000000d is circuit-busy
    == Everyone is busy/congested at this time (1:0/1/0)

    this means that either you have something wrong, or your provider does. and number two, your password is EXTREMELY soft. did you add any trunk information in a2billing? you need to do that, as well as rates and callplan etc.

  26. Daniel

    hi matt a long time ago i am trying to configure asterisk 1.6.2 and a2billing dial plan with agi config i am changing to 1_6 and it does not work but when i change it to 1_4 it works can someone please tell me how i can get it to work this is my dial plan

    exten => _.,1,Answer(750)
    exten => _.,n,DeadAgi(a2billing.php,1)
    exten => _.,n,Hangup

    exten => _.,1,DeadAgi(a2billing.php,1,callback)
    exten => _.,n,Hangup

    exten => h,1,Hangup
    exten => _.,1,DeadAgi(a2billing.php,1,cid-callback,) ;last parameter is the callback area code
    exten => _.,n,Hangup

    exten => _.,1,DeadAgi(a2billing.php,1,all-callback,) ;last parameter is the callback area code
    exten => _.,n,Hangup

    exten => _.,1,DeadAgi(a2billing.php,1,predictivedialer)
    exten => _.,n,Hangup

    exten => _.,1,DeadAgi(a2billing.php,1,did)
    exten => _.,2,Hangup

    exten => _.,1,Answer(1)
    exten => _.,n,DeadAgi(a2billing.php,1,voucher)
    ;exten => _.,n,AGI(a2billing.php,1,voucher,) ; will add 44 in front of the callerID for the CID authentication
    exten => _.,n,Hangup

    ; for sip clients – agi-conf2 (make sure a2billing-sip set as context for a2billing customer)
    exten => _X.,1,DeadAGI(a2billing.php,2)
    exten => _X.,n,Hangup

    when i try to make a call i get a message in asterisk

    Everyone is busy/congested at this time (1:0/1/0)

    i will appreciate it if someone tells wheat i am doing wrong

    Thank you

  27. matt Post author

    Hi Daniel,

    How are you making a call? Is this via a calling card access number or a SIP client/phone?

  28. Daniel

    Hi matt thank your for replying to my question.

    i am trying every way i can a call. When i change in agi-conf1 to 1_4 everything works fine but when i change it to 1_6 i cant make a call i am changing 1_6 because i am using asterisk . I think that somewhere in asterisk there need to be some changes but i am not sure

    thank your

  29. matt Post author

    One thing that changing the setting to 1_6 does is automatically replace any ‘|’ in the dial string with ‘,’ (this was a change with Asterisk 1.6).

    If you are working OK with that setting set to 1_4 I would not worry. It looks like you already have all the custom conexts using commas.

    Are you seeing any other negative effects of using the setting at 1_4?

  30. Samuel

    Hello Matt,
    Thanks for all over your help here…

    I have asterisk 1.4&a2b 1.9.
    I add the following context into a2billing dialplan:

    exten => 123,1,Playback(demo-echotest)
    exten => 123,n,Echo
    exten => 123,n,Playback(demo-echodone)

    But when I try to test it placing a call to 123, in cli I see:
    — Accepting AUTHENTICATED call from 95.++.++.++:
    > requested format = gsm,
    > requested prefs = (),
    > actual format = ulaw,
    > host prefs = (ulaw|alaw|gsm|g729),
    > priority = mine
    — Executing [[email protected]:1] NoOp(“IAX2/0****-3832”, “A2Billing Start”) in new stack
    — Executing [[email protected]:2] DeadAGI(“IAX2/0***-3832”, “a2billing.php|2”) in new stack
    — Launched AGI Script /var/lib/asterisk/agi-bin/a2billing.php
    — AGI Script a2billing.php completed, returning 0
    — Hungup ‘IAX2/0***-3832’

    And as you see, the call is doped…

    Why I’m having that?

  31. matt Post author

    I think you need to turn on a2billing debugging (which you can find in the AGI-CONF settings you are using). If you set debug to 4 this will give you detailed feedback about the a2billing.php script. Don’t leave it that way in production though as it will slow things down.

  32. Samuel

    Thanks Matt for so fast prompt…
    Kindly bellow the cli:

    Connected to Asterisk 1.4.40 currently running on sipcel (pid = 1004)
    Verbosity was 3 and is now 4
    — Accepting AUTHENTICATED call from 95.*******:
    > requested format = gsm,
    > requested prefs = (),
    > actual format = ulaw,
    > host prefs = (ulaw|alaw|gsm|g729),
    > priority = mine
    — Executing [[email protected]:1] NoOp(“IAX2/0***-3881”, “A2Billing Start”) in new stack
    — Executing [[email protected]:2] DeadAGI(“IAX2/0****-3881”, “a2billing.php|2”) in new stack
    — Launched AGI Script /var/lib/asterisk/agi-bin/a2billing.php
    — AGI Script a2billing.php completed, returning 0
    — Hungup ‘IAX2/0****-3881’


  33. matt Post author

    That’s just Asterisk logs. A2Billing has it’s own detailed logging and inbetween these 2 lines –

    Launched AGI Script /var/lib/asterisk/agi-bin/a2billing.php
    — AGI Script a2billing.php completed, returning 0

    You should see 50 lines or so of debug from a2billing if it’s switched on (in the a2billing GUI)

  34. Samuel

    It seem to be returning the error for prefix issue… kindly see below:
    [18/05/2011 15:35:51]:[file:a2billing.php – line:396 – uniqueid:1305732951.32]:[CallerID:***]:[CN:06604]:[TARIFF ID -> 1]
    [18/05/2011 15:35:51]:[file:Class.A2Billing.php – line:881 – uniqueid:1305732951.32]:[CallerID:***]:[CN:06604]:[[CALL 2 DID]]
    [18/05/2011 15:35:51]:[file:Class.A2Billing.php – line:896 – uniqueid:1305732951.32]:[CallerID:***]:[CN:06604]:[DESTINATION ::> 123]
    [18/05/2011 15:35:51]:[file:Class.A2Billing.php – line:1017 – uniqueid:1305732951.32]:[CallerID:***]:[CN:06604]:[ERROR ::> RateEngine didnt succeed to match the dialed number over the ratecard (Please check : id the ratecard is well create ; if the removeInter_Prefix is set according to your prefix in the ratecard ; if you hooked the ratecard to the Call Plan)]
    [18/05/2011 15:35:51]:[CallerID:***]:[CN:****]:[[exit]]

  35. matt Post author

    Yes, it’s just not matching a rate to the number you dialled. Have a go with Rates/Simulator in the GUI, that will tell you if your Rate Card is working the way you expect.

  36. Samuel

    Yes, but I’m dealing this as an echo test, as I said, I add the echo test context in a2billing dialplan as:
    exten => 123,1,Playback(demo-echotest)
    exten => 123,n,Echo
    exten => 123,n,Playback(demo-echodone)

    So, how should I add the rate for that, and to which trunk mapp it, if yes?

  37. Pingback: FreePBX (CentOS 5.5) & A2Billing 1.9.4 (Stable) inside VirtualBox 4.0.8 Installation Notes « BinaryGuru

  38. Ali

    Hi Matt,
    appreciate your efforts for the very helpful tutorial. i followed it using freepbx latest,asterisk 1.6 and a2billing 1.9.4.. all worked fine but my problem is a common i think.. outbound call is answered and starts billing while it still ringing the called party. I am using Freepbx extensions to be billed through a2billing.
    do you have any idea how to avoid this problem ??

  39. matt Post author

    Hi Ali,

    I’m going to write a blog post about this as it’s a common problem. I know 3 places to check –

    1 – In the dial plan (extensions_custom.conf?) ensure you don’t have an Answer line for the context you are using
    2 – In the AGI-CONF that you are using ensure answer_call is set to no
    3 – In the AGI-CONF that you uare using ensure there is no ‘H’ ‘r’ or ‘R’ as part of the dial_command

  40. Samuel

    Hello Matt, and other friends,

    I have new server running asterisk 1.8.3&a2billing 1.9.4, everything it’s working properly…

    But, I have been created agi2 to handle voip reselling, where in I have dialcommand_param_sipiax_friend=,60,HiL(3600000:61000:30000) , and answer_call=no

    And int he dialplan I have:
    exten => _X.,1,Answer
    exten => _X.,n,Wait(1)
    exten => _X.,n,AGI(a2billing.php,2)
    exten => _X.,n,Hangup

    I’m facing FAS problems, that asterisk is answering the calls, meanwhile it still in progress, so it start billing the traunk user…

    I removed the answer line from the dialcommand, but when i do that i get
    [Quote]chan_sip.c:21619 handle_request_invite: Call from ‘s’ to extension ‘XXXXXXXXX’ rejected because extension not found in context ‘a2billing’.[/Quote]

    Any other idea to figure out the FAS problem, please?

    Thanks in advance!

  41. Samuel

    Hello Matt,
    What about if I don’t want to use Freepbx, so I have running asterisk 1.8.4 with a2billing 1.9.4, and everything it’s outgoing fine. Just i wanted to created the inbound context.

    The custom extensions which you refer her, for freepbx, how can i create them in extensions.conf file?

    Cause i try to make:
    exten => 7777,1,Dial(a2billing,${EXTEN},1)

    But asterisk is not finding that extensions, and it’s not working, how can i create that extensions in asterisk files directly without freepbx?

    Thanks in advance.

  42. matt Post author

    If not using FreePBX then you should just need to make sure that the line is in a context that is being loaded by Asterisk.

  43. Samuel

    Thanks Matt for your prompt.
    I’m not sure if I understand you, or I’m misunderstanding something… in this example, i wanted to appoint the inbound test ext. 777 for the a2billing calling card application, as you made in freepbx: Custom Destination: a2billing,${EXTEN},1 Description: a2billing .

    So, as you said, I add that ext. into the a2billing context as below:
    exten => _0.,1,Verbose(1,${CONTEXT} – ${EXTEN} – ${CALLERID(all)} – ${STRFTIME($
    exten => _0.,n,Wait(1)
    exten => _0.,n,AGI(a2billing.php,2)
    exten => _0.,n,Wait(1)
    exten => _0.,n,Hangup

    ;;Echo Test Ext.
    exten => 123,1,Playback(demo-echotest)
    exten => 123,n,Echo
    exten => 123,n,Playback(demo-echodone

    ;;Inbound Context
    exten => 7777,1,Dial(a2billing,${EXTEN},1)

    But when i call from an asterisk ext. to the ext. 123, i get correctly the echo test, but when i call to 7777, asterisk is showing this:
    [Jul 4 07:33:25] WARNING[12928]: app_dial.c:1950 dial_exec_full: Dial argument takes format (technology/[device:]number1)
    == Spawn extension (a2billing, 7777, 1) exited non-zero on ‘SIP/5769-0000001a’

    What I’m mistaking?

    Thanks again,

  44. Samuel

    Sorry, this forum don’t allow me to edit my own messages, so I’d answer my previous question, by my ownself…

    it’s really simple, creating inbound ext. and appoint them to the refereed context and put into a2billing agi conf. I mean, just create ext. for all dids, for example, and appoint it to a2billing-did for the inbound did…

    So, asterisk&a2billing without freepbx.


  45. Ahmed

    Hello Matt,
    i should say first that i lernt a lot from your tutorial, so keep on your good job. i have done the things you made in this tutorail 1 to 1, i am using an elastix machine. so i have 2 trunks which is working fine with elastix extinsions, and my a2billing is also working fine and i can make calls through trunk1 with a2billing. but when i am using the trunk2 i cant get calls, the call debug see as:

    Aug 16 15:10:34 VERBOSE [25550] app_dial.c: == Everyone is busy/congested at this time (1:0/1/0)
    Aug 16 15:10:34 WARNING [2921] chan_sip.c:Retransmission timeout reached on transmission [email protected]:5060 for seqno 102 (Critical Request) — See
    Packet timed out after 32123ms with no response
    Aug 16 15:10:34 VERBOSE [25550] res_agi.c:– AGI Script Executing Application: (DIAL) Options: (SIP/voip_info/00966534455119|60|HRrL(8428000:61000:30000))
    Aug 16 15:10:34 WARNING [25550] pbx.c: The application delimiter is now the comma, not the pipe. Did you forget to convert your dialplan? (Dial(SIP/voip_info/00966534455119|60|HRrL(8428000:61000:30000)))
    Aug 16 15:10:34 VERBOSE [25550] netsock2.c: == Using SIP RTP TOS bits 184
    Aug 16 15:10:34 VERBOSE [25550] netsock2.c: == Using SIP RTP CoS mark 5
    Aug 16 15:10:34 VERBOSE [25550] app_dial.c: — Called SIP/voip_info/00966534455119|60|HRrL(8428000:61000:30000)

    i hope you can help this time also as you did last time .. -:)

  46. matt Post author

    Hi Ahmed,

    I think you should set the Asterisk version to 1_6 in the A2Billing config (it’s probably set to 1_4 now).

    Cheers, Matt

  47. Tim

    Hi, Matt!

    After installing Asterisk and FreePBX 1.9, I followed your guides and everything works perfectly now! 🙂 However, sometimes when I call my DID, it asks for the PIN and works smoothly and times it plays the “the number you’ve dialed is not in service” What could it be from?


  48. matt Post author

    Hi Tim,

    I’d guess that either the call is coming from a different IP sometimes,or the CLID number is being presented differently for some calls.

    You could do ‘sip set debug on’ at the console and try to see what’s happening to the call (don’t forget to ‘sip set debug off’ when you’re done!)

  49. Jermaine Gray

    Hi matt am trying to route incoming call through a2billing but am getting a message saying the part you are trying to reach is unavailable. i configure my custom destination in the tutorial i do know what else t do. please help

  50. Elliot

    I am having problems making calls from my a2billing.
    I cam make calls from elastix freepbx.
    but when i make call with my account in a2billing after prompting to enter destination number or a direct dial over sip phone, its finds the correct route and carrier but hangs and disconnect.
    any help will be appriciated.
    The issue started after i upgraged to the latest satble Elastix.
    A2billing was setup manually before. with Admin, Agent, and cutomer interface.

  51. Elliot

    ok i forgot. this the line it stops
    Called SIP/xx.xx.xx.xx./004xxxxxxxxxxxxxx|60|HRrL(1260000:61000:30000)

  52. matt Post author

    What version of Asterisk are you running? If it’s version 1.6+ then they should be ‘,’ now not ‘|’. Changing Asterisk version to ‘1_6’ in A2Billing global settings should fix that.

  53. matt Post author

    You can replace them all if you want. Changing that setting should do it for you though in the background.

  54. Jermaine

    Hi Matte

    am now able to route incoming call to a2billing but i can call sip friendly account. when i try to call a sip account from my DID the it go to my did voice mail. am not sure how to run the log your ask me to run can you provided more detail.

    my setting are:

    ;for call through service
    exten => _X.,1,deadAGI(a2billing.php,1)
    exten => _X.,n,Hangup

    ;To deliver DID and bill for them
    exten => _X.,1,Answer
    exten => _X.,n,Wait(3)
    exten => _X.,1,deadAGI(a2billing.php,1,did)
    exten => _X.,2,Hangup

  55. Jermaine

    also i got this log from a2billing

    [20/11/2011 15:02:17]:[file:Class.RateEngine.php – line:1090]:[CallerID:8765648121]:[CN:07748]:[[USEDRATECARD=0]]
    [20/11/2011 15:02:17]:[file:Class.RateEngine.php – line:777]:[CallerID:8765648121]:[CN:07748]:[ft2c_package_offer : 1 ; 0 ; 0]
    [20/11/2011 15:02:17]:[file:Class.RateEngine.php – line:607]:[CallerID:8765648121]:[CN:07748]:[[CC_RATE_ENGINE_CALCULCOST: K=0 – CALLDURATION:6 – freetimetocall_used=0]]
    [20/11/2011 15:02:17]:[file:Class.RateEngine.php – line:642]:[CallerID:8765648121]:[CN:07748]:[[TEMP – CC_RATE_ENGINE_CALCULCOST: 1. COST: 0]:[ (6/60) * 0 ]]
    [20/11/2011 15:02:17]:[file:Class.RateEngine.php – line:719]:[CallerID:8765648121]:[CN:07748]:[[CC_RATE_ENGINE_CALCULCOST: K=0 – BUYCOST: 0 – SELLING COST: 0]]
    [20/11/2011 15:02:17]:[file:Class.RateEngine.php – line:824]:[CallerID:8765648121]:[CN:07748]:[[CC_RATE_ENGINE_UPDATESYSTEM: usedratecard K=0 – (sessiontime=6 :: dialstatus=ANSWER :: buycost=0 :: cost=0 : signe_cc_call=-: signe=+)]]
    [20/11/2011 15:02:17]:[file:Class.RateEngine.php – line:848]:[CallerID:8765648121]:[CN:07748]:[[CC_asterisk_stop QUERY = INSERT INTO cc_call (uniqueid,sessionid,username,nasipaddress,starttime,sessiontime, calledstation, terminatecause, stoptime, calledrate, sessionbill, calledcountry, calledsub, destination, id_tariffgroup, id_tariffplan, id_ratecard, id_trunk, src, sipiax, buyrate, buycost, id_card_package_offer) VALUES (‘1321819286.8’, ‘SIP/BroadVoice-00000008’, ‘07748’, ”, CURRENT_TIMESTAMP – INTERVAL 6 SECOND , ‘6’, ‘9543371446’, ‘ANSWER’, now(), ‘0’, ‘-0’, ”, ”, ‘local’, ‘4’, ‘4’, ‘349’, ‘4’, ‘8765648121’, ‘0’, ‘0’, ‘0’, ‘0’)]]
    [20/11/2011 15:02:17]:[file:Class.RateEngine.php – line:851]:[CallerID:8765648121]:[CN:07748]:[[CC_asterisk_stop 1.1: SQL: DONE : result=1]]
    [20/11/2011 15:02:17]:[file:Class.RateEngine.php – line:869]:[CallerID:8765648121]:[CN:07748]:[[CC_asterisk_stop 1.2: SQL: UPDATE cc_card SET credit= credit+0 , redial=’9543371446′ , lastuse=now(), nbused=nbused+1 WHERE username=’07748′]]
    [20/11/2011 15:02:17]:[file:Class.RateEngine.php – line:874]:[CallerID:8765648121]:[CN:07748]:[UPDATE cc_trunk SET secondusedreal = secondusedreal + 6 WHERE id_trunk=’4′]
    [20/11/2011 15:02:17]:[file:Class.RateEngine.php – line:878]:[CallerID:8765648121]:[CN:07748]:[UPDATE cc_tariffplan SET secondusedreal = secondusedreal + 6 WHERE id=’4′]
    [20/11/2011 15:02:17]:[file:a2billing.php – line:309]:[CallerID:8765648121]:[CN:07748]:[[a2billing account stop]]
    [20/11/2011 15:02:17]:[file:a2billing.php – line:169]:[CallerID:8765648121]:[CN:07748]:[[CHANNEL STATUS : = Channel is down and available]]
    [20/11/2011 15:02:17]:[file:a2billing.php – line:170]:[CallerID:8765648121]:[CN:07748]:[[CREDIT : 0][CREDIT MIN_CREDIT_2CALL : 0]]
    [20/11/2011 15:02:17]:[file:Class.A2Billing.php – line:634]:[CallerID:8765648121]:[CN:07748]:[[CARD STATUS UPDATE : UPDATE cc_card SET inuse=inuse-1 WHERE username=’07748′]]
    [20/11/2011 15:02:17]:[CallerID:8765648121]:[CN:07748]:[[STOP – EXIT]]

  56. Elliot

    Hello everybody,
    i have beene able to setup my a2billing. The calling card is working without problem but when i call with my sip softphone i get the error below

    extension ’00xxxxxxxxxx’ rejected because extension not found in context ‘a2billing’

    Any help will be appreciated

  57. Elliot

    Thanks matt,
    I have just noticed that my sip accounts are using the wrong contex.
    I have (a2billing) for my calling cards and a2billing-sip for my sip/Iax accounts. but cant make any call if my sip accounts are set to a2billing-sip contex. I treid changing the contex to something else but once i reload asterisk everything comes back to the old contex again. (a2billing-sip)
    Thanks in advance

  58. Jermaine

    Hi matt i install the new elastix 2.2 and a2billing 1.4 but am not able to used the say setting for my inbound calling to a2billing please advise or point me to the nearest instruction.

  59. Jermaine

    Hi matt
    Thank you very much for your help my server is up and running. But i have only have one question. can i add more context to a2billing-sip to allowing the IVR to prompt me for entering the a2billing sip friend account to call.

  60. jain

    Hi there, I was wondering if you please tell me how can I install A2Billing on my fresh installed FreePBX. I am not able to download it
    using given instruction..please help.


  61. matt Post author

    Did you check out the install notes that come with A2Billing. If so they should get you most of the way there.

  62. Tia

    I am running asterisk 1.8.4, freepbx 2.8 and a2billing 1.6. I have followed your tutorial with no success. right now I can make call using extension created by freepbx and customer created in a2billing but i cannot link the two together. This means my call (extension created in freepbx) is never routed to a2billing.


  63. Ricky

    Hello Matt,
    I have installes trixbox 2.8 and a2billing 1.9.4
    i configured a2billing folowing your video from youtube. now my problem is that when i change my inbound route set destination from IVR to CUSTOM DESTINATIONS (a2billing) and i make a call simulation using 7777 the system just hangs up the call. Any idea? ANY HELP WILL BE VERY APPRECIATED. Thanks

    here is how my extensions_custom.conf looks like:

    ; This file contains example extensions_custom.conf entries.
    ; extensions_custom.conf should be used to include customizations
    ; to AMP’s Asterisk dialplan.

    ; All custom context should contain the string ‘custom’ in it’s name

    ; Extensions in AMP have access to the ‘from-internal’ context.
    ; The context ‘from-internal-custom’ is included in ‘from-internal’ by default
    #include extensions_hud.conf


    ;1234,1,Playback(demo-congrats) ; extensions can dial 1234
    ;include => custom-recordme ; extensions can also dial 5678

    ; custom-count2four,s,1 can be used as a custom target for
    ; a Digital Receptionist menu or a Call Group

    ; custom-recordme,5678,1 can be used as a custom target for
    ; a Digital Receptionist menu or a Call Group
    ;exten => 5678,1,Wait(2)
    ;exten => 5678,2,Record(/tmp/asterisk-recording:gsm)
    ;exten => 5678,3,Wait(2)
    ;exten => 5678,4,Playback(/tmp/asterisk-recording)
    ;exten => 5678,5,Wait(2)
    ;exten => 5678,6,Hangup

    exten => s,1,Answer
    exten => s,n,Wait(3)
    exten => s,n,CBMysql()
    exten => s,n,Hangup

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

    exten => _X.,1,DeadAGI(a2billing.php,1,callback)
    exten => _X.,n,Hangup

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

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

    exten => _X.,1,DeadAGI(a2billing.php,1,predictivedialer)
    exten => _X.,n,Hangup

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

    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
    exten => _X.,n,Hangup

    exten => _X.,1,DeadAGI(a2billing.php,2)
    exten => _X.,n,Hangup

  64. matt Post author

    I’d try not using an IVR, but just putting an Inbound Route straight through to A2Billing to test. Otherwise it would be a case of turning up Asterisk debugging and watching what is happening to the call.

  65. matt Post author

    From the asterisk console you should look at the ‘core set debug’ and ‘core set verbosity’ commands.

  66. lyly

    I want to configure Callback on a2billing. Please tell me how to config and test it if you know. Thanks so much

  67. ulrich

    bonjour Matt
    j’ai utiliser freepbx distro 1.8 a2billing 1.9.4
    j’ai suivi le tuto du debut jusqu’a la fin ce je ne comprend est que apres avoir creer mes customers sous a2billing et que je clique sur les bouton sip ou iax pour generer les compte sur asterisk ça ne fait rien du tout
    svp j’ai besoin d’aide.merci pour le tuto

  68. ChrisM

    Hello i need to get my dialplan to redirect the call after the a2billing script completion to an ivr.

    ; CallingCard application
    exten => _.,1,NoOp(A2Billing Start)
    ;exten => _.,n,DeadAgi(a2billing.php,1)
    exten => _.,n,AGI(a2billing.php,1)
    ;exten => _.,n,Dial(SIP/203);
    exten => _,n,Goto(ivr-4,s,1)
    ;exten => _.,n,Playback(tt-weasels,skip);
    ;exten => _.,n,Hangup

    The channel hangs up before going to the ivr

    Thanks in advance.

  69. Joe

    I want to use a2billing to bill for time on all inbound call and outbound calls from a FREEPBX install. I have a2billing configured and I can point calls to it from in bound routes. Only I don’t want my customer to have to type in a pin or calling card. I just want to pass then to the IVR. If I change the inbound to custom, I can’t get them to the IVR… Help?

  70. matt Post author

    Hi Joe. Unfortunately it’s only really possible to offer that level of support to customers. You want to be looking at the agi-conf you are using and checking the audio settings I think.

    Cheers, Matt

  71. Javid


    in your video you say you have 2 agi-conf files, one is for inbound routes which is the DID number and one for the sip customers.

    I have added the second agi-conf file and I have also configured my extensions accordingly (A2billing-SIP) and I have also created a custom destination to use the A2billing-SIP extension.

    Now how do i tell the asterisk to use agi-conf1 for calling cards and agi-conf2 for SIP customers. Thank you

  72. effweb

    Tengo A2b 1.9.4 con Elx 2.3 todo me funciona bien pero necesito tarificar tambien las llamadas entrantes a las extensiones.

    Nota: Mis llamadas entrantes entran por IVR y marcan la extension.

    Pero aunque marquen directo del DID hacia las extensiones con que me funcione soy feliz.

    He buscado y no encuentro nada

    solo que necesito pasar las llamadas primero por IVR para que tecleen la extension primero

    llamada — IVR —- a2billing

    Alguien tiene solucion

    mil Gracias !!!

  73. Elwin Machado

    Hola effweb:
    Creo que vas a tener que meterle un poquito mas de mano a los contextos, o yo no he entendido bien lo que quieres, cualquier cosa que necesites estoy a disposición

    Elwin Machado

  74. effweb

    Actualmente puedo tarificar bien una llamada entrante DID uando a2billing a una extension
    Lo que necesito es que las llamadas entrantes necesito primero que pasen por el IVR de asterisk
    y luego marquen el No de extension antes de pasar a a2billing

    llamada entrante — IVR (teclear Extension ) — a2billin (tarificar) — Extension (rinnnggg)

    Ya estoy como loco no encuentro como hacerlo please ayudenme

  75. Joseph

    Hi Matt
    I am having a weired problem. Please notice Dest. number is my DID numner, it should have the number I have dialed. A2billing log show its trying to
    terminate call in right number.

    Call Date Recording System Src Chan. Source DID App. Dest. Dst. Chan. Disposition Duration Userfield Account
    2013-01-07 21:14:39 1357593279.420 SIP 447940402245 442032987620 AGI 442032987620 SIP ANSWERED 00:33
    2013-01-07 21:14:04 1357593244.419 SIP 447940402245 Playback s ANSWERED 00:07

  76. matt Post author

    Hi Joseph.

    Difficult to tell without knowing how your passing the call to a2billing. A2Billing will just use the destination number passed to it.

  77. Nick


    I used Ealstix 2.3 come with A2billing 1.9.4 when I try to custom build the inbound route with below command, call always hangup

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

  78. matt Post author

    You need a way to pass the incoming call to the a2billing context. It won’t be going there by default. Maybe with a Custom Destination in FreePBX.

  79. Nick

    I follow your guide line from above. Replace the pipe (|) symbols below need changing to commas (,) since I’m using Asterisk 1.8

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

    exten => _X.,1,DeadAGI(a2billing.php,1,callback)
    exten => _X.,n,Hangup

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

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

    exten => _X.,1,DeadAGI(a2billing.php,1,predictivedialer)
    exten => _X.,n,Hangup

    exten => _X.,1,DeadAGI(a2billing.php,1,did)
    exten => _X.,2,Hangup

    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

    exten => _X.,1,DeadAGI(a2billing.php,2)
    exten => _X.,n,Hangup

  80. py

    Hi matt

    i do not have any sound from a2billing on incoming calls .

    i have this log on console

    == Using SIP RTP TOS bits 184
    == Using SIP RTP CoS mark 5
    == Using SIP VRTP TOS bits 136
    == Using SIP VRTP CoS mark 6
    — Executing [[email protected]:1] Set(“SIP/callwithus-00000003”, “__FROM_DID=s”) in new stack
    — Executing [[email protected]:2] Gosub(“SIP/callwithus-00000003”, “app-blacklist-check,s,1”) in new stack
    — Executing [[email protected]:1] GotoIf(“SIP/callwithus-00000003”, “0?blacklisted”) in new stack
    — Executing [[email protected]:2] Return(“SIP/callwithus-00000003”, “”) in new stack
    — Executing [[email protected]:3] ExecIf(“SIP/callwithus-00000003”, “0 ?Set(CALLERID(name)=+33590326014)”) in new stack
    — Executing [[email protected]:4] Set(“SIP/callwithus-00000003”, “__CALLINGPRES_SV=allowed_not_screened”) in new stack
    — Executing [[email protected]:5] Set(“SIP/callwithus-00000003”, “CALLERPRES()=allowed_not_screened”) in new stack
    — Executing [[email protected]:6] Goto(“SIP/callwithus-00000003”, “custom-a2billing,s,1”) in new stack
    — Goto (custom-a2billing,s,1)
    — Executing [[email protected]:1] Answer(“SIP/callwithus-00000003”, “”) in new stack
    == Spawn extension (custom-a2billing, s, 2) exited non-zero on ‘SIP/callwithus-00000003’
    and i have this in my extensions_custom.conf

    exten => s,1,Answer
    exten => s,2,Wait,2
    exten => s,3,DeadAGI(a2billing.php)
    exten => s,4,Wait,2
    exten => s,5,Hangup

    if a i try with hold forever i do have sound in return but not with a2billing

    do you have any clues



  81. matt Post author

    You should see the a2billing.php script being called in the debug log you posted, which I do not see, It looks like the a2billing.php script and libraries are not installed correctly.

  82. Kelly

    Hi Matt,
    Thank for this post. I configure a inbound number, when I make a call, the call go in a2billing. But when I want to connect a sip client softphone with a account of a2billing I have message Forbidden (bad auth).
    the softphone work good with a asterisk extension.
    I must setting the ip adress for work with a2billing?

  83. matt Post author

    If you are not using Asterisk realtime did you click on the button in A2Billing that says ‘build sip/iax config files’ (or something like that …)

  84. yan

    Hi matt

    i try to set up an IAX billing trunk with a2billing;
    i have 2 server A and B .
    on server A i have extension from 10000 and server B from 20000
    without a2billing i can ring phones on both sides throuhg IAX channels.
    a2billing is on server A with a trunk the IP of server B for route gateway.
    then when i call an ext 20000 i have a2billing deadagi asking for pin number .
    but then i have extension not found .
    could you help me on this.


  85. matt Post author

    I’m not too sure how you’d do that. I think you’d need to turn on the a2billing debugging to see what it was trying to do.

    Have you set up an IAX trunk in a2billing which connects to server B?

  86. Cassio Simoes

    Hi Matt,

    How do I make a2billing bill FreePBX existing trunks only?

    I don’t want to route calls through a2billing, I want only it to keep a record of calls (and their prices) inside a2billing, but made from FreePBX extensions to FreePBX (SIP, DAHDI and CUSTOM) trunks.

    Any help is appreciated,



  87. Matt Newcombe Post author

    Hi Cassio

    Unfortunately, because of the way a2billing works, you can’t do that. You need to feed the call through a2billing to get it to bill for the calls. A2Billing doesn’t read CDR’s it actually handles the call and rates/bills for it while the call is being processed.

    Regards – Matt

  88. Cassio Simoes

    Thanks Matt, so I thought so.

    Can you recommend any free (or cheap) software that does that?

    I’ve already searched a lot but didn’t find the final solution yet..


  89. Cassio Simoes

    Hi again Matt,

    I thought a2billing worked like a gateway, and outgoing calls should be routed through pre-configured trunks in it, but now I understand it only collects informations through the dial plan and the call actually are output directly from the trunks within freepbx (please correct me if I’m wrong).

    That said, it will then perfectly fit my needs and you may ignore my last question.

    Thank you for your time.

    Best regards!


  90. Matt Newcombe Post author

    Hi Cassio

    No, that’s not correct. A2billing is mainly a PHP script that actually processes the call in real time. The call must be passed to the PHP script by the dial plan for processing.

    Cheers Matt

  91. Cassio Simoes

    Thank you for your reply.

    I am required to create customers, in a2billing choose whether prepaid or postpaid, create account code at each extension, etc. .. Or is there a simpler way to make a simple billing system based only on the caller ID extension or something like that?

    I don’t need the balance part, etc, I just need to know how much each extension of a company PABX spends monthly on calls.

    Also, can a2billing also generate reports based on the PINs used in freepbx?

    Anyway, I’ve followed your other tutorial ( but I can’t get calls to get calls to go out, I get the “currently unavailable” message, but my trunk is correctly setup in freepbx (I can call out through it directly)…

    Thanks Matt

  92. Matt Newcombe Post author

    That’s pretty much what you’d have to do. You don’t need to create multiple customers if you only need a group total. Multiple extensions could use the same account code (which would mean the calls are logged against the same a2billing account)

    It’s difficult to know why the calls are not working. Initially I would try creating a separate a2billing sip user and check calls are working that way. Then try passing the calls from an extension.

    There are too many potential problems to guess though. Check your rate cards are setup OK like this –

  93. Cassio Simoes

    OK, got it.

    About the account balance, is making an enormous refill the most elegant way to go with? Or is there a more proper way to do it?

  94. Matt Newcombe Post author

    It’s not great but I’d make them post pay customers with a large credit limit, then add a credit at the end of the month for the amount used.

  95. Cassio Simoes

    Just one more thing, I’m getting 0 calls on a2billing CDR report, although I have 10 calls in trunk reports as follows:
    0.0000 0 sec 10 10

    Any idea what could be causing this?


  96. Cassio Simoes

    Mark, sorry to bother you again, I just can’t find the solution for this.

    I have a custom trunk in FreePBX that I must use to dial out, it’s Local/[email protected]

    The FreePBX trunk descriptive name is Consulta-Local, so I’ve put in a2billing’s trunk provider IP “Consulta-Local”. I’ve set the technology to Local, tried also with SIP but I get another error (this custom trunk is chan_dongle actually).

    But if I try to dial, I get:

    No such extension/context [email protected] while calling Local channel

    If I set Provider IP to g2 and technology to DAHDI, it correctly dials out through DAHDI group 2 though, so it just doesn’t work with the trunk name.

    What am I missing?

    Thanks Mark!

    Best Regards


  97. Nikie

    Hi there,

    I was wondering if you could help me out here.
    I am using latest FreePBX ( and latest A2B.
    I am trying to configure normal callback (not CID callback) so when some calls in the system will ask for pin & destination number, it will hang up and call the user, provided his authentication worked.
    I have done the Custom Destinations (in FPBX) as per your guide and although the CID-callback works (does not answer and calls the user prompting him to enter his destination)….the simple callback does not work properly. When the incoming call comes, the system answers, asks for authentication and then for destionation. It then *calls* the destination (as in normal CCards mode) without hanging up and calling the user.

    Any ideas what I am doing wrong? By the way I’m using separate agi-conf files in each case.

    Thank you

Comments are closed.