Telemarketing conversation threat detection

Updated at:

The telemarketing conversation threat detection service analyzes outbound sales calls to detect threats such as abuse, complaints, and intimidation. You can use this service for voice quality inspection.

Note

This service is provided by the NLP Self-learning Platform. You can use this service by calling the API directly.

Service activation and resource plan purchase

Before you start, confirm that the service is activated. After you activate the service, you must purchase a resource plan.

Service invocation and debugging

For more information about model invocation, see Model Invocation.

For more information about software development kit (SDK) examples, see SDK Examples.

Debugging

You can run this API operation in OpenAPI Explorer. This eliminates the need to calculate a signature. After a successful call, OpenAPI Explorer automatically generates SDK example code.

Configure access credentials (AccessKey ID and AccessKey secret) using environment variables

  1. Note:

    1. An AccessKey for an Alibaba Cloud account provides full access permissions to all APIs. This practice poses a high security risk. We recommend that you create and use a Resource Access Management (RAM) user for API calls or routine O&M. To create a RAM user, log on to the RAM console.

    2. Do not hard-code your AccessKey ID and AccessKey secret in your code because this can lead to security risks. Instead, store and access your keys using environment variables.

  2. Configuration for Linux and macOS

    export NLP_AK_ENV=<access_key_id>
    export NLP_SK_ENV=<access_key_secret>

    Replace <access_key_id> with your AccessKey ID and <access_key_secret> with your AccessKey secret. For more information about how to obtain an AccessKey ID and an AccessKey secret, see Step 2: Obtain an AccessKey for an account.

  3. Configuration for Windows

    1. Create the NLP_AK_ENV and NLP_SK_ENV environment variables. Set their values to your AccessKey ID and AccessKey secret, respectively.

    2. Restart your Windows system.

Java code example

/**

* An AccessKey for an Alibaba Cloud account provides full access permissions to all APIs. This practice poses a high security risk. We recommend that you create and use a Resource Access Management (RAM) user for API calls or routine O&M. 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 if required.

* Do not hard-code your AccessKey ID and AccessKey secret in your code because this can lead to security risks.

 *//**

* An AccessKey for an Alibaba Cloud account provides full access permissions to all APIs. This practice poses a high security risk. We recommend that you create and use a Resource Access Management (RAM) user for API calls or routine O&M. 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 if required.

* Do not hard-code your AccessKey ID and AccessKey secret in your code. Doing so creates a security risk.

 */class MsgDO{
            private String role;
            private String words;
            public MsgDO(String role,String words) {
                this.role = role;
                this.words = words;
            }
            public String getRole() {
                return role;
            }
            public void setRole(String role) {
                this.role = role;
            }
            public String getWords() {
                return words;
            }
            public void setWords(String words) {
                this.words = words;
            }
        }
/**
 * An AccessKey for an Alibaba Cloud account has full access permissions to all APIs. This poses a high security risk. Create and use a Resource Access Management (RAM) user for API calls or routine O&M. Log on to the RAM console to create a RAM user.
 * This example shows how to store the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
 * Do not hard-code your AccessKey ID and AccessKey secret in your code. This can lead to security risks.
 */
String accessKeyId = System.getenv("NLP_AK_ENV");
String accessKeySecret = System.getenv("NLP_SK_ENV");
DefaultProfile defaultProfile = DefaultProfile.getProfile("cn-hangzhou",accessKeyId,accessKeySecret);
IAcsClient client = new DefaultAcsClient(defaultProfile);
Map<String, Object> obj = new HashMap<String, Object>();
List<MsgDO> msgs = new ArrayList<MsgDO>();
msgs.add(new MsgDO("Customer Service","Mr. Li."));
msgs.add(new MsgDO("Customer Service","Are you ***?"));
obj.put("msgs",msgs);
obj.put("session_id",123);
RunPreTrainServiceRequest request = new RunPreTrainServiceRequest();
request.setServiceName("This service is not directly available. To obtain access, join the Alibaba Cloud NLP Self-learning Platform user group on DingTalk at 23142693.");
request.setPredictContent(JSON.toJSONString(obj));
RunPreTrainServiceResponse response = client.getAcsResponse(request);
System.out.println(response.getPredictResult());

Python code example

# Install dependencies
pip install aliyun-python-sdk-core
pip install aliyun-python-sdk-nlp-automl
# -*- coding: utf8 -*-
import json
import os

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdknlp_automl.request.v20191111 import RunPreTrainServiceRequest

/**
 * An AccessKey for an Alibaba Cloud account has full access permissions to all APIs. This poses a high security risk. Create and use a Resource Access Management (RAM) user for API calls or routine O&M. Log on to the RAM console to create a RAM user.
 * This example shows how to store the AccessKey ID and AccessKey secret in environment variables. You can also store them in a configuration file as needed.
 * Do not hard-code your AccessKey ID and AccessKey secret in your code. This can lead to security risks.
 */
access_key_id = os.environ['NLP_AK_ENV']
access_key_secret = os.environ['NLP_SK_ENV']

# Initialize AcsClient instance
client = AcsClient(
  access_key_id,
  access_key_secret,
  "cn-hangzhou"
);
content = {
    "session_id": 123,
    "msgs":[
    {
      "role": "Customer Service",
      "words": "Mr. Li."
    },
    {
      "role": "Customer Service",
      "words": "Are you ***?"
    }
  ]
}
# Initialize a request and set parameters
request = RunPreTrainServiceRequest.RunPreTrainServiceRequest()
request.set_ServiceName("This service is not directly available. To obtain access, join the Alibaba Cloud NLP Self-learning Platform user group on DingTalk at 23142693.")
request.set_PredictContent(json.dumps(content))
# Print response
response = client.do_action_with_exception(request)
resp_obj = json.loads(response)
predict_result = json.loads(resp_obj['PredictResult'])
print(predict_result)

PredictContent example

{
  "session_id": 123,
  "msgs": [
    {
      "role": "Customer Service",
      "words": "Mr. Li."
    },
    {
      "role": "Customer Service",
      "words": "Are you ***?"
    }
  ]
}

PredictResult example

{
  "session_id": "9e961ffb96ce9b411bc06ef8b69b30da7014oe",
  "cost": "402.725ms",
  "result": [
    {
      "risks": [
        {
          "label": "No Threat",
          "prob": 0.071
        },
        {
          "label": "Customer Service Abuse",
          "prob": 0.941
        },
        {
          "label": "Complaint",
          "prob": 0.0
        },
        {
          "label": "Customer Abuse",
          "prob": 0.001
        },
        {
          "label": "Customer Threat",
          "prob": 0.0
        },
        {
          "label": "Pornography",
          "prob": 0.0
        },
        {
          "label": "Customer Service Threat",
          "prob": 0.0
        },
        {
          "label": "Prohibited Content",
          "prob": 0.0
        },
        {
          "label": "Gambling",
          "prob": 0.0
        },
        {
          "label": "Political Content",
          "prob": 0.0
        },
        {
          'label': 'Suspected Fraud', 
          'prob': 0.0
         }

      ]
    }
  ],
  "code": "SUCCESS"
}

Request parameters

Parameter

Description

session_id

A unique string that identifies the request. Include this parameter for troubleshooting. You can use an MD5 hash, or a random number with a timestamp. This parameter is required.

msgs

The conversation content. This parameter is required.

role

The role of the speaker. Valid values are Customer Service and Customer.

words

The content spoken by the speaker.

Response parameters

Parameter

Description

session_id

The unique identifier.

result

The threat classification result for the conversation. The result is a list of (label, prob) tuples. Each tuple contains a threat label and a probability score. Supported threat types include No Threat, Customer Service Abuse, Complaint, Customer Service Threat, Customer Abuse, Customer Threat, Pornography, Prohibited Content, Political Content, Gambling, and Suspected Fraud.

code

The query status. `SUCCESS` indicates a successful query. `INVALID_INPUT_FORMAT` indicates an invalid input format. `FIELD_MISSING` indicates that a required field is missing. `INVALID_TEXT_VALUE` indicates that the `msgs` field has no valid value.

cost

The time taken for the query.