twilio-java
twilio-java copied to clipboard
How to record and play voice message after conference call got created if required
Issue Summary
Hi team
Here is my case.
- Create a conference call.
- Record and Play voice message if required
- Add participants to the call
- End conference call
Steps to Reproduce
My TwiML Response
Create conference call api
Add Participant
End conference API using conference id
Code Snippet
Create TwiMl
@PostMapping(value = "/twiml", produces = "text/xml")
public String generateTwiml() throws URISyntaxException {
System.out.println( "IncomingCallWebhook().generateTwiml()" );
Conference conferenceBuilder = new Conference.Builder( CONFERENCE_ROOM_NAME )//
.record( Conference.Record.RECORD_FROM_START )//
.recordingStatusCallback( new URI( PUBLIC_URL + "recordCallBack" ) )//
.recordingStatusCallbackEvents( Conference.RecordingEvent.COMPLETED )//
.startConferenceOnEnter( true ).endConferenceOnExit( true ).statusCallback( new URI( PUBLIC_URL + "callback" ) )//
.statusCallbackMethod( HttpMethod.POST )//
.statusCallbackEvents( Arrays.asList( Conference.Event.START, Conference.Event.END, Conference.Event.JOIN, Conference.Event.LEAVE, Conference.Event.HOLD, Conference.Event.SPEAKER ) ).build();
Say say = new Say.Builder( "Hi! Welcome" ).voice( Voice.WOMAN ).language( Language.EN_US ).build();
Record record1 = new Record.Builder().timeout( 10 ).action( new URI( PUBLIC_URL + "recordVmCallback" ) ).method( HttpMethod.POST )//
.recordingStatusCallback( new URI( PUBLIC_URL + "recordVmUrl" ) ).recordingStatusCallbackMethod( HttpMethod.POST ).recordingStatusCallbackEvents( Record.RecordingEvent.COMPLETED ).build();
Say say2 = new Say.Builder( "I did not receive a recording" ).build();
return new VoiceResponse.Builder().say( say )// .record( record1 ).say( say2 )// .play( play )
.dial( new Dial.Builder().conference( conferenceBuilder ).build() ).build().toXml();
}
Create conference code
@PostMapping(value = "/createConference")
public ResponseEntity<ObjectNode> createConference( @RequestBody ObjectNode objectNode ) throws URISyntaxException, InterruptedException {
System.out.println( "IncomingCallWebhook().createConference() objectNode = " + objectNode );
ObjectNode response = JsonNodeFactory.instance.objectNode();
Twilio.init( objectNode.get( "sid" ).asText(), objectNode.get( "auth" ).asText() );
Call call = Call.creator( new PhoneNumber( objectNode.get( "to" ).asText() ), new PhoneNumber( objectNode.get( "from" ).asText() ), new URI( PUBLIC_URL + "twiml" ) )//
.setStatusCallbackEvent( Arrays.asList( "initiated", "ringing", "answered", "completed" ) ).setStatusCallback( new URI( PUBLIC_URL + "call/callback" ) )//
// .setRecord( true )//
.setStatusCallbackMethod( HttpMethod.POST ).create();
response.put( "callid", call.getSid() );
return ResponseEntity.ok( response );
}
Add Participant
@PostMapping(value = "/addParticipant")
public ResponseEntity<String> addParticipant( @RequestBody ObjectNode objectNode ) throws URISyntaxException {
System.out.println( "IncomingCallWebhook().updateConference() objectNode = " + objectNode );
Twilio.init( objectNode.get( "sid" ).asText(), objectNode.get( "auth" ).asText() );
Participant participant = Participant//
.creator( objectNode.get( "cid" ).asText(), new PhoneNumber( objectNode.get( "from" ).asText() ), new PhoneNumber( objectNode.get( "to" ).asText() ) )//
// .setRecord( true )
.create();
return ResponseEntity.ok( participant.toString() );
}
End confernce
@PostMapping(value = "/updateConference")
public ResponseEntity<String> updateConference( @RequestBody ObjectNode objectNode ) throws URISyntaxException {
System.out.println( "IncomingCallWebhook().updateConference() objectNode = " + objectNode );
Twilio.init( objectNode.get( "sid" ).asText(), objectNode.get( "auth" ).asText() );
com.twilio.rest.api.v2010.account.Conference conference = com.twilio.rest.api.v2010.account.Conference.updater( objectNode.get( "cid" ).asText() ).setStatus( com.twilio.rest.api.v2010.account.Conference.UpdateStatus.COMPLETED ).update();
return ResponseEntity.ok( conference.toString() );
}
Technical details:
- twilio-java version: 7.48.0
- java version:amazon corretto 11
Hi Team Can some one help me to implement record and play voice message ?
Thanks is advance.
Hi @Rajesh-Thiyagarajan, Thank you for for taking the time to report this. I would request you to go through this link, and if it doesn't provide information that you are looking for, please file a support ticket here. Thanks!