ตรวจจับการใช้ข้อความที่ไม่เหมาะสม
API การตรวจจับการละเมิดข้อความเป็น API ที่ตรวจจับและตรวจสอบการละเมิด (คำต้องห้าม, โฆษณาสแปม) ในข้อความ
การเตรียมการ¶
ตรวจสอบว่าคุณมีสิทธิ์เข้าถึงเมนู Hive Console > AI Services > Abuse Detection > Chat Abusing Detection หรือไม่ และถ้าไม่มี ให้ดูที่ Hive Console Permission Administration Guide เพื่อขอสิทธิ์เข้าถึงเมนู ลงทะเบียนโครงการใหม่ใน Chat Abusing Detection.
การกำหนดว่าข้อความเป็นการใช้คำพูดที่ไม่เหมาะสมหรือไม่¶
หลังจากส่งข้อความแล้ว จะทำการตรวจสอบว่าข้อความนั้นเป็นโฆษณาสแปมหรือมีคำต้องห้ามหรือไม่ จากนั้นจึงส่งผลลัพธ์กลับ
URL การร้องขอ¶
| URL สด | https://tads.withhive.com/cads2/send-text-data | 
|---|---|
| URL Sandbox | https://sandbox-tads.withhive.com/cads2/send-text-data | 
| วิธีการ HTTP | POST | 
| ประเภทเนื้อหา | application/json | 
เนื้อหาของคำขอ¶
| ชื่อฟิลด์ | คำอธิบาย | ประเภท | จำเป็น | 
|---|---|---|---|
| project_key | คีย์โปรเจกต์ | สตริง | ใช่ | 
| text_log | ข้อมูลข้อความ | อ็อบเจ็กต์ | ใช่ | 
text_log¶
| ชื่อฟิลด์ | คำอธิบาย | ประเภท | จำเป็น | 
|---|---|---|---|
| text_array | อาร์เรย์ของวัตถุที่ประกอบด้วยข้อความและเวลาที่ส่งข้อความ | อาร์เรย์(วัตถุ) | ใช่ | 
| text_count | จำนวนวัตถุใน text_array | จำนวนเต็ม | ใช่ | 
วัตถุใน text_array¶
| ชื่อฟิลด์ | คำอธิบาย | ประเภท | จำเป็น | 
|---|---|---|---|
| time_stamp | เวลาที่ข้อความถูกส่ง (รูปแบบเวลาที่อิงตาม UTC ในรูปแบบ ISO, ตัวอย่าง: 2024-01-30T10:35:49.95457+09:00) | สตริง | ใช่ | 
| text_info | สตริงที่เข้ารหัสด้วย AES256 โดยใช้กุญแจการเข้ารหัสที่ได้รับจาก Hive Console จาก วัตถุ JSON. ขนาดสูงสุดคือ 5KB. สำหรับรายละเอียดเพิ่มเติมเกี่ยวกับวิธีการเข้ารหัส โปรดดูที่ ตัวอย่างโค้ด. | สตริง | ใช่ | 
text_info JSON Object¶
 สร้างวัตถุ JSON ตามรูปแบบด้านล่าง จากนั้นเข้ารหัสด้วย AES256 เพื่อสร้างสตริง text_info
| ชื่อฟิลด์ | คำอธิบาย | ประเภท | จำเป็น | 
|---|---|---|---|
| user_id | หมายเลข ID ที่ไม่ซ้ำกันของผู้ใช้ | สตริง | ใช่ | 
| lang_code | รหัสภาษา (ISO 639-1) * เกาหลี: ko * อังกฤษ: en * ญี่ปุ่น: ja * จีนแบบย่อ: zh-hans * จีนแบบดั้งเดิม: zh-hant * สเปน: es * รัสเซีย: ru * เยอรมัน: de * ฝรั่งเศส: fr * โปรตุเกส: pt * อิตาลี: it * ไทย: th * อินโดนีเซีย: id * ตุรกี: tr * มาเลเซีย: ms * เวียดนาม: vi | สตริง | ใช่ | 
| text | ข้อความเพื่อตรวจสอบการใช้ที่ไม่เหมาะสม | สตริง | ใช่ | 
| text_type | หากข้อความเป็นข้อความแชท จะตกอยู่ในหนึ่งใน 3 รูปแบบแชทด้านล่าง * "chat_party": แชทกลุ่ม * "chat_guild": แชทกิลด์ * "chat_whisper": กระซิบ | สตริง | ไม่ | 
| room_num | หากข้อความเป็นข้อความแชท นี่คือหมายเลขห้องแชท | สตริง | ไม่ | 
| channel_info | หากข้อความเป็นข้อความแชท นี่คือข้อมูลช่องแชท | สตริง | ไม่ | 
การตอบสนอง¶
| ชื่อฟิลด์ | คำอธิบาย | ประเภท | 
|---|---|---|
| result_code | รหัสการตอบกลับ | สตริง | 
| result_text | คำอธิบายของรหัสการตอบกลับ | สตริง | 
| result_array | อาร์เรย์ที่มีผลลัพธ์การตรวจจับ | อาร์เรย์(วัตถุ) | 
result_array¶
| ชื่อฟิลด์ | คำอธิบาย | ประเภท | 
|---|---|---|
| tads_result | ผลการตรวจจับ | วัตถุ | 
| text_result | ผลของการใช้การปิดบังกับข้อความต้นฉบับตามข้อความต้นฉบับและผลการตรวจจับ | วัตถุ | 
tads_result¶
| ชื่อฟิลด์ | คำอธิบาย | ประเภท | 
|---|---|---|
| forbidden_yn | ว่าพบคำต้องห้ามหรือไม่ ( 0: ไม่พบคำต้องห้ามในข้อความ,1: พบคำต้องห้ามในข้อความ) | สตริง | 
| spam_yn | ว่าข้อความถูกตรวจพบว่าเป็นสแปมหรือไม่ ( 0: ไม่ถูกตรวจพบว่าเป็นสแปม,1: ถูกตรวจพบว่าเป็นสแปม) | สตริง | 
| aug_yn | ว่าข้อความถูกประมวลผลเป็นชุดหรือไม่ ( 0: ไม่ได้ประมวลผลเป็นชุด,1: ประมวลผลเป็นชุด) | สตริง | 
| long_yn | ว่าข้อความเป็นสตริงยาวหรือไม่ ซึ่งหมายความว่าถ้าหากมันมีมากกว่า 5,000 ตัวอักษร อัลกอริธึมการตรวจจับไม่สามารถทำงานบนข้อความได้ ( 0: น้อยกว่า 5,000 ตัวอักษร,1: มากกว่า 5,000 ตัวอักษร) | สตริง | 
ผลลัพธ์ข้อความ¶
| ชื่อฟิลด์ | คำอธิบาย | ประเภท | 
|---|---|---|
| text | ข้อความที่ต้องตรวจสอบการใช้ในทางที่ผิด | สตริง | 
| masking_text | ข้อความที่มีการปกปิด ( textจะเหมือนกันหากไม่มีการตั้งค่าการปกปิดใน Hive Console หรือหากค่าtads_result.forbidden_ynเป็น0) | สตริง | 
รหัสการตอบกลับ¶
| รหัส | ข้อความ | หมายเหตุ | 
|---|---|---|
| 200 | "สำเร็จ" | สำเร็จ | 
| 500 | "คำขอไม่ถูกต้อง" | มีข้อผิดพลาดในคำขอ กรุณาตรวจสอบว่า URL ของคำขอและเนื้อหาของคำขอถูกต้องหรือไม่ | 
| 501 | "จำนวนข้อมูลไม่ถูกต้อง" | จำนวนของข้อความที่ส่งไม่ตรงกัน ค่าของ text_count และความยาวของ text_array ต้องตรงกัน | 
| 502 | "คีย์ลับไม่ถูกต้อง" | ค่าคีย์ลับไม่ถูกต้อง กรุณาตรวจสอบคีย์ลับของโปรเจกต์ใน การจัดการโปรเจกต์ | 
| 503 | "ProjectKey ที่ไม่ได้ลงทะเบียน" | ค่าคีย์โปรเจกต์ไม่ถูกต้อง กรุณาตรวจสอบคีย์โปรเจกต์ของโปรเจกต์ใน การจัดการโปรเจกต์ | 
| 506 | "ข้อผิดพลาดของระบบ" | นี่คือข้อผิดพลาดภายใน เช่น ข้อผิดพลาดของเครือข่าย กรุณาเรียก API อีกครั้งหลังจากผ่านไปสักครู่ | 
| 507 | "ขนาดของข้อความใหญ่เกินไป" | ขนาดของข้อความใหญ่เกินไป ขนาดสูงสุดของ text_array คือ 5KB กรุณาลดขนาดของข้อความ | 
ตัวอย่างคำขอ¶
import json
import base64
import requests
from datetime import datetime
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
def encrypt(text, user_id, lang_code, secret_key, channel_info=None, room_num=None, text_type=None) -> str: ## รหัสสำหรับการเข้ารหัส 
    aes = AES.new(secret_key, AES.MODE_ECB)
    jsonData =  {"text_type": text_type, ## ใช้เฉพาะเมื่อจำเป็น
                "room_num" : room_num, ## ใช้เฉพาะเมื่อจำเป็น
                "user_id": user_id,
                "channel_info" : channel_info, ## ใช้เฉพาะเมื่อจำเป็น
                "lang_code": lang_code,
                "text": text}
    rawJsonStr = json.dumps(jsonData)
    paddedStr = pad(rawJsonStr.encode("utf-8"),AES.block_size)
    encrypted_data = aes.encrypt(paddedStr)
    encrypted_data_b64 = base64.b64encode(encrypted_data).decode("utf-8")
    return encrypted_data_b64
project_key = <PROJECT_KEY>
secret_key = <SECRET_KEY>
now = datetime.now().astimezone().isoformat()
lang_code = "ko"
user_id = "432414"
channel_info = "4342314" ## ใช้เฉพาะเมื่อจำเป็น
room_num = "12312" ## ใช้เฉพาะเมื่อจำเป็น
text_type = "chat_whisper" ## ใช้เฉพาะเมื่อจำเป็น
url = "https://tads.withhive.com/cads2/send-text-data"
payload =  {"project_key": project_key,
                      "text_log": {
                              "text_count": 2, ## ควรตรงกับจำนวนของ elements ของ text_array
                              "text_array": [
                                            {"time_stamp": now,
                                            "text_info": encrypt(text=str("test1"), 
                                                            user_id=user_id,
                                                            channel_info=channel_info, ## ใช้เฉพาะเมื่อจำเป็น
                                                            room_num=room_num, ## ใช้เฉพาะเมื่อจำเป็น
                                                            text_type=text_type, ## ใช้เฉพาะเมื่อจำเป็น
                                                            lang_code=lang_code,
                                                            secret_key=secret_key)},
                                            {"time_stamp": now,
                                            "text_info": encrypt(text=str("test2"), 
                                                            user_id=user_id,
                                                            channel_info=channel_info, ## ใช้เฉพาะเมื่อจำเป็น
                                                            room_num=room_num, ## ใช้เฉพาะเมื่อจำเป็น
                                                            text_type=text_type, ## ใช้เฉพาะเมื่อจำเป็น
                                                            lang_code=lang_code,
                                                            secret_key=secret_key)}]},}
res = requests.post(url, data=json.dumps(payload), headers={"Content-Type": "application/json"})
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;
import org.jooq.tools.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.log;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
@Slf4j
public class TadsComponent {
@Autowired
RestTemplate restTemplate;
@Autowired
ObjectMapper objectMapper;
public void sendHttp() throws Exception{
    String projectKey =  <PROJECT_KEY>; // provide the project key
    String secretKey =  <SECRET_KEY>;  // provide the project secret key
    String url = "https://tads.withhive.com/cads2/send-text-data";
    String user_id = "432414";
    String channel_info = "4342314"; // ใช้เฉพาะเมื่อจำเป็น
    String room_num = "12312"; // ใช้เฉพาะเมื่อจำเป็น
    String text_type = "chat_whisper"; // ใช้เฉพาะเมื่อจำเป็น
    String lang_code = "ko";
    String text_1 = "test1";
    String text_2 = "test2";
    DateTimeFormatter formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
    ZonedDateTime now = ZonedDateTime.now();
    Map<String, Object> payload = new HashMap<>();
    payload.put("project_key", projectKey);
    Map<String, Object> textLog = new HashMap<>();
    textLog.put("text_count", 2); // ควรตรงกับจำนวนของ elements ของ text_array
    Map<String, Object> textArray1 = new HashMap<>();
    textArray1.put("time_stamp", now.format(formatter));
    textArray1.put("text_info", encrypt(text_1, user_id, channel_info, room_num, text_type, lang_code, secretKey));
Map<String, Object> textArray2 = new HashMap<>();
   textArray2.put("time_stamp", now.format(formatter));
   textArray2.put("text_info", encrypt(text_2, user_id, channel_info, room_num, text_type, lang_code, secretKey));
    Object[] textArrayObj = {textArray1, textArray2};
    textLog.put("text_array", textArrayObj);
    payload.put("text_log", textLog);
    JsonNode callBodyNode = objectMapper.valueToTree(payload);
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json");
    HttpEntity<String> entity = new HttpEntity<>(callBodyNode.toString(), headers);
    ResponseEntity<String> responseEntity =  restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
    int responseStatusCode =  responseEntity.getStatusCodeValue();
    String responseBodyString = responseEntity.getBody();
    JsonNode responseBodyNode = objectMapper.readTree(responseBodyString);
    return;
}
public static String encrypt(String text, String UserId, String channelInfo, String roomNum, String textType, String langCode, String secretKey) {
    try {
        Cipher aes = Cipher.getInstance("AES/ECB/PKCS5Padding");
        SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(), "AES");
        aes.init(Cipher.ENCRYPT_MODE, secretKeySpec);
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("room_num", roomNum); // ใช้เฉพาะเมื่อจำเป็น
        map.put("channel_info", channelInfo); // ใช้เฉพาะเมื่อจำเป็น
        map.put("lang_code", langCode);
        map.put("text", text);
        map.put("text_type", textType); // ใช้เฉพาะเมื่อจำเป็น
        map.put("user_id", UserId);
        String encrypt_str = JSONObject.toJSONString(map);
        byte[] paddedData = padString(encrypt_str).getBytes();
        byte[] encryptedData = aes.doFinal(paddedData);
        return Base64.getEncoder().encodeToString(encryptedData);
    } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException e) {
        e.printStackTrace();
        return null;
    }
}
private static String padString(String source) {
    char paddingChar = ' ';
    int size = 16;
    int x = source.length() % size;
    int padLength = size - x;
    StringBuilder paddedString = new StringBuilder(source);
    for (int i = 0; i < padLength; i++) {
        paddedString.append(paddingChar);
    }
    return paddedString.toString();
}} // รหัสสำหรับการเข้ารหัส
ตัวอย่างการตอบกลับ¶
{
    "result": {
        "result_array": '[
                        {"tads_result":{
                            "forbidden_yn":"0",
                            "spam_yn":"0",
                            "aug_yn":"0",
                            "long_yn":"0"},
                        "text_result":{
                            "text":"test1",
                            "masking_text":"test1"
                        }},
                        {"tads_result":{
                            "forbidden_yn":"0",
                            "spam_yn":"0",
                            "aug_yn":"0",
                            "long_yn":"0"},
                        "text_result":{
                            "text":"test2",
                            "masking_text":"test2"
                        }}
                            ]',
        "result_code": "200",
        "result_text": "success"
    }
}