Skip to main content

Asterisk

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

Have the following information in hand from your Fone AI Console and Asterisk server:

  • API_KEY – Create one if needed from the API Keys page
  • PUBLIC_IP – Your Asterisk server’s public IP. You can get it from executing curl ifconfig.me using terminal
  • 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.

PJSIP Configuration​

Open the file /etc/asterisk/pjsip.conf
(or wherever your Asterisk SIP config is located)

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

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

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

[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

[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

Dialplan Configuration​

Open the file /etc/asterisk/extensions.conf
(or wherever your Asterisk Extensions is located)

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

Reload and restart​

Go to Asterisk CLI using asterisk -rvv if asterisk is already running. Execute all the three below commands after getting into the CLI:

  • Reload Pjsip using pjsip reload
  • Reload Dialplan using dialplan reload
  • Reload entire Asterisk using core restart now

If asterisk is not up and running, start it using the asterisk command on the terminal and continue.

tip

The EXTEN should be the campaign extension and should be dialled into the ai dialplan context. Read more in the Invoke Campaigns section