Voice API¶
The Voice API contains all the methods to create and manage:
- Phone Calls
- Conferences
- Recordings
- Transcriptions
Client Initialization¶
Before using the sdk you must initialize a Client with your Bandwidth App Platform API credentials:
# single import
import bandwidth
voice_api = bandwidth.client('voice', 'u-user', 't-token', 's-secret')
# OR for IDE goodness with auto completes
from bandwidth import voice
voice_api = voice.Client('u-user', 't-token', 's-secret')
Create a call:
import bandwidth
voice_api = bandwidth.client('voice', 'u-user', 't-token', 's-secret')
call_id = voice_api.create_call(from_ = '+1234567890', to = '+1234567891', callback_url = "http://yoursite.com/calls")
print(call_id)
## c-abc123
my_call = api.get_call(call_id)
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',
## 'start_time' : '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:
import bandwidth
voice_api = bandwidth.client('voice', 'u-user', 't-token', 's-secret')
call_list = voice_api.list_calls(to = '+19192223333', size = 2)
print(list(call_list))
## [
## {
## 'active_time' : '2017-01-26T16:10:23Z',
## 'callback_url' : 'http://yoursite.com/calls',
## 'chargeable_duration' : 60,
## 'direction' : 'out',
## 'endTime' : '2017-01-26T16:10:33Z',
## 'events' : 'https://api.catapult.inetwork.com/v1/users/u-abc123/calls/c-abc123/events',
## 'from' : '+17079311113',
## 'id' : 'c-abc123',
## 'recording_enabled' : False,
## 'recording_file_format' : 'wav',
## 'recordings' : 'https://api.catapult.inetwork.com/v1/users/u-abc123/calls/c-abc123/recordings',
## 'start_time' : '2017-01-26T16:10:11Z',
## 'state' : 'completed',
## 'to' : '+19192223333',
## 'transcription_enabled': False,
## 'transcriptions' : 'https://api.catapult.inetwork.com/v1/users/u-abc123/calls/c-abc123/transcriptions'
## },
## {
## 'active_time' : '2016-12-29T23:50:35Z',
## 'chargeable_duration' : 60,
## 'direction' : 'out',
## 'endTime' : '2016-12-29T23:50:41Z',
## 'events' : 'https://api.catapult.inetwork.com/v1/users/u-abc123/calls/c-xyz987/events',
## 'from' : '+19194443333',
## 'id' : 'c-xyz987',
## 'recording_enabled' : False,
## 'recording_file_format' : 'wav',
## 'recordings' : 'https://api.catapult.inetwork.com/v1/users/u-abc123/calls/c-xyz987/recordings',
## 'start_time' : '2016-12-29T23:50:15Z',
## 'state' : 'completed',
## 'to' : '+19192223333',
## 'transcription_enabled': False,
## 'transcriptions' : 'https://api.catapult.inetwork.com/v1/users/u-abc123/calls/c-xyz987/transcriptions'
## }
## ]
Voice Methods¶
- Calls
- list_calls
- create_call
- get_call
- update_call
- play_audio_to_call
- send_dtmf_to_call
- list_call_recordings
- list_call_transcriptions
- list_call_events
- get_call_event
- create_call_gather
- get_call_gather
- update_call_gather
- answer_call
- reject_call
- hangup_call
- enable_call_recording
- disable_call_recording
- toggle_call_recording
- transfer_call
- Conferences
- create_conference
- get_conference
- update_conference
- play_audio_to_conference
- list_conference_members
- create_conference_member
- get_conference_member
- update_conference_member
- play_audio_to_conference_member
- speak_sentence_to_conference_member
- play_audio_file_to_conference_member
- remove_conference_member
- hold_conference_member
- mute_conference_member
- terminate_conference
- hold_conference
- mute_conference
- Bridges
- Recordings
- Transcriptions