Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Ekim
Ekim

Posted on

     

Asterisk AGI short sharing

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>
Enter fullscreen modeExit fullscreen mode

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
Enter fullscreen modeExit fullscreen mode

 
 
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)
Enter fullscreen modeExit fullscreen mode

 
 
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
Enter fullscreen modeExit fullscreen mode

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)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Joined

More fromEkim

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp