From 47e7b2ad1b9082b87a2b088ce69e71d72d18d17b Mon Sep 17 00:00:00 2001 From: lunarfyre7 Date: Thu, 25 Mar 2021 14:59:38 -0700 Subject: [PATCH] add new commands to call (#58) Co-authored-by: d-telnyx <68876596+d-telnyx@users.noreply.github.com> --- lib/telnyx/call.rb | 4 +- test/telnyx/call_control_test.rb | 78 +++++++++++++++++++++----------- 2 files changed, 54 insertions(+), 28 deletions(-) diff --git a/lib/telnyx/call.rb b/lib/telnyx/call.rb index 9f567eb..5a35b8b 100644 --- a/lib/telnyx/call.rb +++ b/lib/telnyx/call.rb @@ -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, diff --git a/test/telnyx/call_control_test.rb b/test/telnyx/call_control_test.rb index f5de011..81f6535 100644 --- a/test/telnyx/call_control_test.rb +++ b/test/telnyx/call_control_test.rb @@ -67,86 +67,110 @@ 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:username@sip.non-telnyx-address.com" + assert_requested :post, format_action_url(@call, "refer") end end @@ -154,7 +178,7 @@ 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