Skip to main content

FreePBX

FreePBX can be integrated with Fone AI using custom SIP trunk connection.

Have the following information in hand from your Fone AI Console and FreePBX service:

  • API_KEY – Create one if needed from the API Keys page
  • PUBLIC_IP – Your FreePBX server’s public IP. You can get it from executing curl ifconfig.me using terminal or visting IP Chicken from that server.
  • BINDING_PORT – The SIP binding port (usually 5060)
  • LOCAL_NET – If NAT is applicable, provide the local subnet
  • SIP_USERNAME – Your SIP username. Available in the SIP Integration page.
  • SIP_PASSWORD – Your SIP password. Available in the SIP Integration page.

FreePBX Configurations​

Go to Configuration File Editor using Admin ➜ Config Edit ➜ Asterisk Custom Configuration Files.

Append the below codes to the respective files

Custom AOR

pjsip.aor_custom.conf
[ai-aor]
type=aor
max_contacts=20
contact=sip:sip.fone.ai:5060

Custom Auth

pjsip.auth_custom.conf
[ai-auth]
type=auth
auth_type=userpass
username=SIP_USERNAME ; <-- Replace with your SIP username
password=SIP_PASSWORD ; <-- Replace with your SIP password

Custom Endpoint

pjsip.endpoint_custom.conf
[ai-endpoint]
type=endpoint
context=ai-transfer
disallow=all
direct_media=no
allow=ulaw,alaw,gsm
transport=transport-udp-ai
outbound_auth=ai-auth
aors=ai-aor

Custom Registration

pjsip.registration_custom.conf
[ai-registration]
type=registration
outbound_auth=ai-auth
server_uri=sip:sip.fone.ai:5060
client_uri=sip:ai@PUBLIC_IP:BINDING_PORT ; <-- Replace with your public IP and binding port
contact_user=ai
retry_interval=60

Custom Transports

pjsip.transports_custom.conf
[transport-udp-ai]
type=transport
protocol=udp
external_media_address=PUBLIC_IP ; <-- Replace with your public IP
;local_net=LOCAL_NET ; <-- Replace with your local net if applicable
external_signaling_address=PUBLIC_IP ; <-- Replace with your public IP
bind=0.0.0.0:BINDING_PORT ; <-- Replace with your binding port

Custom Extensions

extensions_custom.conf
[handler]
exten => addheader,1,Set(PJSIP_HEADER(add,X-api-key)=API_KEY) ; <-- Replace with your API Key
;same => n,Set(PJSIP_HEADER(add,X-custom)={"key1":"value1","key2":"value2"})
same => n, Return()

[ai]
exten => _XXXXXXXX.,1,NoOP()
same => n,Dial(PJSIP/${EXTEN}@ai-endpoint,,b(handler^addheader^1))
same => n,Hangup()

Apply Config

Click on the Apply Config button to the right of the topbar to apply the modified configuration

After you set up the configurations, you can dial into the AI through DID or through internal extensions.


For Inbound DIDs​

Create a Custom Trunk​

Create a custom trunk by going to Connectivity ➜ Trunks. Click ✚ Add Trunk ➜ ✚ Add Custom Trunk.

In the General tab of the Add CUSTOM Trunk, enter the Trunk Name.

Under Custom Settings, enter the Custom Dial String as:

Local/$OUTNUM$@ai

This will invoke the local ai dialplan context created in extensions_custom.conf.

Click the Submit button at the bottom to create the custom trunk.

Create an Outbound Route​

Create an outbound route by going to Connectivity ➜ Outbound Routes. Click ✚ Add Outbound Route.

In the Route Settings tab:

  • Enter the Route Name
  • Set Trunk Sequence for Matched Routes to the Custom Trunk created earlier

In the Dial Patterns tab:

  • Set Prefix to 0000
  • Set Match Pattern to X.

Click the Submit button at the bottom to save the route.

Create a Misc Destination​

Go to Applications ➜ Misc Destinations. Click ✚ Add Misc Destination.

In the form:

  • Set Description appropriately (e.g., AI Misc Destination)
  • Set Dial to:
    0000{campaign_extension}

If you used a different prefix, prepend that to the Campaign Extension from the Fone AI console.
For example, if the prefix is 0000 and the campaign extension is 4140515644, set Dial to:

00004140515644

Click Submit to create the Misc Destination.

Create an Inbound Route​

Go to Connectivity ➜ Inbound Routes. Click ✚ Add Inbound Route.

In the form:

  • Set the Description
  • Set DID Number to your incoming number
  • Under Set Destination, choose Misc Destinations and select the AI destination created earlier

Click on the Apply Config button to the right of the topbar to apply the modified configuration

Once done, calling the DID will route the call to the Fone AI campaign through FreePBX.


Direct Dial Through an Extension​

You can also directly dial the AI from an extension by navigating to Connectivity ➜ Extensions

Create a new extension or edit an existing one.

In the Advanced tab of the extension, scroll down to find the Dial field under the Edit Extension form group. Set the Dial value to:

Local/{campaign_extension}@ai

For e.g., Local/4140515644@ai to connect with the campaign 4140515644.

Click Submit, then click the Apply Config button at the top right to apply the changes.

Once done, calling this extension will route the call to the corresponding Fone AI campaign through FreePBX.