Adding Lenny To FreePBX

I first heard about Lenny from an episode of  The Snow Plow Show at   And I realized I had to have Lenny on my asterisk server.  I followed a howto at however it wasn’t as complete as I liked,  I still had to figure some stuff out.     Setting Lenny up is relatively easy.     Just follow the instructions below and it will get you going.   🙂


Step 1

Create the Lenny custom context in Asterisk

SSH into freepbx and edit extensions_custom.conf with your favorite text editor

Then add the following lines of code.

exten => talk,1,Set(i=${IF($["0${i}"="016"]?7:$[0${i}+1])})
same => n,ExecIf($[${i}=1]?MixMonitor(${UNIQUEID}.wav))
same => n,Playback(Lenny/Lenny${i})
same => n,BackgroundDetect(Lenny/backgroundnoise,1500)  

Save and exit the extensions_custom.conf file

Step 2

Use your favorite SCP client to SCP the Lenny sound files into /var/lib/asterisk/sounds/Lenny

Note:  If you are using FreePBX 13, the sound directory is /var/lib/asterisk/sounds/en/Lenny.

You can download the sound files here Lenny Sound Files

Step 3

Now youll need to create a custom destination.

Under the FreePBX interface choose Admin-> Custom Destinations.

Add a new Custom Destination with these settings.

Custom Destination: Lenny,talk,1

Description: Lenny


Click Submit Changes followed by the apply changes button.

Lenny is set up at this point.

Step 4.

Create a new virtual extension and give it the extension number of your choice.


Then click Advanced and look for optional destinations and set it just like this.  advanced

Save and Apply Settings.  And you are done.    Now you can dial the extension you assigned and talk to Lenny.

C*NET Configuration with FreePBX


I had been fighting with vanilla asterisk a long time trying to get the perfect C*NET configuration.  And I found there wasn’t a guide on how to get C*NET going with FreePBX.    I like FreePBX because it makes configuration of Asterisk easy.  It runs on minimal hardware and works relatively well.     This post covers the basic set up of configuring FreePBX to connect to C*NET.

Thanks to phonegenius for the initial configuration 🙂


This post assumes you have the following completed beforehand

  1. Followed the instructions at  C*NET The Telephone Collectors Network
  2. Have FreePBX installed
  3. Have Port 4569 opened in your router.


Step 1

Create a new IAX Trunk in FreePBX

Name the trunk cnet-trunk

Nothing needs to be in PEER details


Now go to the Incoming Section and set it up like this

In the user context insert your username you came up with when you signed up for C*NET


Click Submit and then Apply Config

Step 2

Create a custom trunk and name it Local/$OUTNUM@cnet-out


Click Submit and then Apply Config


Now go under custom settings and enter this into Custom Dial String  Local/$OUTNUM$@cnet-out


Step 3

Create an outbound route and name it CNET


Make sure that Local/$OUTNUM$@cnet-out is selected as trunk sequence for matched routes.

Click Submit and then Apply Config

Step 4

Click on Dial Patterns and enter the following in the match pattern



Click Submit and then Apply Config


Step 5

ssh into your FreePBX system with the username root, and the password is the password you defined when you installed FreePBX

Then type nano /etc/asterisk/extensions_custom.conf,  Copy and paste this file into the bottom of extensions_custom.conf.  Modify it to suit your needs.

After you do this just type in asterisk at your prompt and type dialplan reload.

You’ll be good to go at that point and you can start making calls on C*NET


;Put this file at the bottom of extensions_custom.conf

; Collectors' Network
exten => s,1,Set(
; Check to see if ARG1 is preceded by a "+"
exten => s,2,GotoIf($[ ${ARG1:0:1} = "+"]?startloop) 
; Skip next line if it already is prefixed by a plus;
; Otherwise, add one to the beginning.
exten => s,3,Set(ARG1=+${ARG1})
exten => s,4(startloop),Set(ENUM=${ENUMLOOKUP(${ARG1},ALL,,1,})
;exten =>s,4(startloop),Set(ENUM=${ENUMLOOKUP(${ARG1},ALL,,})
; Sanity check the return, make sure there's something in there.
; If not, send it to CONTINUE.
exten => s,5,GotoIf($[${LEN(${ENUM})} = 0 ]?continue) 
; If the return includes the word SIP, go to SIPURI
exten => s,6,GotoIf($[${ENUM:0:3} = sip ]?sipuri) 
; Otherwise, if the return includes the word IAX, go IAXURI 
exten => s,7,GotoIf($[${ENUM:0:3} = iax ]?iaxuri) 
; And, if the return includes the word H323, send it to H323URI 
exten => s,8,GotoIf($[${ENUM:0:3} = h32 ]?h323uri) 
; If we're here, it's not a protocol we know about. Let's increment the pointer 
; and if it's more than ENUMCOUNT, we know we've run out of options.
; This is the generic CANT BE ROUTED spot 
exten => s,9(continue),Macro(invalid-office-code,${ARG1}) 
exten => s,10,Wait(5) 
exten => s,11,Hangup 
; If the prefix is 'sip:'...
exten => s,12(sipuri),Set(DIALSTR=SIP/${ENUM:4})
exten => s,13,Goto(dodial)
; If it's IAX2...
exten => s,14(iaxuri),Set(DIALSTR=IAX2/${ENUM:5})
exten => s,15,Goto(dodial)
; Or even if it's H323.
exten => s,16(h323uri),Set(DIALSTR=H323/${ENUM:5})
; And this is where we end up if we actually CAN route the call.
exten => s,17(dodial),Dial(${DIALSTR})
exten => s,18,Goto(q-${DIALSTATUS},1)
exten => q-CONGESTION,1,Macro(congestion)
exten => q-CONGESTION,n,Hangup
exten => q-CHANUNAVAIL,1,Macro(chanunavail)
exten => q-CHANUNAVAIL,n,Hangup
exten => q-BUSY,1,Busy
exten => q-BUSY,n,Hangup
exten => _q-.,1,Hangup()



exten => _1NXXXXXX,1,Macro(dialcnet,${EXTEN})
exten => _1NXXXXXX,2,Congestion

exten => _X.,1,Macro(dialcnet,${EXTEN})
exten => _X.,2,Congestion


;This context is called from the IAX trunk definition defined within the FreePBX environment.
;Select incoming called number blocks are rewritten to conform to the local 3 or4 digit dial plan
;and then passed on to contexts managed by FreePBX.
; 555xxxx - Direct station calls to your phones - replace 555 with your office code

;3 digit ext numbers
;exten => _1555xxxx,1,set(destnum=${EXTEN:-3}) ;strip 1555x to match local 3 digit dial plan
;exten => _1555xxxx,n,SIPAddHeader("Alert-Info:<>") 
;exten => _1555xxxx,n,Gosub(app-blacklist-check,s,1)
;exten => _1555xxxx,n,goto(from-internal,${destnum},1)

;4 digit ext numbers
exten => _1555xxxx,1,set(destnum=${EXTEN:-4}) ;strip 1555 to match local 4 digit dial plan
exten => _1555xxxx,n,SIPAddHeader("Alert-Info:<>")
exten => _1555xxxx,n,Gosub(app-blacklist-check,s,1)
exten => _1555xxxx,n,goto(from-internal,${destnum},1)