Alibaba Cloud Contact Center
Smart Conversation Analysis (SCA) supports integration with Alibaba Cloud Contact Center. You can choose between two integration methods: automatic integration and manual integration.
Automatic integration
Recordings from Cloud Contact Center (CCC) can be automatically pushed to Smart Conversation Analysis (SCA) for quality checks. For more information, see Quality Inspection Push Management.
Manual integration
If automatic integration does not meet your requirements, you can use the SDK to initiate a quality check.
Procedure
Call the GetUploadAudioDataParams operation of the CCC SDK to get audio information.
For more information, see GetUploadAudioDataParams.
Assemble the jsonStr input parameter.
For more information, see Upload audio for quality check.
Call the UploadAudioData operation of the SCA SDK to initiate a quality check.
Java code example
Maven dependencies for the CCC and quality check SDKs. The fastjson dependency is optional.
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>ccc20200701</artifactId>
<version>2.6.7</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-qualitycheck</artifactId>
<version>3.0.7</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.0.6</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83_noneautotype</version>
</dependency>Complete example
Before you call the API, you must configure environment variables to read your access credentials. For configuration instructions, see Configure access credentials for the Java SDK.
Environment variables for the CCC AccessKey ID and AccessKey Secret: CC_AK_ENV, CC_SK_ENV
Environment variables for the SCA AccessKey ID and AccessKey Secret: SCA_AK_ENV, SCA_SK_ENV
package com.aliyun.sample;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.ccc20200701.models.GetUploadAudioDataParamsResponse;
import com.aliyun.tea.TeaException;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.aliyuncs.qualitycheck.model.v20190115.UploadAudioDataRequest;
import com.aliyuncs.qualitycheck.model.v20190115.UploadAudioDataResponse;
/**
* Demonstrates how to retrieve audio information from Cloud Contact Center (CCC) and initiate a quality check.
* Prerequisites:
* 1. The contactId and instanceId for the audio recording in CCC.
* 2. (Optional) Other parameters in the jsonStr for UploadAudioData. Add them as needed.
*/
public class Sample {
/**
* Initializes the Cloud Contact Center (CCC) client by reading the AccessKey from environment variables.
* @return Client
* @throws Exception
*/
public static com.aliyun.ccc20200701.Client createCCClient() throws Exception {
// Using an Alibaba Cloud account's AccessKey poses a high security risk because it grants full permissions on all APIs. We strongly recommend that you create and use a RAM user for API calls and routine operations. To create a RAM user, log on to the RAM console.
// This example shows how to store the AccessKey ID and AccessKey Secret in environment variables. You can also store them in a configuration file based on your business needs.
// For security reasons, do not hard-code the AccessKey ID or AccessKey Secret in your code. This can lead to credential leaks.
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
.setAccessKeyId(System.getenv("CC_AK_ENV"))
.setAccessKeySecret(System.getenv("CC_SK_ENV"));
// The endpoint for Cloud Contact Center (CCC). This example uses the China (Shanghai) region.
config.endpoint = "ccc.cn-shanghai.aliyuncs.com";
return new com.aliyun.ccc20200701.Client(config);
}
/**
* Initializes the Smart Conversation Analysis (SCA) client by reading the AccessKey from environment variables.
* @return Client
* @throws Exception
*/
public static IAcsClient createSCAClient() throws Exception {
// Using an Alibaba Cloud account's AccessKey poses a high security risk because it grants full permissions on all APIs. We strongly recommend that you create and use a RAM user for API calls and routine operations. To create a RAM user, log on to the RAM console.
// This example shows how to store the AccessKey ID and AccessKey Secret in environment variables. You can also store them in a configuration file based on your business needs.
// For security reasons, do not hard-code the AccessKey ID or AccessKey Secret in your code. This can lead to credential leaks.
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", System.getenv("SCA_AK_ENV"), System.getenv("SCA_SK_ENV"));
// Specify the service endpoint. The following value is fixed.
DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Qualitycheck", "qualitycheck.cn-hangzhou.aliyuncs.com");
return new DefaultAcsClient(profile);
}
/**
* Calls the Cloud Contact Center (CCC) SDK to get audio parameters.
* @param args_
* @throws Exception
*/
public static void main(String[] args_) throws Exception {
/**
* 1. Call the Cloud Contact Center (CCC) SDK to get audio information.
* For a detailed example, see https://help.aliyun.com/document_detail/450651.html
* Replace the placeholder "contactId" and "instanceId" strings with the actual IDs from your audio recording in the CCC console.
*/
String ccAudioStr = getParamStr("contactId","instanceId");
/**
* Example of the ccAudioStr return value. The validTimes and channels fields are required. Other fields can be retrieved as needed.
* {
* "autoSplit":1,
* "appKey":1**********1,
* "sampleRate":8,
* "callList":[
* {
* "callId":"job-2********8",
* "validTimes":[
* {
* "begin_time":0,
* "end_time":67060,
* "speaker_id":"xuan"
* }
* ],
* "resolveType":"ali-ACC",
* "instance":"report-test-2",
* "callee":"1********2",
* "accUid":1********1,
* "callStartTime":1659444574225,
* "customerServiceName":"x****qi",
* "tid":"760427ac-fa3f-4785-8286-1cb2cf3104b9",
* "callType":1,
* "skillGroupUUID":"listTest@report-test-2",
* "caller":"0********8",
* "customerServicePhone":"8********7",
* "channels":[
* {
* "speaker_id":"x****o",
* "channel_key":"ch-user-1********2-8********7-1********6-job-2********8"
* }
* ],
* "sourceType":1,
* "channelKey":"ch-user-1********2-8********7-1********6-job-2********8",
* "skillGroupName":"listTest",
* "voiceFileUrl":"https://ccc-v2-staging.oss-cn-hangzhou.aliyuncs.com/ccc-record-mixed/report-test-2/2022/08/job-2********8.mkv?Expires=1663124613&OSSAccessKeyId=L********q&Signature=bxLnpftFnn4h1GU1FqPPrgvGrCk%3D#v2",
* "skillGroupId":0,
* "customerServiceId":2**********4
* }
* ]
* }
*/
/**
* 2. Assemble the call parameters.
*/
String jsonStr = assemble(ccAudioStr);
/**
* Example of the assembled jsonStr. The validTimes, channels, voiceFileUrl, and audioType fields are required. Other fields can be retrieved as needed.
* {
* "callList":[
* {
* "audioType":"ali-mkv",
* "validTimes":[
* {
* "begin_time":0,
* "end_time":67060,
* "speaker_id":"x****i"
* }
* ],
* "channels":[
* {
* "speaker_id":"x****i",
* "channel_key":"ch-user-1********2-8********7-1********6-job-2********8"
* }
* ],
* "voiceFileUrl":"https://ccc-v2-staging.oss-cn-hangzhou.aliyuncs.com/ccc-record-mixed/report-test-2/2022/08/job-2********8.mkv?Expires=1663124613&OSSAccessKeyId=L********q&Signature=bxLnpftFnn4h1GU1FqPPrgvGrCk%3D#v2",
* }
* ]
* }
*/
/**
* 3. Call the Smart Conversation Analysis (SCA) SDK to start a quality check task.
* For detailed documentation, see https://help.aliyun.com/document_detail/139399.html
*/
uploadAudioData(jsonStr);
}
/**
* Gets the audio information to use as input for the UploadAudioData operation.
* You can find the contactId and instanceId for the CCC audio recording in the CCC console.
* @param contactId The contact ID.
* @param instanceId The instance ID.
* @throws Exception
*/
public static String getParamStr(String contactId,String instanceId) throws Exception {
com.aliyun.ccc20200701.Client client = Sample.createCCClient();
com.aliyun.ccc20200701.models.GetUploadAudioDataParamsRequest getUploadAudioDataParamsRequest = new com.aliyun.ccc20200701.models.GetUploadAudioDataParamsRequest();
getUploadAudioDataParamsRequest.setContactId(contactId);
getUploadAudioDataParamsRequest.setInstanceId(instanceId);
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
GetUploadAudioDataParamsResponse uploadAudioDataParamsWithOptions = client.getUploadAudioDataParamsWithOptions(getUploadAudioDataParamsRequest, runtime);
// Add your own logging logic here if needed.
System.out.println(uploadAudioDataParamsWithOptions.getBody().getData().getParamsStr());
return uploadAudioDataParamsWithOptions.getBody().getData().getParamsStr();
} catch (TeaException error) {
// Add your own error logging logic here if needed.
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// Add your own error logging logic here if needed.
com.aliyun.teautil.Common.assertAsString(error.message);
}
return null;
}
/**
* Assembles the jsonStr parameter. This example includes only the required fields.
* @param ccAudioStr
* @return
*/
public static String assemble(String ccAudioStr) {
JSONObject jsonStrObject = new JSONObject();
JSONObject ccStrObject = JSON.parseObject(ccAudioStr);
JSONArray callList = ccStrObject.getJSONArray("callList");
JSONArray jsonStrCallList = new JSONArray();
callList.add(
new JSONObject()
.fluentPut("validTimes",callList.getJSONObject(0).getJSONObject("validTimes"))
.fluentPut("channels",callList.getJSONObject(0).getJSONObject("channels"))
.fluentPut("voiceFileUrl",callList.getJSONObject(0).getString("voiceFileUrl"))
// The audioType parameter must be set to ali-mkv.
.fluentPut("audioType","ali-mkv")
);
jsonStrObject.put("callList",jsonStrCallList);
// You can add other parameters to implement your custom business logic.
System.out.println(jsonStrObject.toJSONString());
return jsonStrObject.toJSONString();
}
public static void uploadAudioData(String ccAudioStr) {
UploadAudioDataRequest req = new UploadAudioDataRequest();
req.setJsonStr(ccAudioStr);
try {
UploadAudioDataResponse response = createSCAClient().getAcsResponse(req);
System.out.println(response.getCode());
System.out.println(response.getMessage());
System.out.println(response.getData());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}