Exemple #1
0
    def test_outbound_permissions(self):
        token = TwilioCapability("AC123", "XXXXX")
        token.allow_client_outgoing("AP123")
        payload = token.payload()

        eurl = "scope:client:outgoing?appSid=AP123"

        self.assertEquals(len(payload), 1)
        self.assertIn(eurl, payload['scope'])
Exemple #2
0
 def get(self):
     capability = TwilioCapability(self.app.config.get('account_sid'), self.app.config.get('auth_token'))
     capability.allow_client_outgoing(self.app.config.get('application_sid'))
     capability.allow_client_incoming('agent1')
     token = capability.generate()
     params = {'token': token}
     jinja_env = self.app.config.get('template')
     template_environment = jinja_env('views').get_template('index.html')
     self.response.write(template_environment.render(params))
Exemple #3
0
def task_profile(request, task_id):

    task = get_object_or_404(Task, id=task_id)

    #It wasn't bad enough that the actual create form was wet and silly.  Now this too.  TODO: FIX THIS F****R.
    user_can_make_new_prototypes = True  #TODO: Turn this into an actual privilege assessment
    task_prototype_name_form = TaskPrototypeNameForm()

    task_prototype_name_form.fields['name'].widget.attrs[
        'class'] = "topLevel"  #So that we can recognize it later via autocomplete.

    rest_of_the_task_prototype_form = RestOfTheTaskPrototypeForm()

    user_privileges = get_privileges_for_user(request.user)

    #Wet and silly.  TODO: Fix
    class SimpleChildForm(forms.Form):
        child = AutoCompleteField(models=(TaskPrototype, ),
                                  name_visible_field=True)

    class SimpleParentForm(forms.Form):
        parent = AutoCompleteField(models=(TaskPrototype, ),
                                   name_visible_field=True)

    task_prototype_form = TaskPrototypeForm()

    task_prototype_parent_form = SimpleParentForm()
    task_prototype_child_form = SimpleChildForm()

    draw_attention_ajax_form = DrawAttentionAjaxForm()

    if task.prototype.id == 251 or task.prototype.id == 7:

        has_outgoing_call = True
        disable_incoming_calls = True
        account_sid = "AC260e405c96ce1eddffbddeee43a13004"
        auth_token = "fd219130e257e25e78613adc6c003d1a"
        capability = TwilioCapability(account_sid, auth_token)
        capability.allow_client_outgoing("APd13a42e60c91095f3b8683a77ee2dd05")

        #The text of the call recipient will be the name of the person in the case of a tech job.  It will be the output of the unicode method of the PhoneNumber in the case of a PhoneCall resolution.
        if task.prototype.id == 251:
            call_to_name = task.related_objects.all()[0].object.get_full_name()
            related_user = task.related_objects.all()[0].object
            phone_numbers = task.related_objects.all(
            )[0].object.userprofile.contact_info.phone_numbers.all()
        if task.prototype.id == 7:
            phone_numbers = [task.related_objects.all()[0].object.from_number]
            if task.related_objects.all()[0].object.from_number.owner:
                call_to_name = task.related_objects.all(
                )[0].object.from_number.owner
            else:
                call_to_name = "Phone Number #%s" % (str(
                    task.related_objects.all()[0].object.id))

    return render(request, 'do/task_profile.html', locals())
Exemple #4
0
 def get_context_data(self, **kwargs):
     context = super(TwillioView, self).get_context_data(**kwargs)
     context['account_sid'] = settings.TWILLIO_ACCOUNT_SID
     context['auth_token'] = settings.TWILLIO_AUTH_TOKEN
     context['auth_token'] = settings.TWILLIO_APP_SID
     capability = TwilioCapability(settings.TWILLIO_ACCOUNT_SID,
                                   settings.TWILLIO_AUTH_TOKEN)
     capability.allow_client_outgoing(settings.TWILLIO_APP_SID)
     context['token'] = capability.generate()
     return context
Exemple #5
0
def index():
    reason, source = reasonSonyaIsAwesome().split('::')
    capability = TwilioCapability(app.config['ACCOUNT_SID'],
                                  app.config['AUTH_TOKEN'])
    capability.allow_client_outgoing(app.config['SONYA_APP_SID'])
    token = capability.generate()
    return render_template('index.html',
                           token=token,
                           reason=reason,
                           source=source)
Exemple #6
0
def index(request):
    account_sid = settings.TWILIO_ACCOUNT_SID
    auth_token = settings.TWILIO_AUTH_TOKEN
    application_sid = settings.TWILIO_APPLICATION_SID

    capability = TwilioCapability(account_sid, auth_token)
    capability.allow_client_outgoing(application_sid)
    capability.allow_client_incoming(request.user.username)
    twilio_token = capability.generate()
    return TemplateResponse(request, 'browser-phone.html', locals())
Exemple #7
0
def client(request):
    account_sid = TWILIO_ACCOUNT_SID
    auth_token = TWILIO_AUTH_TOKEN
    capability = TwilioCapability(account_sid, auth_token)
    application_sid = APPLICATION_SID
    capability.allow_client_outgoing(application_sid)
    token = capability.generate()
    context_dict = {}
    context_dict['token'] = token
    return render(request, 'client.html', context_dict)
Exemple #8
0
def index():
    # Create a capability token for this client instance
    capability = TwilioCapability(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
    # If the client attempts an outgoing call, invoke a TwiML app
    capability.allow_client_outgoing("AP17a745dc5cfc00000000000000000000")
    # We can make incoming calls to this client with <dial><client>david</client></dial>
    capability.allow_client_incoming("david")
    token = capability.generate()
    return render_template("client_browser.html",
                           capability_token=token)
def get_capability_token():
    """Respond to incoming requests."""

    # Find these values at twilio.com/console
    account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
    auth_token = 'your_auth_token'

    capability = TwilioCapability(account_sid, auth_token)

    capability.allow_client_incoming("jenny")
    token = capability.generate()

    return Response(token, mimetype='application/jwt')
Exemple #10
0
def build_twilio_token(client_name):

    # Find these values at twilio.com/user/account
    account_sid = "TWILIO_ACCOUNT_SID"
    auth_token = "TWILIO_AUTH_TOKEN"

    cap = TwilioCapability(account_sid, auth_token)

    app_sid = ''
    cap.allow_client_outgoing(app_sid)
    cap.allow_client_incoming(client_name)

    return cap.generate()
Exemple #11
0
 def test(self, var=None, **params):
     room = str(urllib.unquote(cherrypy.request.params['room']))
     user = str(urllib.unquote(cherrypy.request.params['user']))
     capability = TwilioCapability(account, token)
     capability.allow_client_outgoing(application_sid)
     template_values = {
         "token": capability.generate(),
         "room": room,
         "user": user
     }
     t = loader.get_template('test.html')
     c = Context(template_values)
     return t.render(c)
Exemple #12
0
def client():
    """Respond to incoming requests."""

    # Find these values at twilio.com/user/account
    account_sid = "AC3d6188091a9109165c89ae83c5d94d1b"
    auth_token = "7a0007278ebe72b311ca4d476c7a6abc"

    capability = TwilioCapability(account_sid, auth_token)

    application_sid = "APcdc54402e77bd0aa98ab42bd5d045f89"  # Twilio Application Sid
    capability.allow_client_incoming("ram")
    token = capability.generate()

    return render_template('client.html', token=token)
Exemple #13
0
    def generate_token(self):
        sid_account = request.env.user.company_id.twilio_account_sid
        token_account = request.env.user.company_id.twilio_auth_token
        sid_twiml = request.env.user.company_id.twiml_application

        capability = TwilioCapability(sid_account, token_account)

        # Allow our users to make outgoing calls with Twilio Client
        capability.allow_client_outgoing(sid_twiml)
        capability.allow_client_incoming('support_agent')

        # Generate the capability token
        token = capability.generate()
        return token
Exemple #14
0
def main_page():
    """Respond to incoming requests."""
    account_sid = ""
    auth_token = ""

    capability = TwilioCapability(account_sid, auth_token)

    # This is a special Quickstart application sid - or configure your own
    # at twilio.com/user/account/apps
    application_sid = "APaf6c7ab08a32e7fb541a78d97d592100"
    capability.allow_client_outgoing(application_sid)
    token = capability.generate()

    return render_template('index.html', token=token)
Exemple #15
0
 def main(self, var=None, **params):
     clientid = urllib.unquote(cherrypy.request.params['id'])
     room = clientid.split(".")[0]
     user = clientid.split(".")[1]
     capability = TwilioCapability(account, token)
     capability.allow_client_outgoing(application_sid)
     template_values = {
         "token": capability.generate(),
         "room": room,
         "user": user
     }
     t = loader.get_template('mainclient.html')
     c = Context(template_values)
     return t.render(c)
Exemple #16
0
def token():
    # get credentials for environment variables

    # Generate a random user name
    identity = alphanumeric_only.sub('', fake.user_name())

    # Create a Capability Token
    capability = TwilioCapability(account_sid, auth_token)
    capability.allow_client_outgoing(application_sid)
    capability.allow_client_incoming(identity)
    token = capability.generate()

    # Return token info as JSON
    return jsonify(identity=identity, token=token)
Exemple #17
0
    def dispatch(self, request, *args, **kwargs):
        account_sid = settings.TWILIO_ACCOUNT_SID
        auth_token = settings.TWILIO_AUTH_TOKEN
        application_sid = settings.TWILIO_CALLBACK_APP_SID

        capability = TwilioCapability(account_sid, auth_token)
        capability.allow_client_outgoing(application_sid)
        token = capability.generate()

        manager = request.user.callbackmanager

        return JsonResponse({
            'token': token,
            'manager': Signer().sign(manager.pk)
        })
Exemple #18
0
def client():
    """Respond to incoming requests."""

    # Find these values at twilio.com/user/account
    account_sid = "AC9c5adc79b9cf3d79fc46f47fa6165c1e"
    auth_token = "6c79f8833d77a2a0433db0418d33d0c7"

    capability = TwilioCapability(account_sid, auth_token)

    application_sid = "APaa7ff4fb5efb45971236e6762e90b1ba"  # Twilio Application Sid
    capability.allow_client_outgoing(application_sid)
    capability.allow_client_incoming("jenny")
    token = capability.generate()

    return render_template('client.html', token=token)
Exemple #19
0
def client():
    """Respond to incoming requests."""
 
    account_sid = "ACdfd86ae9d14d1932491fb8d18c1bc983"
    auth_token = "31999b4fabf7b98ba4491738c9b4c493"
 
    # This is a special Quickstart application sid - or configure your own
    # at twilio.com/user/account/apps
    application_sid = "APabe7650f654fc34655fc81ae71caa3ff"
 
    capability = TwilioCapability(account_sid, auth_token)
    capability.allow_client_outgoing(application_sid)
    token = capability.generate()
 
    return render_template('client.html', token=token)
def get_capability_token():
    """Respond to incoming requests."""

    # Find these values at twilio.com/console
    account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
    auth_token = 'your_auth_token'

    capability = TwilioCapability(account_sid, auth_token)

    # Twilio Application Sid
    application_sid = 'APXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
    capability.allow_client_outgoing(application_sid)
    capability.allow_client_incoming(request.form["ClientName"])
    token = capability.generate()

    return Response(token, mimetype='application/jwt')
Exemple #21
0
def get_token(request):
    """Returns a Twilio Client token.
    Create a TwilioCapability object with our Twilio API credentials."""
    capability = TwilioCapability(
        settings.TWILIO_ACCOUNT_SID,
        settings.TWILIO_AUTH_TOKEN)
    """Allow our users to make outgoing calls with Twilio Client"""
    capability.allow_client_outgoing(settings.TWIML_APPLICATION_SID)

    """Allow our users to accept incoming calls from pyphon"""
    capability.allow_client_incoming('caller')

    """Generate the capability token"""
    token = capability.generate()

    return JsonResponse({'token': token})
Exemple #22
0
def capability_token(request):
    mhluser_id = request.user.id
    capability = TwilioCapability(settings.TWILIO_ACCOUNT_SID,
                                  settings.TWILIO_ACCOUNT_TOKEN)
    capability.allow_client_outgoing(settings.TWILIO_APP_SID)
    capabilityToken = capability.generate()
    response = {
        'data': {
            'capabilityToken': capabilityToken,
            'mhluser_id': mhluser_id
        },
        'warnings': {},
    }
    print json.dumps(response)
    return HttpResponse(content=json.dumps(response),
                        mimetype='application/json')
Exemple #23
0
    def test_decode(self):
        token = TwilioCapability("AC123", "XXXXX")
        token.allow_client_outgoing("AP123", foobar=3)
        token.allow_client_incoming("andy")
        token.allow_event_stream()

        outgoing_uri = "scope:client:outgoing?appParams=foobar%3D3&appSid=AP123&clientName=andy"
        incoming_uri = "scope:client:incoming?clientName=andy"
        event_uri = "scope:stream:subscribe?path=%2F2010-04-01%2FEvents"

        result = jwt.decode(token.generate(), "XXXXX")
        scope = result["scope"].split(" ")

        self.assertIn(outgoing_uri, scope)
        self.assertIn(incoming_uri, scope)
        self.assertIn(event_uri, scope)
def client():
    configuration_error = None
    for key in ('TWILIO_ACCOUNT_SID', 'TWILIO_AUTH_TOKEN', 'TWILIO_APP_SID',
                'TWILIO_CALLER_ID'):
        if not app.config[key]:
            configuration_error = "Missing from local_settings.py: %s" % key
            token = None
    if not configuration_error:
        capability = TwilioCapability(app.config['TWILIO_ACCOUNT_SID'],
                                      app.config['TWILIO_AUTH_TOKEN'])
        capability.allow_client_incoming("joey_ramone")
        capability.allow_client_outgoing(app.config['TWILIO_APP_SID'])
        token = capability.generate()
    params = {'token': token}
    return render_template('client.html', params=params,
                           configuration_error=configuration_error)
Exemple #25
0
def incomingWidget(request):
    callsid = request.GET['callsid']
    group_id = request.GET['group_id']
    number = request.GET['number']
    account_sid = TWILIO_ACCOUNT_SID
    auth_token = TWILIO_AUTH_TOKEN
    capability = TwilioCapability(account_sid, auth_token)
    application_sid = APPLICATION_SID
    capability.allow_client_incoming(callsid)
    token = capability.generate()
    context_dict = {}
    context_dict['token'] = token
    context_dict['number'] = number
    context_dict['group_id'] = "g:" + group_id
    # TODO
    # change this to incoming call
    return render(request, 'incoming.html', context_dict)
Exemple #26
0
def token():
    account_sid = os.environ.get("ACCOUNT_SID", ACCOUNT_SID)
    auth_token = os.environ.get("AUTH_TOKEN", AUTH_TOKEN)
    app_sid = os.environ.get("APP_SID", APP_SID)

    capability = TwilioCapability(account_sid, auth_token)

    # This allows outgoing connections to TwiML application
    if request.values.get('allowOutgoing') != 'false':
        capability.allow_client_outgoing(app_sid)

    # This allows incoming connections to client (if specified)
    client = request.values.get('client')
    if client != None:
        capability.allow_client_incoming(client)

    # This returns a token to use with Twilio based on the account and capabilities defined above
    return capability.generate()
Exemple #27
0
def client():
    global pending_call_token
    token = request.args.get("token")

    print "/"
    print "pending_call_token: {}".format(pending_call_token)
    print "token: {}".format(token)

    if pending_call_token and (token == pending_call_token):
        capability = TwilioCapability(twilio_account_sid, twilio_auth_token)
        capability.allow_client_outgoing(twilio_application_sid)
        capability.allow_client_incoming(twilio_client_name)
        twilio_token = capability.generate()

        return render_template('client.html',
                               twilio_token=twilio_token,
                               call_token=pending_call_token,
                               door_unlock_digits=door_unlock_digits)
    else:
        return render_template("answered.html")
Exemple #28
0
def reqclient():
    """Respond to incoming requests."""

    client_name = request.values.get('client', None) or "jenny"

    # Find these values at twilio.com/user/account
    account_sid = __ACCOUNT_SID
    auth_token = __AUTH_TOKEN

    capability = TwilioCapability(account_sid, auth_token)

    application_sid = "APabe7650f654fc34655fc81ae71caa3ff"  # Twilio Application Sid
    capability.allow_client_outgoing(application_sid)
    capability.allow_client_incoming(client_name)
    token = capability.generate()

    return render_template('client.html',
                           token=token,
                           appID=__APP_ID,
                           appSecret=__APP_SECRET,
                           client_name=client_name)
Exemple #29
0
def get_token(request):
    """Returns a Twilio Client token"""
    # Create a TwilioCapability object with our Twilio API credentials
    capability = TwilioCapability(settings.TWILIO_ACCOUNT_SID,
                                  settings.TWILIO_AUTH_TOKEN)

    # Allow our users to make outgoing calls with Twilio Client
    capability.allow_client_outgoing(settings.TWIML_APPLICATION_SID)

    # If the user is on the support dashboard page, we allow them to accept
    # incoming calls to "support_agent"
    # (in a real app we would also require the user to be authenticated)
    if request.GET['forPage'] == reverse('dashboard'):
        capability.allow_client_incoming('support_agent')
    else:
        # Otherwise we give them a name of "customer"
        capability.allow_client_incoming('customer')

    # Generate the capability token
    token = capability.generate()

    return JsonResponse({'token': token})
Exemple #30
0
def index():
    # Make sure we have this host configured properly.
    config_errors = []
    for option in ['TWILIO_ACCOUNT_SID', 'TWILIO_AUTH_TOKEN']:
        if not app.config[option]:
            config_errors.append("%s is not configured for this host." %
                                 option)

    # Define important links
    params = {
        'sms_request_url': url_for('.sms', _external=True),
        'config_errors': config_errors
    }

    # Generate capability token
    capability = TwilioCapability(app.config['TWILIO_ACCOUNT_SID'],
                                  app.config['TWILIO_AUTH_TOKEN'])
    capability.allow_client_outgoing(app.config['TWILIO_APP_SID'])
    token = capability.generate()

    # If not a submission, render form.
    return render_template('index.html', params=params, token=token)