sudo apt update
sudo apt install -y \
build-essential \
libncurses5-dev \
libssl-dev \
libxml2-dev \
libsqlite3-dev \
uuid-dev \
libjansson-dev \
libedit-dev \
libcurl4-openssl-dev \
libspeexdsp-dev \
pkg-config \
subversion \
wget \
git
cd /usr/src
sudo wget https://downloads.asterisk.org/pub/telephony/asterisk/asterisk-20-current.tar.gz
sudo tar xzf asterisk-20-current.tar.gz
cd asterisk-20.*
sudo contrib/scripts/install_prereq install
sudo apt install -y build-essential wget curl xmlstarlet bash \
libopus-dev libssl-dev
sudo apt install -y xmlstarlet bash
sudo apt install -y libcurl4-openssl-dev
sudo ./configure
sudo make menuselect
sudo make -j$(nproc)
sudo make install
sudo make samples
sudo make config
Enable:
Codec Translators → codec_opus
Edit:
sudo nano /etc/asterisk/pjsip.conf
[sessiontelecoms-auth]
type = auth
auth_type = userpass
username = SIP_CLIENT_USERNAME
password = SIP_CLIENT_PASSWORD
[sessiontelecoms-registration]
type = registration
transport = transport-tcp
outbound_auth = sessiontelecoms-auth
server_uri = sip:SIP_CLIENT_DOMAIN
client_uri = sip:SIP_CLIENT_USERNAME@SIP_CLIENT_DOMAIN
retry_interval = 60
[sessiontelecoms-aor]
type = aor
contact = sip:SIP_CLIENT_DOMAIN
[sessiontelecoms-endpoint]
type = endpoint
transport = transport-tcp
context = from-external
disallow = all
allow = opus,ulaw,alaw
outbound_auth = sessiontelecoms-auth
aors = sessiontelecoms-aor
from_user = SIP_CLIENT_USERNAME
from_domain = SIP_CLIENT_DOMAIN
[transport-tcp]
type = transport
protocol = tcp
bind = 0.0.0.0
[transport-wss]
type = transport
protocol = wss
bind = 0.0.0.0:8089
[6001]
type = auth
auth_type = userpass
username = 6001
password = supersecret
[6001]
type = aor
max_contacts = 1
remove_existing = yes
[6001]
type = endpoint
context = from-internal
disallow = all
allow = opus,ulaw,alaw
auth = 6001
aors = 6001
transport = transport-wss
webrtc = yes
direct_media = no
Edit:
sudo nano /etc/asterisk/extensions.conf
[from-internal]
exten => _+X.,1,NoOp(Outbound call from ${CALLERID(num)} to ${EXTEN})
same => n,Set(CALL_ID=${EPOCH}-${CHANNEL(name)})
same => n,Set(__CALL_ID=${EPOCH}-${CHANNEL(name)})
same => n,Set(__FROM=${CALLERID(num)})
same => n,Set(__TO=${EXTEN})
same => n,Set(__WEBHOOK_URL=${PJSIP_HEADER(read,X-Webhook-URL)})
same => n,ExecIf($["${WEBHOOK_URL}"=""]?Hangup(403))
same => n,Set(RECORDING_FILE=/var/spool/asterisk/monitor/${EPOCH}-${FROM}-${TO})
same => n,Set(__RECORDING_FILE=${RECORDING_FILE})
same => n,MixMonitor(${RECORDING_FILE}.wav,b)
same => n,System(curl -s -m 1 -X POST -H "Content-Type: application/json" \
-d '{"event":"start","call_id":"'"${CALL_ID}"'","from":"'"${FROM}"'","to":"'"${TO}"'","recording":"'"${RECORDING_FILE}.wav"'"}' \
${WEBHOOK_URL} &)
same => n,Dial(PJSIP/${EXTEN}@sessiontelecoms-endpoint)
same => n,Set(__FINAL_DIALSTATUS=${DIALSTATUS})
same => n,Hangup()
exten => h,1,NoOp(Call ended)
same => n,System(curl -s -m 1 -X POST -H "Content-Type: application/json" \
-d '{"event":"end","call_id":"'"${CALL_ID}"'","from":"'"${FROM}"'","to":"'"${TO}"'","dialstatus":"'"${FINAL_DIALSTATUS}"'","hangupcause":"'"${HANGUPCAUSE}"'","duration":"'"${CDR(duration)}"'","billsec":"'"${CDR(billsec)}"'","recording":"'"${RECORDING_FILE}.wav"'"}' \
${WEBHOOK_URL} &)
[from-internal]
exten => _+X.,1,NoOp(Outbound call from ${CALLERID(num)} to ${EXTEN})
same => n,Set(CALL_ID=${EPOCH}-${CHANNEL(name)})
same => n,Set(__CALL_ID=${EPOCH}-${CHANNEL(name)})
same => n,Set(__FROM=${CALLERID(num)})
same => n,Set(__TO=${EXTEN})
same => n,Set(__WEBHOOK_URL=${PJSIP_HEADER(read,X-Webhook-URL)})
same => n,ExecIf($["${WEBHOOK_URL}"=""]?Hangup(403))
same => n,System(curl -s -m 1 -X POST -H "Content-Type: application/json" \
-d '{"event":"start","call_id":"'"${CALL_ID}"'","from":"'"${FROM}"'","to":"'"${TO}"'"}' \
${WEBHOOK_URL} &)
same => n,Dial(PJSIP/${EXTEN}@sessiontelecoms-endpoint)
same => n,Set(__FINAL_DIALSTATUS=${DIALSTATUS})
same => n,Hangup()
exten => h,1,NoOp(Call ended)
same => n,System(curl -s -m 1 -X POST -H "Content-Type: application/json" \
-d '{"event":"end","call_id":"'"${CALL_ID}"'","from":"'"${FROM}"'","to":"'"${TO}"'","dialstatus":"'"${FINAL_DIALSTATUS}"'","hangupcause":"'"${HANGUPCAUSE}"'","duration":"'"${CDR(duration)}"'","billsec":"'"${CDR(billsec)}"'"}' \
${WEBHOOK_URL} &)
Edit:
sudo nano /etc/asterisk/http.conf
[general]
servername=Asterisk
enabled=yes
bindaddr=0.0.0.0
Edit:
sudo nano /etc/rtp.conf
[general]
rtpstart=10000
rtpend=20000
icesupport=yes
stunaddr=stun.l.google.com:19302
You can now start Asterisk:
sudo systemctl start asterisk
sudo asterisk -rvvv