python - Create own IVR that will access Database -


i'm interning company , have been tasked researching methods of using telephony. goal provide our clients ability call in , through ivr-prompted questions, information back. information our database.

i have done using twilio , small python app. i'm looking do, except cost factor can bit high, if have 30,000+ clients calling minutes on end.

my goal find way replicate i've done twilio, on our own server. i've found options asterisk , incrediblepbx, because limited knowledge of linux, every error run results in scouring internet answers. ultimately, i'm not sure if i'm heading in right direction.

this example of i'd accomplish:

client calls number. they're directed provide account number, (possibly phone number) @ point take information , talk database. gathering information relay client status of account etc.

questions: hoping use google voice route calls similar twilio, possible? alternatively, company switch voip , same thing?

if move away twilio, can asterisk perform necessary tasks? receiving calls , running app gather database information.

current code twilio, in python:

from flask import flask, request, redirect  import twilio.twiml  import json  urllib.request import urlopen     app = flask(__name__)  callers = {      "+": "nicholas",  }     @app.route("/", methods=['get', 'post'])  def initial():      # caller's phone number incoming twilio request      from_number = request.values.get('from', none)      resp = twilio.twiml.response()         # if caller know:      if from_number in callers:          # greet caller name          caller = callers[from_number]      else:          caller = ""        resp = twilio.twiml.response()      resp.say("hello " + caller)      resp.say("thank calling.")      your_number = list(from_number)      del your_number[0]      del your_number[0]      resp.say("you calling from: ")      x = 0      while x < len(your_number):          resp.say(your_number[x])          x += 1        print("please enter neighborhood i.d. you're looking for.")      resp.gather(numdigits=1, action="/handle-first", method="post") g:      	g.say("please enter neighborhood i.d. you're looking for.")        return str(resp)    @app.route("/handle-first", methods=['get', 'post'])  def handle_key():      digit_pressed = request.values.get('digits', '')      resp = twilio.twiml.response()      url = 'http://localhost/...'      response = urlopen(url)      data = json.loads(response.readall().decode('utf-8'))         current = data['rows'][0]['neighborhood']      print(current)      resp.say("you have chosen " + current + "as neighborhood.")      resp.gather(numdigits=1, action="/handle-second", method="post") h:          h.say("press 1 choose neighborhood?")        return str(resp)    @app.route("/handle-second", methods=['get', 'post'])  def handle_key2():      digit_pressed = request.values.get('digits', '')      resp = twilio.twiml.response()      if digit_pressed == "1":          return redirect("/")        else:          resp.say("thank calling. good-bye.")          return str(resp)       if __name__ == "__main__":      app.run(debug=true)

asterisk fundamentally different twilio, can opposites. track seeking follow of asterisk dialplan combination of agi. agi asterisk gateway interface, , enable way interact asterisk via simple scripting mechanism. api simple , there whole range of ready made libraries can use. let's put way, when comes agi, pick poison - php, python, java, ruby - available.

my personal favorite, , many in asterisk world well, php - lgpl component called php-agi. it's old , has been around years, works versions of asterisk. if wish walk on bleeding edge , require stronger call control, can go ari (asterisk rest interface), however, judging requirement - that's overkill.

you can read bit agi development php @ link:

https://www.packtpub.com/books/content/asterisk-gateway-interface-scripting-php

(shameful plug - wrote book)

in addition, can refer following presentation additional information (again, own presentation) - it's little old, still valid in terms of concept , usage:

http://osdc.org.il/2006/html/asterisk_agi_programming.ppt

good luck


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -