Code Monkey home page Code Monkey logo

browser-calls-django's Introduction

Twilio

Browser Calls (Django)

This repository is now archived and is no longer being maintained. Check out the JavaScript SDK Quickstarts to get started with browser-based calling.

About

Learn how to use Twilio's JavaScript SDK to make browser-to-phone and browser-to-browser calls with ease. The unsatisfied customers of the Birchwood Bicycle Polo Co. need your help!

Set up

Requirements

Twilio Account Settings

This application should give you a ready-made starting point for writing your own application. Before we begin, we need to collect all the config values we need to run the application:

Config Value Description
TWILIO_ACCOUNT_SID Your primary Twilio account identifier - find this in the Console.
TWILIO_NUMBER A Twilio phone number in E.164 format - you can get one here
TWIML_APPLICATION_SID The TwiML application with a voice URL configured to access your server running this app - create one in the console here. Also, you will need to configure the Voice "REQUEST URL" on the TwiML app once you've got your server up and running.
API_KEY / API_SECRET Your REST API Key information needed to create an Access Token - create one here.

Create a TwiML App

This project is configured to use a TwiML App, which allows us to easily set the voice URLs for all Twilio phone numbers we purchase in this app.

Create a new TwiML app at https://www.twilio.com/console/voice/twiml/apps and use its Sid as the TWIML_APPLICATION_SID environment variable wherever you run this app.

Once you have created your TwiML app, configure your Twilio phone number to use it (instructions here). If you don't have a Twilio phone number yet, you can purchase a new number in your Twilio Account Dashboard.

Local development

  1. Clone this repo and cd into it.

    git clone https://github.com/TwilioDevEd/browser-calls-django.git
    cd browser-calls-django
  2. Create a new virtual environment, load it and install dependencies.

    make install
  3. Install the twilio-client js library.

    npm install
  4. Set your environment variables. Copy the env.example file and edit it.

    cp .env.example .env

    See Twilio Account Settings to locate the necessary environment variables.

  5. Run the migrations.

    make serve-setup
  6. Start the development server (will run on port 8000). Before running the following command, make sure the virtual environment is activated.

    make serve
  7. Expose your application to the wider internet using ngrok. This step is important because the application won't work as expected if you run it through localhost.

    $ ngrok http 8000
  8. Once you have started ngrok, update your TwiML app's voice URL setting to use your ngrok hostname, so it will look something like this:

    http://<your-ngrok-subdomain>.ngrok.io/support/call
  9. Everything is setup, now you can open two tabs:

    When the customer click on the "Call Support" button, the support agent will see the call immediatly and be able to pick up the call with the "Answer Call" button.

    Another scenario is the customer fill out the form to open a ticket, the support agent can refresh the dashboard and we'll be able to click the "Call customer" button which will start a call to the phone number listed in the ticket.

That's it!

Tests

You can run the tests locally through coverage, before running the following command, make sure the virtual environment is activated.

$ coverage run manage.py test --settings=twilio_sample_project.settings.test

You can then view the results with coverage report or build an HTML report with coverage html. |

Resources

  • The CodeExchange repository can be found here.

License

MIT

Disclaimer

No warranty expressed or implied. Software is as is.

browser-calls-django's People

Contributors

atbaker avatar bld010 avatar dependabot-preview[bot] avatar hortega avatar joliveros avatar jonedavis avatar kwhinnery avatar maylonpedroso avatar mcelicalderon avatar rojastob avatar smendes avatar well1791 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

browser-calls-django's Issues

Code Exchange quality checklist

The purpose of this checklist is to assess the state of this repository, and bring it to an acceptable level for long-term support by completing the tasks listed below.

This checklist is used internally but can be used as a guidance for others

Please check every part of this checklist for us to process your request. You can do this by marking them with [x] instead of [ ].

Documentation

  • LICENSE file exists in repository

  • Code of Conduct exists in repository

  • CONTRIBUTING exists in repository

  • No broken links in README.md

  • Build status exists at top of README.md

  • Set up steps are complete and accurate

  • CodeExchange repository is linked in README.md

GitHub

  • Dependabot set up

  • Dependabot automerge set up

  • Uses GitHub Actions (required for Twilio sample) or other CI

Code

  • Packages/dependencies are up to date

  • Code compiles against latest packages/dependencies

  • Matches CodeExchange Guidelines to the best of ability

Tests

  • Functionality tests have been created

  • All tests pass

App

  • Confirmed sample behaves as expected (after dependencies have been updated)

  • This file has been copied into a wiki entry for the respective repository or added as a GitHub issue

General

  • App is released under a permissive license like MIT or Apache-2

  • I've read and followed the contribution guidelines

  • I've read and implemented my template according to the respective coding guidelines for my project

  • I agree and adhere to the Code of Conduct

  • The template has been authored by me / or my organization and will be kept up-to-date. If the template will not longer be maintained, I'll notify this project.

Code is outdated and uses jquery

https://www.twilio.com/docs/voice/tutorials/browser-calls-python-django#setting-up-a-twilio-device-client

I do not use node.js for my django application. I am not sure what to do for this step coding wise. I was able to download https://github.com/twilio/twilio-voice.js and add twilio.min.js to my app.

Is there a way that this node.js / jquery code can be converted to vanilla javascript? If you cannot change the node.js code via a PR, can you paste the vanilla javascript code equivalent in this thread?

If it cannot be converted to javascript, can it be converted to django?

I also see that things may be a bit outdated. The tutorial uses capability tokens instead of access tokens. The javascript API is now version 2.0.

Decode error for Python

On Python 3.8 you will get an error when you visit http://localhost:8000/support/dashboard:

File "/Users/rsunga/PycharmProjects/browser-calls-django/browser_calls/views.py", line 49, in get_token return JsonResponse({'token': token.decode('utf-8')}) AttributeError: 'str' object has no attribute 'decode'

You need to change line 49 here

from return JsonResponse({'token': token.decode('utf-8')})
to return JsonResponse({'token': token})

Since it seems the token is already serialized.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.