Created
August 21, 2015 16:59
-
-
Save jarodreyes/dbbdb8275b6c7c35ada8 to your computer and use it in GitHub Desktop.
All recordings for a phone number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# GET /recordings/:agent | |
def show | |
@agent_number = params[:agent] | |
@recordings = recordings_for_agent(@agent_number) | |
end | |
def call_sids(number) | |
# store the sids here | |
@call_sids = [] | |
# all calls to our agent number | |
@calls = @client.account.calls.list({ | |
to: number | |
}).each do |call| | |
@call_sids.push call.sid | |
end | |
return @call_sids | |
end | |
# filter the recordings by call_sid | |
def recordings_for_call(call_sid) | |
@response = {} | |
@client.account.recordings.list({ | |
call_sid: call_sid | |
}).each do |recording| | |
if recording.uri | |
recording_object = { | |
'url' => recording.uri + ".mp3", # does twilio-ruby force a .json extension? | |
'transcription' => recording.transcriptions.list[0].transcription_text | |
} | |
@response = recording_object | |
end | |
end | |
# break here if no response | |
return if @response.empty? | |
return @response | |
end | |
# get the recordings for each call_sid made to this agent and add | |
# to a list of recordings | |
def recordings_for_agent(number) | |
recordings = [] | |
call_sids(number).each do |call_sid| | |
call_recordings = recordings_for_call(call_sid) | |
if call_recordings | |
recordings.push call_recordings | |
end | |
end | |
return recordings | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment