sangoma / switchy

async FreeSWITCH cluster control
https://switchy.readthedocs.io/en/latest/
Mozilla Public License 2.0
72 stars 18 forks source link

Flask-like routes API #46

Closed goodboy closed 8 years ago

goodboy commented 8 years ago

We already have this implemented in the example auto-dialler. I propose we include it as a built-in Router app.

The jist of it is an API like:

@Router.route('811', filename='ivr-hello.wav')
@Router.route('911', filename='ivr-contact_system_administrator.wav')
def playback_file(match, app, sess, filename):
    """Play back a media file by according to the dialled extension.
    Note: You could also lookup an external database / extension list based
          on the `match` received here.
    """
    log.info("'{}': Matched on DTMF sequence '{}'".format(
        sess.uuid, match.group()))
    log.info("'{}': Playing file {}".format(sess.uuid, filename))
    play_filename = "{}/{}".format(app.sound_dir, filename)
    sess.call.vars['playing'] = True
    sess.playback(play_filename)

@Router.route('0(.*)#', profile='internal', proxy='myproxy.com:5060')
def bridge_to_dest(match, app, sess, profile, proxy):
    """Bridge call to a remote destination.
    WARNING:
        The host/IP informations here are examples and should be replaced
        by valid destinations.
    """
    # get the digits between '9' and '#' (see the `re` module)
    extension = match.group(1)

    # bridge the call to your PBX using parsed extension
    sess.bridge(
        dest_url='{}@mypbx.com:5060'.format(extension),
        proxy=proxy,
        profile=profile,
    )

It'll need docs too.