Skip to content

Commit 8136061

Browse files
authored
add customContext support for create call and redirect call (Azure#34241)
* add customContext support for create call and redirect call * Fix typo
1 parent a51007c commit 8136061

File tree

4 files changed

+100
-6
lines changed

4 files changed

+100
-6
lines changed

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/CallAutomationAsyncClient.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.azure.communication.callautomation.models.CreateCallOptions;
2323
import com.azure.communication.callautomation.implementation.models.CommunicationIdentifierModel;
2424
import com.azure.communication.callautomation.implementation.models.CreateCallRequestInternal;
25+
import com.azure.communication.callautomation.implementation.models.CustomContext;
2526
import com.azure.communication.callautomation.implementation.models.AnswerCallRequestInternal;
2627
import com.azure.communication.callautomation.implementation.models.RedirectCallRequestInternal;
2728
import com.azure.communication.callautomation.implementation.models.RejectCallRequestInternal;
@@ -188,6 +189,13 @@ private CreateCallRequestInternal getCreateCallRequestInternal(CreateGroupCallOp
188189
.setTargets(targetsModel)
189190
.setCallbackUri(createCallGroupOptions.getCallbackUrl())
190191
.setOperationContext(createCallGroupOptions.getOperationContext());
192+
193+
if (createCallGroupOptions.getSipHeaders() != null || createCallGroupOptions.getVoipHeaders() != null) {
194+
CustomContext customContext = new CustomContext();
195+
customContext.setSipHeaders(createCallGroupOptions.getSipHeaders());
196+
customContext.setVoipHeaders(createCallGroupOptions.getVoipHeaders());
197+
request.setCustomContext(customContext);
198+
}
191199

192200
if (createCallGroupOptions.getMediaStreamingConfiguration() != null) {
193201
MediaStreamingConfigurationInternal streamingConfigurationInternal =
@@ -237,6 +245,14 @@ private CreateCallRequestInternal getCreateCallRequestInternal(CreateCallOptions
237245
.setTargets(targetsModel)
238246
.setCallbackUri(createCallOptions.getCallbackUrl())
239247
.setOperationContext(createCallOptions.getOperationContext());
248+
249+
// Need to do a null check since SipHeaders and VoipHeaders are optional; If they both are null then we do not need to set custom context
250+
if (createCallOptions.getCallInvite().getSipHeaders() != null || createCallOptions.getCallInvite().getVoipHeaders() != null) {
251+
CustomContext customContext = new CustomContext();
252+
customContext.setSipHeaders(createCallOptions.getCallInvite().getSipHeaders());
253+
customContext.setVoipHeaders(createCallOptions.getCallInvite().getVoipHeaders());
254+
request.setCustomContext(customContext);
255+
}
240256

241257
if (createCallOptions.getMediaStreamingConfiguration() != null) {
242258
MediaStreamingConfigurationInternal streamingConfigurationInternal =
@@ -366,7 +382,15 @@ Mono<Response<Void>> redirectCallWithResponseInternal(RedirectCallOptions redire
366382

367383
RedirectCallRequestInternal request = new RedirectCallRequestInternal()
368384
.setIncomingCallContext(redirectCallOptions.getIncomingCallContext())
369-
.setTarget(CommunicationIdentifierConverter.convert(redirectCallOptions.getTargetCallImvite().getTarget()));
385+
.setTarget(CommunicationIdentifierConverter.convert(redirectCallOptions.getTargetCallInvite().getTarget()));
386+
387+
// Need to do a null check since SipHeaders and VoipHeaders are optional; If they both are null then we do not need to set custom context
388+
if (redirectCallOptions.getTargetCallInvite().getSipHeaders() != null || redirectCallOptions.getTargetCallInvite().getVoipHeaders() != null) {
389+
CustomContext customContext = new CustomContext();
390+
customContext.setSipHeaders(redirectCallOptions.getTargetCallInvite().getSipHeaders());
391+
customContext.setVoipHeaders(redirectCallOptions.getTargetCallInvite().getVoipHeaders());
392+
request.setCustomContext(customContext);
393+
}
370394

371395
return azureCommunicationCallAutomationServiceInternal.redirectCallWithResponseAsync(request,
372396
context)

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/models/CreateGroupCallOptions.java

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.azure.core.annotation.Fluent;
99

1010
import java.util.List;
11+
import java.util.Map;
1112

1213
/**
1314
* The options for creating a group call.
@@ -38,9 +39,29 @@ public class CreateGroupCallOptions {
3839
* Media Streaming Configuration.
3940
*/
4041
private MediaStreamingOptions mediaStreamingOptions;
41-
42+
43+
/**
44+
* Display name for call source
45+
*/
4246
private String sourceDisplayName;
47+
48+
/**
49+
* PhoneNumber for call source when making PSTN call
50+
*/
4351
private PhoneNumberIdentifier sourceCallIdNumber;
52+
53+
/**
54+
* Custom Context for PSTN targets
55+
*/
56+
private Map<String, String> sipHeaders;
57+
58+
/**
59+
* Custom Context for Voip targets
60+
*/
61+
private Map<String, String> voipHeaders;
62+
63+
64+
4465

4566
/**
4667
* Constructor
@@ -116,6 +137,22 @@ public String getSourceDisplayName() {
116137
public PhoneNumberIdentifier getSourceCallIdNumber() {
117138
return sourceCallIdNumber;
118139
}
140+
141+
/**
142+
* Get Custom Context for PSTN targets
143+
* @return Custom Context for PSTN targets
144+
*/
145+
public Map<String, String> getSipHeaders() {
146+
return sipHeaders;
147+
}
148+
149+
/**
150+
* Get Custom Context for Voip targets
151+
* @return Custom Context for Voip targets
152+
*/
153+
public Map<String, String> getVoipHeaders() {
154+
return voipHeaders;
155+
}
119156

120157
/**
121158
* Set the operationContext: A customer set value used to track the answering of a call.
@@ -170,4 +207,28 @@ public CreateGroupCallOptions setSourceCallIdNumber(PhoneNumberIdentifier source
170207
this.sourceCallIdNumber = sourceCallIdNumber;
171208
return this;
172209
}
210+
211+
212+
/**
213+
* Set Custom Context for PSTN targets
214+
* @param sipHeaders collection of Custom Context for PSTN targets
215+
* @return the CreateGroupCallOptions object itself
216+
*/
217+
public CreateGroupCallOptions setSipHeaders(Map<String, String> sipHeaders) {
218+
this.sipHeaders = sipHeaders;
219+
return this;
220+
}
221+
222+
223+
/**
224+
* Set Custom Context for Voip targets
225+
* @param voipHeaders collection of Custom Context for Voip targets
226+
* @return the CreateGroupCallOptions object itself
227+
*/
228+
public CreateGroupCallOptions setVoipHeaders(Map<String, String> voipHeaders) {
229+
this.voipHeaders = voipHeaders;
230+
return this;
231+
}
232+
233+
173234
}

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/models/RedirectCallOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public String getIncomingCallContext() {
4444
* Information of target of being redirected to
4545
* @return the callInvite to redirect target
4646
*/
47-
public CallInvite getTargetCallImvite() {
47+
public CallInvite getTargetCallInvite() {
4848
return targetCallInvite;
4949
}
5050
}

sdk/communication/azure-communication-callautomation/src/test/java/com/azure/communication/callautomation/CallAutomationAsyncClientUnitTests.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
import java.util.AbstractMap;
2121
import java.util.ArrayList;
2222
import java.util.Collections;
23+
import java.util.HashMap;
2324
import java.util.List;
25+
import java.util.Map;
2426

2527
import static org.junit.jupiter.api.Assertions.assertEquals;
2628
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -59,10 +61,14 @@ public void createGroupCallWithResponse() {
5961
new AbstractMap.SimpleEntry<>(generateCallProperties(CALL_CONNECTION_ID, CALL_SERVER_CALL_ID,
6062
CALL_CALLER_ID, CALL_CALLER_DISPLAY_NAME, CALL_TARGET_ID, CALL_CONNECTION_STATE, CALL_SUBJECT, CALL_CALLBACK_URL, MEDIA_SUBSCRIPTION_ID), 201)
6163
)));
64+
Map<String, String> voipHeaders = new HashMap<String, String>();
65+
Map<String, String> sipHeaders = new HashMap<String, String>();
6266
List<CommunicationIdentifier> targets = new ArrayList<>(Collections.singletonList(new CommunicationUserIdentifier(CALL_TARGET_ID)));
6367
CreateGroupCallOptions callOptions = new CreateGroupCallOptions(targets, CALL_CALLBACK_URL);
6468
callOptions.setOperationContext(CALL_SUBJECT);
65-
callOptions.setMediaStreamingConfiguration(MEDIA_STREAMING_CONFIGURATION);
69+
callOptions.setMediaStreamingConfiguration(MEDIA_STREAMING_CONFIGURATION)
70+
.setSipHeaders(sipHeaders)
71+
.setVoipHeaders(voipHeaders);
6672

6773
Response<CreateCallResult> createCallResult = callAutomationAsyncClient.createCallWithResponse(callOptions).block();
6874

@@ -80,7 +86,8 @@ public void createCallWithResponse() {
8086
CALL_CALLER_ID, CALL_CALLER_DISPLAY_NAME, CALL_TARGET_ID, CALL_CONNECTION_STATE, CALL_SUBJECT, CALL_CALLBACK_URL, MEDIA_SUBSCRIPTION_ID), 201)
8187
)));
8288
//List<CommunicationIdentifier> targets = new ArrayList<>(Collections.singletonList(new CommunicationUserIdentifier(CALL_TARGET_ID)));
83-
CallInvite callInvite = new CallInvite(new CommunicationUserIdentifier(CALL_TARGET_ID));
89+
Map<String, String> voipHeaders = new HashMap<String, String>();
90+
CallInvite callInvite = new CallInvite(new CommunicationUserIdentifier(CALL_TARGET_ID), voipHeaders);
8491
CreateCallOptions callOptions = new CreateCallOptions(callInvite, CALL_CALLBACK_URL);
8592
callOptions.setOperationContext(CALL_SUBJECT);
8693
callOptions.setMediaStreamingConfiguration(MEDIA_STREAMING_CONFIGURATION);
@@ -132,7 +139,9 @@ public void redirectCall() {
132139
new AbstractMap.SimpleEntry<>("", 204)
133140
))
134141
);
135-
CallInvite target = new CallInvite(new CommunicationUserIdentifier(CALL_TARGET_ID));
142+
143+
Map<String, String> voipHeaders = new HashMap<String, String>();
144+
CallInvite target = new CallInvite(new CommunicationUserIdentifier(CALL_TARGET_ID), voipHeaders);
136145

137146
callAutomationAsyncClient.redirectCall(CALL_INCOMING_CALL_CONTEXT, target);
138147
}

0 commit comments

Comments
 (0)