Can Asterisk interact with customer database?

Good morning! I am a developer whom is new to phone systems, and am curious to know if Asterisk can support my current need for a project.

I am looking to set up a phone system which interacts with my customer database. The workflow I envision looks something like this:

Customers calls my business line -> PBX checks caller ID to obtain their number -> PBX sends number (over some protocol) to external database -> Database checks for that number against existing customers -> IF it finds a match, the database sends (presumably via the same protocol as before) an extension back to the PBX to connect them to their specific service representative. If no match is found, connect them to the next available representative.

In short, I want a dynamic dial plan based on input from an external database. With that, I have a few questions:

1). Is this possible with Asterisk?
2). On a scale of ā€œhelloWorldā€ to 150 gB AAA video game title, how difficult would this be to implement?
3). What protocols does asterisk support to achieve this?

Thank you in advance for your comments and time! looking forward to learning a new skill!

I think it is not a good idea to call an external database when a call comes in, unless you know how to asynchronously update the display. The problem is, if there is a communication problem or something is wrong with the database, no calls get processed and you canā€™t wait until an internet connection times out.

If you keep a local database or simply use astdb.sqlite3 and regularly update it, you should be fine. Itā€™s relatively straightforward to implement this.

1 Like

Yes you can totally do this.

Look at func_odbc, you can define a custom sql command to lookup callers in your external database.

Iā€™d say this is pretty easy, if you look for ā€œAsterisk the definitive guideā€ on google you should find the web version of the book and it has a chapter on ODBC.

2 Likes
  1. Yes.
  2. Pretty simple if you have programming skills.
  3. You can do this using the ODBC functions in the dialplan ā€˜languageā€™ ā€“ but I wouldnā€™t.

I would do this by writing an ā€˜externalā€™ program and calling it from the dialplan using the agi() function. This way you are using a ā€˜realā€™ programming language (C, Perl, PHP, Python, etc) and can use real programming language features like a debugger and have better access to error handling.

Using the ODBC functions always looks messy and fragile to me. I like having a nice little black box I can call so my dialplan can be nice an simple like:

[customer-service]
        exten = _x.,1,         verbose(1,[${EXTEN}@${CONTEXT}!${ANI}])
        same = n,		       agi(lookup-cs-rep)
        same = n,              goto(representative,${REP-EXTEN},1)

Where lookup-cs-rep would:

  1. Connect to the database.
  2. Lookup the representativeā€™s extension in the database.
  3. Set a channel variable (REP-EXTEN) with the representativeā€™s extension or the extension of the representative queue if the customer does not have an assigned rep.
1 Like

Extremely simple, I made this quick code you can adapt to your needs, it will serve you as reference

1 Like

Thank you all for your comments! I am working on implementing this and will report back!

usually u need to get an api to data base

in dial plan you could use the curl function something like this

same => n,Set(curltmp={CURL({serverurl}/RegistrationRest/}) ;CHECK IF THERE ARE EVENTS

etc

I work with Microsoft Sql Server via php and AGI. Also, as has already been noted, it is possible to interact by means of odbc (I did not manage to execute stored procedures with the asterisk odbc interface, just queries).

This is incredibly helpful, thank you! I have asterisk running now and have written a script in python that is accessed by AGI. I can confirm that the python is working and can show the new extension using this line

sys.stdout.write(ā€˜verbose %s 0 \nā€™ % r.content)

where r.content is the new extension.

But this only writes the variable to the console, how do I write this to a system variable accessible to the dialplan?

Good afternoon everyone,

Just to follow up, I was able to get this working, had a typo in the dialplan (that took me 3 days to find!) Thank you again for all your help!

best,
Chris

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.