diff --git a/src/Plivo/Resources/MultiPartyCall/MultiPartyCallInterface.php b/src/Plivo/Resources/MultiPartyCall/MultiPartyCallInterface.php index 326936d7..ecd58e4f 100644 --- a/src/Plivo/Resources/MultiPartyCall/MultiPartyCallInterface.php +++ b/src/Plivo/Resources/MultiPartyCall/MultiPartyCallInterface.php @@ -744,4 +744,56 @@ public function getParticipant($participantId, array $optionalArgs = []){ ); return $response->getContent(); } + + public function startPlayAudio($participantId, $url, array $optionalArgs = []){ + MPCUtils::validParam('participantId', $participantId, ['string', 'integer'], true); + MPCUtils::validUrl('url', $url, true); + if(isset($optionalArgs['uuid'])){ + MPCUtils::validParam('uuid', $optionalArgs['uuid'], ['string'],false); + } + if(isset($optionalArgs['friendly_name'])){ + MPCUtils::validParam('friendly_name', $optionalArgs['friendly_name'], ['string'],false); + } + if(!isset($optionalArgs['uuid'])){ + $optionalArgs['uuid'] = null; + } + if(!isset($optionalArgs['friendly_name'])){ + $optionalArgs['friendly_name'] = null; + } + $mpcId = self::mpcId($optionalArgs['uuid'], $optionalArgs['friendly_name']); + unset($optionalArgs['uuid']); + unset($optionalArgs['friendly_name']); + $mandatoryArgs = ['url' => $url]; + $optionalArgs['isVoiceRequest'] = true; + $response = $this->client->update( + $this->uri. $mpcId. '/Member/'. $participantId. '/Play/', + array_merge($mandatoryArgs, $optionalArgs) + ); + return $response->getContent(); + } + + public function stopPlayAudio($participantId, array $optionalArgs = []){ + MPCUtils::validParam('participantId', $participantId, ['string', 'integer'], true); + if(isset($optionalArgs['uuid'])){ + MPCUtils::validParam('uuid', $optionalArgs['uuid'], ['string'],false); + } + if(isset($optionalArgs['friendly_name'])){ + MPCUtils::validParam('friendly_name', $optionalArgs['friendly_name'], ['string'],false); + } + if(!isset($optionalArgs['uuid'])){ + $optionalArgs['uuid'] = null; + } + if(!isset($optionalArgs['friendly_name'])){ + $optionalArgs['friendly_name'] = null; + } + $mpcId = self::mpcId($optionalArgs['uuid'], $optionalArgs['friendly_name']); + unset($optionalArgs['uuid']); + unset($optionalArgs['friendly_name']); + $optionalArgs['isVoiceRequest'] = true; + $response = $this->client->delete( + $this->uri. $mpcId. '/Member/'. $participantId. '/Play/', + $optionalArgs + ); + return $response->getContent(); + } } \ No newline at end of file diff --git a/tests/Mocks/multiPartyCallsStartParticipantRecordingResponse.json b/tests/Mocks/multiPartyCallsStartParticipantRecordingResponse.json new file mode 100644 index 00000000..088197e4 --- /dev/null +++ b/tests/Mocks/multiPartyCallsStartParticipantRecordingResponse.json @@ -0,0 +1,6 @@ +{ + "api_id": "036c80f3-3721-11ec-a678-0242ac110002", + "message": "MPC: samplempc participant record started", + "recording_id": "24670db8-c723-4ba2-8521-f10ec41ddf8b", + "recording_url": "https://media-qa.voice.plivodev.com/v1/Account/MAXXXXXXXXXXXX/Recording/XXXXX-XXXX-XXXX-XXXXX.mp3" +} \ No newline at end of file diff --git a/tests/Mocks/multiPartyCallsStartPlayAudioResponse.json b/tests/Mocks/multiPartyCallsStartPlayAudioResponse.json new file mode 100644 index 00000000..f1dc9a68 --- /dev/null +++ b/tests/Mocks/multiPartyCallsStartPlayAudioResponse.json @@ -0,0 +1,8 @@ +{ + "api_id": "c07db813-3721-11ec-8bcd-0242ac110008", + "message": "play queued into MPC", + "mpcMemberId": [ + "1003" + ], + "mpcName": "samplempc" +} \ No newline at end of file diff --git a/tests/Resources/MultiPartyCallTest.php b/tests/Resources/MultiPartyCallTest.php index eb043dee..c0135bd4 100644 --- a/tests/Resources/MultiPartyCallTest.php +++ b/tests/Resources/MultiPartyCallTest.php @@ -49,6 +49,7 @@ function testMPCAddParticipant(){ 'confirm_key_sound_method'=> 'GET', 'dial_music'=> 'Real', 'ring_timeout'=> 45, + 'delay_dial'=> 0, 'max_duration'=> 14400, 'max_participants'=> 10, 'wait_music_method'=> 'GET', @@ -70,7 +71,7 @@ function testMPCAddParticipant(){ 'enter_sound'=> 'beep:1', 'enter_sound_method'=> 'GET', 'exit_sound'=> 'beep:2', - 'exit_sound_method'=> 'GET', + 'exit_sound_method'=> 'GET' ]); $body = file_get_contents(__DIR__ . '/../Mocks/multiPartyCallsAddParticipantResponse.json'); @@ -218,9 +219,94 @@ function testMPCGetParticipant(){ ); $body = file_get_contents(__DIR__ . '/../Mocks/multiPartyCallsGetParticipantResponse.json'); - $this->mock(new PlivoResponse($request,200)); + $this->mock(new PlivoResponse($request,200, $body)); $actual = $this->client->multiPartyCalls->getParticipant(10, ['uuid' => '12345678-90123456']); $this->assertRequest($request); self::assertNotNull($actual); } + + function testMPCStartParticipantRecording(){ + $request = new PlivoRequest( + 'POST', + 'Account/MAXXXXXXXXXXXXXXXXXX/MultiPartyCall/uuid_12345678-90123456/Participant/10/Record/', + ['file_format'=> 'wav', + 'status_callback_url'=> 'https://plivo.com/status', + 'status_callback_method'=> 'POST'] + ); + $body = file_get_contents(__DIR__ . '/../Mocks/multiPartyCallsStartParticipantRecordingResponse.json'); + + $this->mock(new PlivoResponse($request,200)); + $actual = $this->client->multiPartyCalls->startParticipantRecording(10, ['uuid' => '12345678-90123456', + 'file_format'=> 'wav', + 'status_callback_url'=> 'https://plivo.com/status', + 'status_callback_method'=> 'POST']); + $this->assertRequest($request); + self::assertNotNull($actual); + } + + function testMPCStopParticipantRecording(){ + $request = new PlivoRequest( + 'DELETE', + 'Account/MAXXXXXXXXXXXXXXXXXX/MultiPartyCall/uuid_12345678-90123456/Participant/10/Record/', + [] + ); + + $this->mock(new PlivoResponse($request,204)); + $actual = $this->client->multiPartyCalls->stopParticipantRecording(10, ['uuid' => '12345678-90123456']); + $this->assertRequest($request); + self::assertNotNull($actual); + } + + function testMPCPauseParticipantRecording(){ + $request = new PlivoRequest( + 'POST', + 'Account/MAXXXXXXXXXXXXXXXXXX/MultiPartyCall/uuid_12345678-90123456/Participant/10/Record/Pause/', + [] + ); + + $this->mock(new PlivoResponse($request,204)); + $actual = $this->client->multiPartyCalls->pauseParticipantRecording(10, ['uuid' => '12345678-90123456']); + $this->assertRequest($request); + self::assertNotNull($actual); + } + + function testMPCResumeParticipantRecording(){ + $request = new PlivoRequest( + 'POST', + 'Account/MAXXXXXXXXXXXXXXXXXX/MultiPartyCall/uuid_12345678-90123456/Participant/10/Record/Resume/', + [] + ); + + $this->mock(new PlivoResponse($request,204)); + $actual = $this->client->multiPartyCalls->resumeParticipantRecording(10, ['uuid' => '12345678-90123456']); + $this->assertRequest($request); + self::assertNotNull($actual); + } + + function testMPCStartPlayAudio(){ + $request = new PlivoRequest( + 'POST', + 'Account/MAXXXXXXXXXXXXXXXXXX/MultiPartyCall/uuid_12345678-90123456/Member/10/Play/', + ['url' => 'https://s3.amazonaws.com/XXX/XXX.mp3'] + ); + $body = file_get_contents(__DIR__ . '/../Mocks/multiPartyCallsStartPlayAudioResponse.json'); + + $this->mock(new PlivoResponse($request,202, $body)); + $actual = $this->client->multiPartyCalls->startPlayAudio(10, "https://s3.amazonaws.com/XXX/XXX.mp3", ['uuid' => '12345678-90123456']); + $this->assertRequest($request); + self::assertNotNull($actual); + } + + function testMPCStopPlayAudio(){ + $request = new PlivoRequest( + 'DELETE', + 'Account/MAXXXXXXXXXXXXXXXXXX/MultiPartyCall/uuid_12345678-90123456/Member/10/Play/', + [] + ); + + $this->mock(new PlivoResponse($request,204)); + $actual = $this->client->multiPartyCalls->stopPlayAudio(10, ['uuid' => '12345678-90123456']); + $this->assertRequest($request); + self::assertNotNull($actual); + } } \ No newline at end of file