Esempio n. 1
0
def tn_lookup_client():
    bandwidth_client = BandwidthClient(
        phone_number_lookup_basic_auth_user_name=BW_USERNAME,
        phone_number_lookup_basic_auth_password=BW_PASSWORD,
    )
    tn_lookup_client = bandwidth_client.phone_number_lookup_client.client
    return tn_lookup_client
Esempio n. 2
0
def mfa_client():
    bandwidth_client = BandwidthClient(
        multi_factor_auth_basic_auth_user_name=BW_USERNAME,
        multi_factor_auth_basic_auth_password=BW_PASSWORD,
    )
    mfa_client = bandwidth_client.multi_factor_auth_client.mfa
    return mfa_client
Esempio n. 3
0
def web_rtc_client():
    bandwidth_client = BandwidthClient(
        web_rtc_basic_auth_user_name=BW_USERNAME,
        web_rtc_basic_auth_password=BW_PASSWORD,
    )
    web_rtc_client = bandwidth_client.web_rtc_client.client
    return web_rtc_client
Esempio n. 4
0
def messaging_client():
    bandwidth_client = BandwidthClient(
        messaging_basic_auth_user_name=BW_USERNAME,
        messaging_basic_auth_password=BW_PASSWORD,
    )
    messaging_client = bandwidth_client.messaging_client.client
    return messaging_client
Esempio n. 5
0
def voice_client():
    bandwidth_client = BandwidthClient(
        voice_basic_auth_user_name=BW_USERNAME,
        voice_basic_auth_password=BW_PASSWORD,
    )
    voice_client = bandwidth_client.voice_client.client
    return voice_client
Esempio n. 6
0
    MESSAGING_ACCOUNT_ID = os.environ["MESSAGING_ACCOUNT_ID"]
    MESSAGING_API_TOKEN = os.environ["MESSAGING_API_TOKEN"]
    MESSAGING_API_SECRET = os.environ["MESSAGING_API_SECRET"]
    MESSAGING_APPLICATION_ID = os.environ["MESSAGING_APPLICATION_ID"]
    VOICE_ACCOUNT_ID = os.environ["VOICE_ACCOUNT_ID"]
    VOICE_API_USERNAME = os.environ["VOICE_API_USERNAME"]
    VOICE_API_PASSWORD = os.environ["VOICE_API_PASSWORD"]
    VOICE_APPLICATION_ID = os.environ["VOICE_APPLICATION_ID"]
    BASE_URL = os.environ["BASE_URL"]
except:
    print("Please set the environmental variables defined in the README")
    exit(-1)

bandwidth_client = BandwidthClient(
    voice_basic_auth_user_name=VOICE_API_USERNAME,
    voice_basic_auth_password=VOICE_API_PASSWORD,
    messaging_basic_auth_user_name=MESSAGING_API_TOKEN,
    messaging_basic_auth_password=MESSAGING_API_SECRET)
voice_client = bandwidth_client.voice_client.client
messaging_client = bandwidth_client.messaging_client.client

app = Flask(__name__)


@app.route("/", methods=["GET"])
def home_page():
    return "Hello world"


@app.route("/Create/Message", methods=["POST"])
def create_message():
Esempio n. 7
0
import os

try:
    BW_USERNAME = os.environ['BW_USERNAME']
    BW_PASSWORD = os.environ['BW_PASSWORD']
    BW_ACCOUNT_ID = os.environ['BW_ACCOUNT_ID']
    BW_NUMBER = os.environ['BW_NUMBER']
    BW_VOICE_APPLICATION_ID = os.environ['BW_VOICE_APPLICATION_ID']
    BW_MESSAGING_APPLICATION_ID = os.environ['BW_MESSAGING_APPLICATION_ID']
except:
    print("Please set the environmental variables defined in the README")
    exit()

bandwidth_client = BandwidthClient(
    two_factor_auth_basic_auth_user_name=BW_USERNAME,
    two_factor_auth_basic_auth_password=BW_PASSWORD
)
auth_client = bandwidth_client.two_factor_auth_client.mfa

recipient_phone_number = input("Please enter your phone number in E164 format (+15554443333): ")
delivery_method = input("Select your method to receive your 2FA request. Please enter \"voice\" or \"messaging\": ")

if delivery_method == "messaging":
    from_phone = BW_NUMBER
    to_phone = recipient_phone_number
    application_id = BW_MESSAGING_APPLICATION_ID
    scope = "scope"
    digits = 6

    body = TwoFactorCodeRequestSchema(
        mfrom = from_phone,
from bandwidth.exceptions.api_exception import APIException
from bandwidth.webrtc.utils.transfer_util import generate_transfer_bxml
from flask import Flask, request, send_from_directory, Response

config = configparser.ConfigParser()
config.read('config.ini')
try:
    config['bandwidth']['BW_USERNAME']
    config['bandwidth']['BW_PASSWORD']
except Exception as error:
    print("Please set the config variables defined in the README", error)
    exit(-1)

bandwidth_client = BandwidthClient(
    voice_basic_auth_user_name=config['bandwidth']['BW_USERNAME'],
    voice_basic_auth_password=config['bandwidth']['BW_PASSWORD'],
    web_rtc_basic_auth_user_name=config['bandwidth']['BW_USERNAME'],
    web_rtc_basic_auth_password=config['bandwidth']['BW_PASSWORD'],
)

app = Flask(__name__)
# track our "rooms" which includes session IDs and phone call Ids
#  - if not a demo, these would be stored in persistant storage
rooms = {}

# track attendee info for easy mapping
attendees = {}

sessionId = False  # get rid of this
# this needs to be saved from PSTN create_participant until the transfer to WebRTC
#  we will also store the token and pstn call_id within this object
pstnParticipant = False  # get rid of this
Esempio n. 9
0
import json
import string
import os

try:
    VOICE_ACCOUNT_ID = os.environ["VOICE_ACCOUNT_ID"]
    VOICE_API_USERNAME = os.environ["VOICE_API_USERNAME"]
    VOICE_API_PASSWORD = os.environ["VOICE_API_PASSWORD"]
    VOICE_APPLICATION_ID = os.environ["VOICE_APPLICATION_ID"]
    BASE_URL = os.environ["BASE_URL"]
except:
    print("Please set the VOICE environmental variables defined in the README")
    exit(-1)

bandwidth_client = BandwidthClient(
    voice_basic_auth_user_name=VOICE_API_USERNAME,
    voice_basic_auth_password=VOICE_API_PASSWORD)

voice_client = bandwidth_client.voice_client.client

voice_app = Blueprint('voice_app', __name__)


def handle_call_me(to, from_):
    """
    A method that creates an outbound call and asks for a gather to transfer the call

    :param str to: The phone number that received the message
    :param str from_: The phone number that sent the message

    :returns: None
Esempio n. 10
0
    BANDWIDTH_API_USER = os.environ["BANDWIDTH_API_USER"]
    BANDWIDTH_API_PASSWORD = os.environ["BANDWIDTH_API_PASSWORD"]
    # Tokens and secrets are generated through the application page on the dashboard
    BANDWIDTH_MESSAGING_TOKEN = os.environ["BANDWIDTH_MESSAGING_TOKEN"]
    BANDWIDTH_MESSAGING_SECRET = os.environ["BANDWIDTH_MESSAGING_SECRET"]

    # Application ID's created on dashboard (Ex. 123ab-cd4efg5-hijklm67-n8o9pqrst)
    BANDWIDTH_MSG_APPLICATION_ID = os.environ[
        "BANDWIDTH_MESSAGING_APPLICATION_ID"]
except:
    print("Please set the environmental variables defined in the README")
    exit(-1)

bandwidth_client = BandwidthClient(
    voice_basic_auth_user_name=BANDWIDTH_API_USER,
    voice_basic_auth_password=BANDWIDTH_API_PASSWORD,
    messaging_basic_auth_user_name=BANDWIDTH_MESSAGING_TOKEN,
    messaging_basic_auth_password=BANDWIDTH_MESSAGING_SECRET)

app = Flask('__main__')
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
db = SQLAlchemy(app)


class TriviaUser(db.Model):
    """Define our database tables"""
    id = db.Column(db.Integer, primary_key=True)
    phoneNumber = db.Column(db.String(12), unique=True, nullable=False)
    points = db.Column(db.Integer, default=0)
    lives = db.Column(db.Integer, default=5)
    time = db.Column(db.DateTime)
Esempio n. 11
0
try:
    BANDWIDTH_ACCOUNT_ID = os.environ["BANDWIDTH_ACCOUNT_ID"]
    BANDWIDTH_API_USER = os.environ["BANDWIDTH_API_USER"]
    BANDWIDTH_API_PASSWORD = os.environ["BANDWIDTH_API_PASSWORD"]
    BANDWIDTH_VOICE_APPLICATION_ID = os.environ[
        "BANDWIDTH_VOICE_APPLICATION_ID"]
    PERSONAL_NUMBER = os.environ["PERSONAL_NUMBER"]
    BASE_URL = os.environ["BASE_URL"]
    PORT = os.environ["PORT"]
except KeyError:
    print("Please set the environmental variables defined in the README")
    exit(-1)

bandwidth_client = BandwidthClient(
    voice_basic_auth_user_name=BANDWIDTH_API_USER,
    voice_basic_auth_password=BANDWIDTH_API_PASSWORD)

voice_client = bandwidth_client.voice_client.client

voice_routes = Blueprint('voice_routes', __name__)


def createOutboundCall(to, mfrom, callId):
    """
    Create the outbound call
    """
    body = ApiCreateCallRequest()
    body.mfrom = mfrom
    body.to = to
    body.application_id = BANDWIDTH_VOICE_APPLICATION_ID
Esempio n. 12
0
from user import User
from flask import Flask, request, Response, render_template, redirect, url_for
from bandwidth.bandwidth_client import BandwidthClient
from bandwidth.exceptions.api_exception import APIException

config = configparser.ConfigParser()
config.read('config.ini')
try:
    config['bandwidth']['api_user']
    config['bandwidth']['api_password']
except error:
    print("Please set the config variables defined in the README", error)
    exit(-1)

bandwidth_client = BandwidthClient(
    two_factor_auth_basic_auth_user_name=config['bandwidth']['api_user'],
    two_factor_auth_basic_auth_password=config['bandwidth']['api_password'],
)

app = Flask(__name__)

# track our username
#  - if not a demo, these would be stored in persistant storage
globalUser = User("Name Not Set")
globalUser.security_level = 0


@app.route("/", methods=["GET"])
def show_login_page():
    # show the login page
    return render_template('home_page.html')
Esempio n. 13
0
from bandwidth.exceptions.api_exception import APIException

try:
    os.environ["BW_USERNAME"]
    os.environ["BW_PASSWORD"]
    os.environ["BW_ACCOUNT_ID"]
    os.environ["USER_NUMBER"]
    os.environ["BW_NUMBER"]
    os.environ["BW_MESSAGING_APPLICATION_ID"]
    os.environ["BW_VOICE_APPLICATION_ID"]
except Exception as e:
    print("Please set the environment variables defined in the README", e)
    exit(-1)

bandwidth_client = BandwidthClient(
    two_factor_auth_basic_auth_user_name=os.environ["BW_USERNAME"],
    two_factor_auth_basic_auth_password=os.environ["BW_PASSWORD"],
)

app = Flask(__name__)

# track our username
#  - if not a demo, these would be stored in persistant storage
globalUser = User("Name Not Set")
globalUser.security_level = 0


@app.route("/", methods=["GET"])
def show_login_page():
    # show the login page
    return render_template('home_page.html')
Esempio n. 14
0
import string
import os

try:
    MESSAGING_ACCOUNT_ID = os.environ["MESSAGING_ACCOUNT_ID"]
    MESSAGING_API_TOKEN = os.environ["MESSAGING_API_TOKEN"]
    MESSAGING_API_SECRET = os.environ["MESSAGING_API_SECRET"]
    MESSAGING_APPLICATION_ID = os.environ["MESSAGING_APPLICATION_ID"]
except:
    print(
        "Please set the MESSAGING environmental variables defined in the README"
    )
    exit(-1)

bandwidth_client = BandwidthClient(
    messaging_basic_auth_user_name=MESSAGING_API_TOKEN,
    messaging_basic_auth_password=MESSAGING_API_SECRET)
messaging_client = bandwidth_client.messaging_client.client

##This is the only Bandwidth url needed
BANDWIDTH_MEDIA_BASE_ENDPOINT = "https://messaging.bandwidth.com/api/v2/users/{accountId}/media/".format(
    accountId=MESSAGING_ACCOUNT_ID)

messaging_app = Blueprint('messaging_app', __name__)


def get_media_id(media_url):
    """
    Takes a full media url from Bandwidth and extracts the media id

    The full media url looks like https://messaging.bandwidth.com/api/v2/users/123/media/<media_id>