Skip to content

Commit

Permalink
VT-5285: Speak API for MPC: Go SDK Changes (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantp-plivo authored Feb 21, 2023
1 parent 1f3ac6a commit 32383e9
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion baseclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
8 changes: 8 additions & 0 deletions fixtures/mPCStartSpeakResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"api_id": "a0d4a358-b11f-11ed-ac48-0242ac110008",
"message": "speak queued into MPC",
"mpcMemberId": [
"209"
],
"mpcName": "MyMPC"
}
29 changes: 29 additions & 0 deletions multipartycall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 != "" {
Expand Down
21 changes: 21 additions & 0 deletions multipartycall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit 32383e9

Please sign in to comment.