Weekly sharing
Hi everyone, I am Ekim, a fresh Bootcamp graduate and an IT helper (I don't dare to call myself a programmer yet). Every Friday, I will share some of the work that I've done over the last week in a bid to get feedbacks from you guys and record my journey to become a programmer.
Previously
Sharing of how I made my own command
Introduction
Today, I am going to start integrating my previous call flow with the use of AGI. To do that, we need the help of AGI (Asterisk Gateway Interface). The reason we might need to do that is that sometimes we want to record every call and insert the call logs into the database. So that, we could know what calls have been made or received. Moreover, the use of database could help us create an IVR , for it could contain all the IVR logic we have.
What is AGI ?
AGI provides an interface between the Asterisk dialplan and an external program that wants to manipulate a channel in the dialplan.
PostgreSQL installation & DB creation
# Install PostgreSQLsudoaptinstallpostgresql postgresql-contrib# start the postgres servicesudoservice postgresql start# Change to user postgres as it can perform all tasks on the databasesudosu postgres# login to the DBpsql# You should see something similar in your terminalpostgres=## Create database# don't miss the colonCREATE Database <your-database-name-here>;# Create an account to manage the database# don't miss the colon and the quotation marksCREATE USER <your-username-here> WITH PASSWORD'your-password-here' SUPERUSER;# Leaving Database and postgres userctrl + d ctrl + d# Try login from the current userpsql-U <user_name>-W-h <hostname> <db_name>
Using AGI in Asterisk
In Asterisk, AGI can be treated as a dialplan application inextensions.conf
. In the following, I will show you how you could use it as a way to insert data into the PostgreSQL database.
In modules.conf
# add the agi moduleload= res_agi.so
In pjsip.conf
[transport-udp-nat]type= transportprotocol= udpbind= 0.0.0.0[calling](!)type=endpointcontext=interaction allow=!all, ulaw, alawdirect_media=notrust_id_outbound=yesrtp_symmetric=yesforce_rport=yesrewrite_contact=yesdevice_state_busy_at=1dtmf_mode=rfc4733[auth-userpass](!)type= auth auth_type= userpass[aor-single-reg](!)type= aormax_contacts= 1[7000](calling)auth=7000aors=7000 callerid= 7000 <7000>[7000](auth-userpass) password= 7000username= 7000[7000](aor-single-reg)[7100](calling)auth=7100aors=7100callerid= 7100 <7100>[7100](auth-userpass)password= 7100username= 7100[7100](aor-single-reg)
In extensions.conf
[interaction]exten= _7X00,1,NoOp(${EXTEN}); setting variablesfordata insertionsame= n,Set(_callInTime=${STRFTIME(,,%Y%b%d-%H%M%S)})same= n,Set(_callerId=${CALLERID(num)})same= n,Set(_extension=${EXTEN})same= n,Set(_callDuration=${CDR(billsec)})same= n,Answersame= n,Dial(PJSIP/${EXTEN},30)same= n,Goto(update_call_duration,s,1)[update_call_duration]; call_log is the agi file, the rest are the argumentsexten= s,1,agi(call_log,${callerId},${callInTime},${extension},${callDuration})same= n,Hangup
In theextensions.conf
, we use theagi
dialplan application. Think of it as running a program likenode abc.js
orpython3 cde.py
.
So, where is our program ?
Actually, we need to go to the defaultagi-bin
path to create the program.
But that would be too much for me today. So, please bear with me and stay tuned for the next week sharing and I will go deeper into theagi
program.
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse