Git Product home page Git Product logo

python-bandwidth's Introduction

Bandwidth Python API

Deprecation Notice

This project is deprecated. Please go to https://github.com/Bandwidth/python-sdk

Build Status Can I Use Python 3?Documentation Status

Client library for the Bandwidth App Platform

Full Reference

dev.bandwidth.com/python-bandwidth

Requirements

Installation

pip install bandwidth-sdk

Usage

Client Initialization

import bandwidth
voice_api = bandwidth.client('voice', 'u-user', 't-token', 's-secret')
messaging_api = bandwidth.client('messaging', 'u-user', 't-token', 's-secret')
account_api = bandwidth.client('account', 'u-user', 't-token', 's-secret')

## Or import each individually for better IDE integration::

from bandwidth import messaging, voice, account
messaging_api = messaging.Client('u-user', 't-token', 's-secret')
voice_api = voice.Client('u-user', 't-token', 's-secret')
account_api = account.Client('u-user', 't-token', 's-secret')

Each of these code sample assumes that you have already initialized a client

Search and order phone number

numbers = account_api.search_available_local_numbers(area_code = '910', quantity = 3)
print(numbers[0]['number'])
## +19104440230

my_number = account_api.order_phone_number(numbers[0]['number'])

print(my_number)
#n-rnd5eag33safchqmrj3q

Send Text Message

message_id = api.send_message(from_ = '+1234567980',
                              to = '+1234567981',
                              text = 'SMS message')
print(message_id)
# m-messageId

Send Picture Message

message_id = api.send_message(from_ = '+1234567980',
                              to = '+1234567981',
                              text = 'MMS message',
                              media=['http://cat.com/cat.png'])
print(message_id)
# m-messageId

Fetch information about single message

my_message = api.get_message('m-messageId')
print(my_message[state])
## received

Create an outbound call

call_id = api.create_call(from_ = '+1234567890',
                          to = '+1234567891',
                          callback_url = "http://yoursite.com/calls")
print(call_id)
## c-abc123

Get information on single call

my_call = api.get_call('c-abc123')
print(my_call)
## {   'callback_url'         : 'http://yoursite.com/calls',
##     'direction'           : 'out',
##     'events'              : 'https://api.catapult.inetwork.com/v1/users/u-abc/calls/c-abc123/events',
##     'from'                : '+1234567890',
##     'id'                  : 'c-abc123',
##     'recording_enabled'    : False,
##     'recording_file_format' : 'wav',
##     'recordings'          : 'https://api.catapult.inetwork.com/v1/users/u-abc/calls/c-abc123/recordings',
##     'startTime'           : '2017-01-26T16:10:11Z',
##     'state'               : 'started',
##     'to'                  : '+1234567891',
##     'transcription_enabled': False,
##     'transcriptions'      : 'https://api.catapult.inetwork.com/v1/users/u-abc/calls/c-abc123/transcriptions'}

Retrieving list of calls

call_list = api.list_calls(to = '+19192223333', size = 2)
print(list(call_list))

python-bandwidth's People

Contributors

aubron avatar avbel avatar axik avatar bwdan avatar dpereira-daitan avatar jkgibbs avatar jmulford-bw avatar joeldodson avatar jsilva-daitan avatar kldavis4 avatar lvivo-daitan avatar msoedov avatar mzizzi avatar truskovskiyk 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

python-bandwidth's Issues

v1 -> v2 Migration for Messaging 2.0

https://dev.bandwidth.com/v2-messaging/messaging2Migration.html

The ones I could find are:

  • Update request params

Add applicationId in its payload for v2.

Currently it looks like https://github.com/Bandwidth/python-bandwidth/blob/master/bandwidth/messaging/client_module.py#L197.

Also drop other unwanted params based on version.

  • Update message_id extraction logic.

v1 has themessage_id in this Location header where it is being extracted from currently as seen here https://github.com/Bandwidth/python-bandwidth/blob/master/bandwidth/messaging/client_module.py#L87

v2 just returns a JSON like below where we will have to extract it from.

{
  "id"            : "14762070468292kw2fuqty55yp2b2",
  "time"          : "2016-09-14T18:20:16Z",
  "to"            : [
    "+12345678902",
    "+12345678903"
  ],
  "from"          : "+12345678901",
  "text"          : "Hey, check this out!",
  "applicationId" : "93de2206-9669-4e07-948d-329f4b722ee2",
  "tag"           : "test message",
  "owner"         : "+12345678901",
  "direction"     : "out",
  "segmentCount"  : 1
}
  • Error handling.

Right now we get the response.json() and fetch the message as well as code keys from it as seen here https://github.com/Bandwidth/python-bandwidth/blob/master/bandwidth/messaging/client_module.py#L72

But v2 seems to send back an "array of objects" and the name of the keys also seem to be different. Based on what I was able to gather, looks like we have replace that logic with response.json()[0] , data['description'] and code=data.get('type')).

Are there plans to make an exhaustive list and work on updating the repo to support v2? Would be happy to help.

No way to specify local proxy

I'm behind a corporate firewall and need to use a proxy for some requests. Since you seem to be using requests behind the scenes, could you add another optional parameter for proxy conf?

quote(media_name) has issue

Thank you for your good work.

I found issue that download media files.

this is the sample media file name to download from bandwidth.

'...Home%281%29-m-m4dh5ymogubeh7i37gsgycq.jpg'

By the way, quote() function change the name such as following
'...Home%25281%2529-m-m4dh5ymogubeh7i37gsgycq.jpg'

and response is as following.

The media resource named '...Home%281%29-m-m4dh5ymogubeh7i37gsgycq.jpg' could not be found

Add more information to the Gather REST API request demos & Docs

In order to combine an audio request to the Gather, please use the prompt value of the gather request

This would look something like:

prompt = voice_api.build_sentence(sentence = "Hello from Bandwidth, please press some digits")
gather_id = voice_api.create_call_gather(call_id, prompt = prompt);

Where the voice_api.build_sentence let's you construct the prompt. If you're using audio playback, there is a similar method build_audio_playback that would be used for the prompt instead.

See the transfer docs for how an example could look.

It could also be worth adding the prompt value directly in the param list instead of relying on **kwargs, no real opinion here.

Todo

  • Add example to the Gather documentation for sentence
  • Add example to the Gather documentation for playAudio

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.