Exemple #1
0
def conference_call_api(conference_name):
    """
    Parameters -
    to : The number to be called.
    clid : The caller id to be used when making the call.

    1. Make an outbound call
    2. Put the call in the conference
    """
    if not config.ALLOW_OUTBOUND_PSTN:
        return jsonify(success=False, message='Calls are disabled')

    if conference_exists(conference_name):
        to_number = request.form.get('to', None)
        clid = request.form.get('clid', config.PLIVO_CALLER_ID)
        answer_url = url_for('conf',
                             _external=True,
                             conference_name=conference_name)
        plivo_conn = get_plivo_connection()
        status, _ = plivo_conn.make_call({
            'to': to_number,
            'from': clid,
            'answer_url': answer_url,
            'answer_method': 'POST'
        })
        if status == 201:
            return jsonify(success=True, message='Call has been queued')
    return jsonify(success=False, message='Call could not be made')
Exemple #2
0
def create_plivo_endpoint(conference_name, app_id):
    """
    Create a Plivo endpoint and attach the application
    to it. This endpoint is used to register to Plivo
    using WebRTC or SIP.

    Returns the endpoint username created on Plivo.
    """

    plivo_conn = get_plivo_connection()
    _, response = plivo_conn.create_endpoint({'username': conference_name, 'password': conference_name, 'alias': conference_name, 'app_id': app_id})
    endpoint_username = response['username']
    return endpoint_username
Exemple #3
0
def create_plivo_endpoint(conference_name, app_id):
    """
    Create a Plivo endpoint and attach the application
    to it. This endpoint is used to register to Plivo
    using WebRTC or SIP.

    Returns the endpoint username created on Plivo.
    """

    plivo_conn = get_plivo_connection()
    _, response = plivo_conn.create_endpoint({'username': conference_name, 'password': conference_name, 'alias': conference_name, 'app_id': app_id})
    endpoint_username = response['username']
    return endpoint_username
Exemple #4
0
def create_plivo_application(conference_name):
    """
    Create a Plivo application and set the answer URL to the conference URL.
    This makes sure that when the call is answered the Conference XML will be
    executed by Plivo.

    Returns the id of the application created on Plivo.
    """

    answer_url = url_for('conf', _external=True, conference_name=conference_name)
    plivo_conn = get_plivo_connection()
    _, response = plivo_conn.create_application({'app_name': conference_name, 'answer_url': answer_url, 'answer_method': 'POST'})
    app_id = response['app_id']
    return app_id
Exemple #5
0
def create_plivo_application(conference_name):
    """
    Create a Plivo application and set the answer URL to the conference URL.
    This makes sure that when the call is answered the Conference XML will be
    executed by Plivo.

    Returns the id of the application created on Plivo.
    """

    answer_url = url_for('conf', _external=True, conference_name=conference_name)
    plivo_conn = get_plivo_connection()
    _, response = plivo_conn.create_application({'app_name': conference_name, 'answer_url': answer_url, 'answer_method': 'POST'})
    app_id = response['app_id']
    return app_id
Exemple #6
0
def attach_inbound_did(app_id):
    """
    Rent a Plivo US DID and attach it the conference application.
    """
    if not config.ALLOW_INBOUND_DID:
        return None

    plivo_conn = get_plivo_connection()
    status, response = plivo_conn.get_number_group({'country_iso': 'US'})
    try:
        group_id = response['objects'][0]['group_id']
        status, response = plivo_conn.rent_from_number_group({'group_id': group_id, 'quantity': 1, 'app_id': app_id})
        number_rented = response['numbers'][0]['number']
        return number_rented
    except Exception as e:
        return None
Exemple #7
0
def attach_inbound_did(app_id):
    """
    Rent a Plivo US DID and attach it the conference application.
    """
    if not config.ALLOW_INBOUND_DID:
        return None

    plivo_conn = get_plivo_connection()
    status, response = plivo_conn.get_number_group({'country_iso': 'US'})
    try:
        group_id = response['objects'][0]['group_id']
        status, response = plivo_conn.rent_from_number_group({'group_id': group_id, 'quantity': 1, 'app_id': app_id})
        number_rented = response['numbers'][0]['number']
        return number_rented
    except Exception as e:
        return None
Exemple #8
0
def conference_call_api(conference_name):
    """
    Parameters -
    to : The number to be called.
    clid : The caller id to be used when making the call.

    1. Make an outbound call
    2. Put the call in the conference
    """
    if not config.ALLOW_OUTBOUND_PSTN:
        return jsonify(success=False, message='Calls are disabled')

    if conference_exists(conference_name):
        to_number = request.form.get('to', None)
        clid = request.form.get('clid', config.PLIVO_CALLER_ID)
        answer_url = url_for('conf', _external=True, conference_name=conference_name)
        plivo_conn = get_plivo_connection()
        status, _ = plivo_conn.make_call({'to': to_number, 'from': clid, 'answer_url': answer_url, 'answer_method': 'POST'})
        if status == 201:
            return jsonify(success=True, message='Call has been queued')
    return jsonify(success=False, message='Call could not be made')