Giter VIP home page Giter VIP logo

sdk-starter-python's Introduction

Twilio

Twilio SDK Starter Application for Python

This sample project demonstrates how to use Twilio APIs in a Python web application. Once the app is up and running, check out the home page to see which demos you can run. You'll find examples for Chat, Video, Sync, and more.

Let's get started!

Configure the sample application

To run the application, you'll need to gather your Twilio account credentials and configure them in a file named .env. To create this file from an example template, do the following in your Terminal.

cp .env.example .env

Open .env in your favorite text editor and configure the following values. The application runs by default in production environment. Feel free to update DEBUG to True if needed.

Configure account information

Every sample in the demo requires some basic credentials from your Twilio account. Configure these first.

Config Value Description
TWILIO_ACCOUNT_SID Your primary Twilio account identifier - find this in the console here.
TWILIO_API_KEY Used to authenticate - generate one here.
TWILIO_API_SECRET Used to authenticate - just like the above, you'll get one here.

A Note on API Keys

When you generate an API key pair at the URLs above, your API Secret will only be shown once - make sure to save this information in a secure location, or possibly your ~/.bash_profile.

Configure product-specific settings

Depending on which demos you'd like to run, you may need to configure a few more values in your .env file.

Configuring Twilio Sync

Twilio Sync works out of the box, using default settings per account. Once you have your API keys configured, run the application (see below) and open a browser!

Configuring Twilio Chat

In addition to the above, you'll need to generate a Chat Service in the Twilio Console. Put the result in your .env file.

Config Value Where to get one.
TWILIO_CHAT_SERVICE_SID Generate one in the Twilio Chat console

With this in place, run the application (see below) and open a browser!

Configuring Twilio Notify

You will need to create a Notify Service and add at least one credential on the Mobile Push Credential screen (such as Apple Push Notification Service or Firebase Cloud Messaging for Android) to send notifications using Notify.

Config Value Where to get one.
TWILIO_NOTIFICATION_SERVICE_SID Generate one in the Notify Console and put this in your .env file.
A Push Credential Generate one with Apple or Google and configure it as a Notify credential.

Once you've done that, run the application (see below) and open a browser!

Run the sample application

This application uses the lightweight Flask Framework.

We need to set up your Python environment. Install virtualenv via pip:

pip install virtualenv

Next, we need to install our dependencies:

virtualenv venv
source venv/bin/activate
pip install -r requirements.txt

Now we should be all set! Run the application using the python command.

python app.py

Your application should now be running at http://localhost:5000. When you're finished, deactivate your virtual environment using deactivate.

Home Screen

Running the SDK Starter Kit with ngrok

If you are going to connect to this SDK Starter Kit with a mobile app (and you should try it out!), your phone won't be able to access localhost directly. You'll need to create a publicly accessible URL using a tool like ngrok to send HTTP/HTTPS traffic to a server running on your localhost. Use HTTPS to make web connections that retrieve a Twilio access token.

ngrok http 5000

License

MIT

sdk-starter-python's People

Contributors

alexisbcc avatar atampere avatar hortega avatar jefflinwood avatar joliveros avatar kevgathuku avatar lgerzz avatar pkamp3 avatar po5i avatar sarias-tw avatar skuusk avatar well1791 avatar

Stargazers

 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

sdk-starter-python's Issues

The referenced twilio=6.1.0-alpha1 library can't be found

When I run pip install -r requirements.txt I get the following output...

Could not find a version that satisfies the requirement twilio==6.1.0-alpha1 (from -r requirements.txt (line 3)) (from versions: 6.2.0, 3.6.5, 3.4.3, 5.5.0, 4.6.0, 4.3.0, 3.7.2, 2.0.1, 5.0.dev3, 5.0.dev2, 4.1.0, 6.0.0rc10, 3.3.10, 3.5.4, 3.3.9, 6.2.0, 5.7.0, 3.6.7, 6.1.1, 3.6.8, 6.0.0rc11, 5.0.dev1, 4.9.dev0, 2.0.10, 2.0.6, 3.5.2, 3.0.1, 3.6.6, 3.6.4, 4.2.0, 3.6.0, 3.2.1, 3.6.2, 6.0rc9, 5.6.1, 6.1.0, 3.4.4, 4.9.0, 4.2.0, 5.2.0, 6.0rc8, 3.2.3, 6.1.1a1, 3.5.1, 3.6.14, 6.0.0rc11, 3.0.0, 5.0.dev0, 3.0.2, 6.1.1, 3.6.3, 3.7.2, 5.6.1, 3.6.13, 6.1.2, 3.7.0, 3.5.3, 5.4.0, 3.4.0, 3.7.3, 4.8.0, 3.7.1, 6.0rc7, 3.1.0, 5.0.0, 6.0rc5, 4.7.dev0, 3.6.6, 3.6.15, 3.6.10, 5.1.0, 6.0.0rc13, 3.7.1, 5.3.0, 3.2.0, 3.2.2, 6.0.0a1, 6.1.2-alpha-1, 3.6.11, 3.4.2, 6.1.0a1, 6.0rc6, 3.3.0, 3.5.4-rc1, 4.9.2, 6.1.2, 6.1.1a1, 3.3.3, 3.6.1, 3.7.3, 6.0.0rc10, 3.6.12, 3.6.14, 3.6.12, 6.1.dev0, 3.4.1, 6.0.dev0, 3.6.11, 3.4.5, 4.9.1, 2.0.9, 3.6.4, 3.3.2, 6.0rc4, 6.0.0rc12, 4.7.0, 3.8.0, 4.5.0, 3.7.0, 4.10.0, 5.6.0, 6.2.dev0, 4.8.dev0, 3.6.9, 3.5.0, 6.0.0rc12, 4.4.0, 3.6.10, 6.1.0, 6.0.0rc2, 3.3.11, 3.8.0, 4.1.0, 6.1.2-alpha-1, 3.3.7, 3.6.13, 6.0rc3, 4.0.0, 6.3.dev0, 3.3.6, 3.3.1, 6.0.0, 3.6.9, 3.3.5)
Cleaning up...
No distributions matching the version for twilio==6.1.0-alpha1 (from -r requirements.txt (line 3))

issues with later chat sdks

Using this with chat 1.2 works fine, 2.2/3.0 all have issues in this section:
var channel = 'CHXXXXXXXXXXXXXXXXXX';
var promise = chatClient.getChannelBySid(channel);

    promise.then(function(channel) {
                generalChannel = channel;
                setupChannel();
            }).catch(function(){
                // If it doesn't exist, let's create it
        
                chatClient.createChannel({
                    uniqueName: 'general',
                    friendlyName: 'General Chat Channel'
        }).then(function(channel) {
            console.log('Created general channel:');
            console.log(channel);
            generalChannel = channel;
            setupChannel();
        });
    });
}

Seems to ignore or be unable to handle the returned promise? The best way to test is to use the same code and just switch the js libraries to 2.2 and 3.0.

The chat front end is BROKEN!!

Uncaught TypeError: Cannot read property 'sendMessage' of undefined

// Send a new message to the general channel var $input = $('#chat-input'); $input.on('keydown', function(e) { if (e.keyCode == 13) { generalChannel.sendMessage($input.val()) $input.val(''); } });

Sync demo not working

Without any changes to the starter kit, the Sync demo is failing for me:

2020-12-05T12:12:24.139Z Twilsock W: Init rejected by server: {"code":401,"status":"UNAUTHORIZED","description":"The authorization with Token failed","errorCode":20151}

I've provided the four credentials required to make that demo work, but maybe telling you the steps I took to get them will help us figure out where the problem lies:

Clone the Twilio SDK Starter Application for Python, copying the instructions for making your own .env file.

Log into your Twilio account.

Go here to create a new Twilio Sync app. Gather the secret and SID and plunk them into your .env file in the Twilio starter app as TWILIO_API_SECRET and TWILIO_API_KEY, respectively. Also, gather your service SID from the single entry here (Sync Services) and put that in for TWILIO_SYNC_SERVICE_SID. Finally, add your TWILIO_ACCOUNT_SID which can be found here.

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.