Skip to content

Commit

Permalink
add new commands to call (#58)
Browse files Browse the repository at this point in the history
Co-authored-by: d-telnyx <[email protected]>
  • Loading branch information
pyrareae and d-telnyx authored Mar 25, 2021
1 parent 1190e7b commit 47e7b2a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 28 deletions.
4 changes: 3 additions & 1 deletion lib/telnyx/call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def id=(val)

ACTIONS = %w[reject answer hangup bridge speak fork_start fork_stop
gather_using_audio gather_using_speak playback_start
playback_stop record_start record_stop send_dtmf transfer].freeze
playback_stop record_start record_stop send_dtmf transfer
transcription_start transcription_stop record_pause
record_resume gather_stop refer].freeze

ACTIONS.each do |action|
nested_resource_class_methods action,
Expand Down
78 changes: 51 additions & 27 deletions test/telnyx/call_control_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,94 +67,118 @@ class CallControlTest < Test::Unit::TestCase
@call = Call.new
@call.id = "1234"
@call.reject cause: "CALL_REJECTED"
assert_requested :post, format_url(@call, "reject")
assert_requested :post, format_action_url(@call, "reject")
@call.answer
assert_requested :post, format_url(@call, "answer")
assert_requested :post, format_action_url(@call, "answer")
@call.hangup
assert_requested :post, format_url(@call, "hangup")
assert_requested :post, format_action_url(@call, "hangup")
@call.bridge call_control_id: SecureRandom.base64(20)
assert_requested :post, format_url(@call, "bridge")
assert_requested :post, format_action_url(@call, "bridge")
@call.speak language: "en-US", voice: "female", payload: "Telnyx call control test"
assert_requested :post, format_url(@call, "speak")
assert_requested :post, format_action_url(@call, "speak")
@call.fork_start call_control_id: SecureRandom.base64(20)
assert_requested :post, format_url(@call, "fork_start")
assert_requested :post, format_action_url(@call, "fork_start")
@call.fork_stop
assert_requested :post, format_url(@call, "fork_stop")
assert_requested :post, format_action_url(@call, "fork_stop")
@call.gather_using_audio audio_url: "https://audio.example.com"
assert_requested :post, format_url(@call, "gather_using_audio")
assert_requested :post, format_action_url(@call, "gather_using_audio")
@call.gather_using_speak language: "en-US", voice: "female", payload: "Telnyx call control test"
assert_requested :post, format_url(@call, "gather_using_speak")
assert_requested :post, format_action_url(@call, "gather_using_speak")
@call.playback_start audio_url: "https://audio.example.com"
assert_requested :post, format_url(@call, "playback_start")
assert_requested :post, format_action_url(@call, "playback_start")
@call.playback_stop
assert_requested :post, format_url(@call, "playback_stop")
assert_requested :post, format_action_url(@call, "playback_stop")
@call.send_dtmf digits: "1www2WABCDw9"
assert_requested :post, format_url(@call, "send_dtmf")
assert_requested :post, format_action_url(@call, "send_dtmf")
@call.transfer to: "+15552223333"
assert_requested :post, format_url(@call, "transfer")
assert_requested :post, format_action_url(@call, "transfer")
end
end

context "commands" do
should "reject" do
@call.reject cause: "CALL_REJECTED"
assert_requested :post, format_url(@call, "reject")
assert_requested :post, format_action_url(@call, "reject")
end
should "answer" do
@call.answer
assert_requested :post, format_url(@call, "answer")
assert_requested :post, format_action_url(@call, "answer")
end
should "hangup" do
@call.hangup
assert_requested :post, format_url(@call, "hangup")
assert_requested :post, format_action_url(@call, "hangup")
end
should "bridge" do
@call.bridge call_control_id: SecureRandom.base64(20)
assert_requested :post, format_url(@call, "bridge")
assert_requested :post, format_action_url(@call, "bridge")
end
should "speak" do
@call.speak language: "en-US", voice: "female", payload: "Telnyx call control test"
assert_requested :post, format_url(@call, "speak")
assert_requested :post, format_action_url(@call, "speak")
end
should "start fork" do
@call.fork_start call_control_id: SecureRandom.base64(20)
assert_requested :post, format_url(@call, "fork_start")
assert_requested :post, format_action_url(@call, "fork_start")
end
should "stop fork" do
@call.fork_stop
assert_requested :post, format_url(@call, "fork_stop")
assert_requested :post, format_action_url(@call, "fork_stop")
end
should "gather using audio" do
@call.gather_using_audio audio_url: "https://audio.example.com"
assert_requested :post, format_url(@call, "gather_using_audio")
assert_requested :post, format_action_url(@call, "gather_using_audio")
end
should "gather using speak" do
@call.gather_using_speak language: "en-US", voice: "female", payload: "Telnyx call control test"
assert_requested :post, format_url(@call, "gather_using_speak")
assert_requested :post, format_action_url(@call, "gather_using_speak")
end
should "playback start" do
@call.playback_start audio_url: "https://audio.example.com"
assert_requested :post, format_url(@call, "playback_start")
assert_requested :post, format_action_url(@call, "playback_start")
end
should "playback stop" do
@call.playback_stop
assert_requested :post, format_url(@call, "playback_stop")
assert_requested :post, format_action_url(@call, "playback_stop")
end
should "send dtmf" do
@call.send_dtmf digits: "1www2WABCDw9"
assert_requested :post, format_url(@call, "send_dtmf")
assert_requested :post, format_action_url(@call, "send_dtmf")
end
should "transfer" do
@call.transfer to: "+15552223333"
assert_requested :post, format_url(@call, "transfer")
assert_requested :post, format_action_url(@call, "transfer")
end
should "start transcription" do
@call.transcription_start
assert_requested :post, format_action_url(@call, "transcription_start")
end
should "end transcription" do
@call.transcription_stop
assert_requested :post, format_action_url(@call, "transcription_stop")
end
should "pause recording" do
@call.record_pause
assert_requested :post, format_action_url(@call, "record_pause")
end
should "resume recording" do
@call.record_resume
assert_requested :post, format_action_url(@call, "record_resume")
end
should "gather stop" do
@call.gather_stop
assert_requested :post, format_action_url(@call, "gather_stop")
end
should "refer" do
@call.refer sip_address: "sip:[email protected]"
assert_requested :post, format_action_url(@call, "refer")
end
end

def create_call
Telnyx::Call.create connection_id: "12345", to: "+15550001111", from: "+15550002222", cause: "test"
end

def format_url(call, action)
def format_action_url(call, action)
"#{Telnyx.api_base}/v2/calls/#{call.call_control_id}/actions/#{action}"
end
end
Expand Down

0 comments on commit 47e7b2a

Please sign in to comment.