diff --git a/CHANGELOG.md b/CHANGELOG.md index e54d6ed..97562cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## [7.21.0](https://github.com/plivo/plivo-go/tree/v7.21.0) (2023-02-21) +**Feature - MPC Speak API** +- Added functionality to start and stop Speak in an MPC + ## [7.20.0](https://github.com/plivo/plivo-go/tree/v7.20.0) (2023-02-20) **Feature - MPC API** - Added support for agent_hold_nusic and customer_hold_music in the XML generation diff --git a/baseclient.go b/baseclient.go index b78fa9d..1fae301 100644 --- a/baseclient.go +++ b/baseclient.go @@ -13,7 +13,7 @@ import ( "github.com/google/go-querystring/query" ) -const sdkVersion = "7.20.0" +const sdkVersion = "7.21.0" const lookupBaseUrl = "lookup.plivo.com" diff --git a/fixtures/mPCStartSpeakResponse.json b/fixtures/mPCStartSpeakResponse.json new file mode 100644 index 0000000..a0d0d37 --- /dev/null +++ b/fixtures/mPCStartSpeakResponse.json @@ -0,0 +1,8 @@ +{ + "api_id": "a0d4a358-b11f-11ed-ac48-0242ac110008", + "message": "speak queued into MPC", + "mpcMemberId": [ + "209" + ], + "mpcName": "MyMPC" +} \ No newline at end of file diff --git a/multipartycall.go b/multipartycall.go index cb082cc..4263048 100644 --- a/multipartycall.go +++ b/multipartycall.go @@ -203,6 +203,13 @@ type MultiPartyCallAudioResponse struct { FriendlyName string `json:"mpcName,omitempty" url:"mpcName,omitempty"` } +type MultiPartyCallSpeakParams struct { + Text string `json:"text" url:"text"` + Voice string `json:"voice" url:"voice,omitempty"` + Language string `json:"language" url:"language,omitempty"` + Mix bool `json:"mix" url:"mix,omitempty"` +} + func (service *MultiPartyCallService) List(params MultiPartyCallListParams) (response *MultiPartyCallListResponse, err error) { req, err := service.client.NewRequest("GET", params, "MultiPartyCall") if err != nil { @@ -424,6 +431,28 @@ func (service *MultiPartyCallService) StopPlayAudio(basicParams MultiPartyCallPa err = service.client.ExecuteRequest(req, nil, isVoiceRequest()) return } + +func (service *MultiPartyCallService) StartSpeak(basicParams MultiPartyCallParticipantParams, params MultiPartyCallSpeakParams) (response *MultiPartyCallAudioResponse, err error) { + mpcId := MakeMPCId(basicParams.MpcUuid, basicParams.FriendlyName) + req, err := service.client.NewRequest("POST", params, "MultiPartyCall/%s/Member/%s/Speak", mpcId, basicParams.ParticipantId) + if err != nil { + return + } + response = &MultiPartyCallAudioResponse{} + err = service.client.ExecuteRequest(req, response, isVoiceRequest()) + return +} + +func (service *MultiPartyCallService) StopSpeak(basicParams MultiPartyCallParticipantParams) (err error) { + mpcId := MakeMPCId(basicParams.MpcUuid, basicParams.FriendlyName) + req, err := service.client.NewRequest("DELETE", nil, "MultiPartyCall/%s/Member/%s/Speak", mpcId, basicParams.ParticipantId) + if err != nil { + return + } + err = service.client.ExecuteRequest(req, nil, isVoiceRequest()) + return +} + func MakeMPCId(MpcUuid string, FriendlyName string) string { mpcId := "" if MpcUuid != "" { diff --git a/multipartycall_test.go b/multipartycall_test.go index f88a2f8..4315edc 100644 --- a/multipartycall_test.go +++ b/multipartycall_test.go @@ -193,3 +193,24 @@ func TestMPCService_StopPlayAudio(t *testing.T) { } assertRequest(t, "DELETE", "MultiPartyCall/%s/Member/%s/Play", "uuid_ebacced2-21ab-466d-9df4-67339991761b", "209") } + +func TestMultiPartyCallService_StartSpeak(t *testing.T) { + expectResponse("MPCStartSpeakResponse.json", 202) + + if response, err := client.MultiPartyCall.StartSpeak(MultiPartyCallParticipantParams{FriendlyName: "MyMPC", ParticipantId: "209"}, MultiPartyCallSpeakParams{Text: "Hello", Language: "en-UK", Voice: "WOMAN", Mix: false}); err != nil { + panic(err) + } else { + log.Println(response) + } + + assertRequest(t, "POST", "MultiPartyCall/%s/Member/%s/Speak", "name_MyMPC", "209") +} + +func TestMultiPartyCallService_StopSpeak(t *testing.T) { + expectResponse("", 204) + + if err := client.MultiPartyCall.StopSpeak(MultiPartyCallParticipantParams{FriendlyName: "MyMPC", ParticipantId: "209"}); err != nil { + panic(err) + } + assertRequest(t, "DELETE", "MultiPartyCall/%s/Member/%s/Speak", "name_MyMPC", "209") +}