Send chat log
Chat log collection system (CLCS)¶
send-chat-log¶
This API sends chat logs to Chat log collection system.
- Request URL
Commercial Server URL | https://clcs.qpyou.cn/chat/api/v1/send-chat-log |
---|---|
Sandbox Server URL | https://sandbox-clcs.qpyou.cn/chat/api/v1/send-chat-log |
HTTP Method | POST |
Content-Type | application/json |
- Request Body
Field Name | Type | Required | Description |
---|---|---|---|
game_key | String | Y | The key value (16 characters) created from the company id and the game id. You can get this key on AI Service > Chat Abusing Detection > Game Management > Confirm Encryption Key in the Hive Console. The company id and game id can also be obtained in the Hive Console AI service > Chat Abusing Detection > Game Management. Example) abcdefghijklmnop |
chat_log | object | Y | the array or the collection of encrypted messages and the chat_count. |
- chat_log object
Field Name | Type | Required | Description |
---|---|---|---|
chat_count | int | Y | The number of msg in the msg_array. Ex) 32 (The chat_count and the size of msg_array containing encrypted msgs must be the same.) |
msg_array | array | Y | 1 or more msg objects |
- msg object;
Field Name | Type | Required | Description |
---|---|---|---|
time_stamp | string | Y | Convert the time of occurrence of a chat message in ISO8601 format and transmit it. If you change the chat message timestamp with the ISO8601 format, ±hh:mm will be added at the tail of the timestamp according to the time zone to which the user who sent the message belongs. The examples of the time_stamp values according to the sender’s time zone and the chat message timestamp * When the time zone is UTC, and the chat message timestamp is 2023-03-30 17:13:00. * Use 2023-03-30T17:13:00+00:00 or 2023-03-30T17:13:00Z * +00:00 can also be written as Z (YYYY-MM-DDTHHss{.mmm}±hh:mm or YYYY-MM-DDTHHss{.mmm}Z) * When the time zone is KST (Korea Standard Time), and the chat message timestamp is 2023-03-30 17:13:00. * Use 2023-03-30T17:13:00+09:00 * When the time zone is CST (Central Standard Time), and the chat message timestamp is 2023-03-30 17:13:00. Use 2023-03-30T17:13:00-05:00 |
msg | string | Y | the JSON string encrypted with the encryption key issued from the Hive Console’s AI Service > Chat Abusing Detection > Game Management > Confirm Encryption Key (maximum size 2KB, AES256 encryption) |
- msg
Field Name | Type | Required | Description |
---|---|---|---|
time_stamp | string | Y | Convert the time of occurrence of a chat message in ISO8601 format and transmit it. If you change the chat message timestamp with the ISO8601 format, ±hh:mm will be added at the tail of the timestamp according to the time zone to which the user who sent the message belongs. The examples of the time_stamp values according to the sender’s time zone and the chat message timestamp * When the time zone is UTC, and the chat message timestamp is 2023-03-30 17:13:00. * Use 2023-03-30T17:13:00+00:00 or 2023-03-30T17:13:00Z * +00:00 can also be written as Z (YYYY-MM-DDTHHss{.mmm}±hh:mm or YYYY-MM-DDTHHss{.mmm}Z) * When the time zone is KST (Korea Standard Time), and the chat message timestamp is 2023-03-30 17:13:00. * Use 2023-03-30T17:13:00+09:00 * When the time zone is CST (Central Standard Time), and the chat message timestamp is 2023-03-30 17:13:00. * Use 2023-03-30T17:13:00-05:00 |
room_num | int | Y | the chat room number Example) 123342 |
lang_code | int | Y | the language code Korean (ko) : 1, English (en): 2, Japanese (ja): 3, Simplified Chinese: 4, Traditional Chinese: 5, España(es): 6, Russia (ru): 7, German (de): 8, French (fr): 9, Portuguese (pt): 10, Italian (it): 11, Thai (th): 12, Indonesian (id): 13, Turkish (tr): 14, Malaysian (ms): 15, Vietnamese (vi): 16 |
chat_msg | string | Y | the chatting contents eg) Hello! The weather is good today. |
chat_mode | int | Y | The chat types Example) 100: general chat 200: group (1:1~N) chatting 300: whisper 4NN: the custom chat type defined by the game studio |
channel_user_id | int | Y | the user’s ID (playerId) in the game |
- Response
Field Name | Type | Description |
---|---|---|
result | object | the container for the output result |
result_code | string | Result Code |
result_msg | string | the result message |
- Result Code
result_code | result_msg | Description |
---|---|---|
200 | Success | The log transfer was successfully finished. |
500 | Incorrect request | There is an error in your request. Please check the request URL and the required request variables are correct. |
501 | The number of messages does not match | The number of messages and the chat_count do not match. The chat_count and the length of msg_array must match. |
502 | Incorrect secret key | Invalid secret key value. Please go to the Hive Console’s AI Service > Chat Abusing Detection > Game Management > Confirm Encryption Key and check the encryption key value. |
503 | Unregistered game key | Invalid game key value. Please go to the Hive Console’s AI Service > Chat Abusing Detection > Game Management > Confirm Encryption Key and check the game key value. |
506 | System error | This error occurs when the chat log collection system is down for maintenance. |
507 | The size of the message is too large | The size of the message is too large. The maximum size of msg_array is 2KB. |
-
Examples
- Python
import requests import json from Crypto.Cipher import AES from Crypto.Util.Padding import pad import base64 game_key = <GAME_KEY> secret_key = <SECRET_KEY> aes = AES.new(secret_key, AES.MODE_ECB) url = "https://clcs.qpyou.cn/chat/api/v1/send-chat-log" ## message encryption def encrypt_msg(room_num:int,lang_code:int,chat_msg:str,chat_mode:int,channel_user_id:int) -> str: json_data = { "time_stamp":"2023-02-20T10:22:10+09:00", ## datetime.now().isoformat() "room_num":room_num, "lang_code":lang_code, "chat_msg":chat_msg, "chat_mode":chat_mode, "channel_user_id":channel_user_id } json_str = json.dumps(json_data) padded_str = pad(json_str.encode("utf-8"),AES.block_size) encrypted_data = aes.encrypt(padded_str) encrypted_data_b64 = base64.b64encode(encrypted_data).decode("utf-8") return encrypted_data_b64 ## Define json payload json_payload = { "game_key": game_key, "chat_log":{ "chat_count": N, ## the size of msg_array "msg_array":[ { "time_stamp":"2023-02-20T10:22:10+09:00", "msg":encrypt_msg(room_num,lang_code,.......) }, { "time_stamp":"2023-02-20T10:22:10+09:00", "msg":encrypt_msg(room_num,lang_code,.......) }, ... ] } } def call_curl_post(url, json_payload): headers = {'Content-type': 'application/json'} response = requests.post(url, data=json.dumps(json_payload), headers=headers) ## function call call_curl_post(url=url, json_payload)
- Java
import java.util.Collections; import java.util.HashMap; import java.util.Map; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import org.apache.tomcat.util.codec.binary.Base64; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import net.minidev.json.JSONObject; public class SampleCode { private String gameKey = <GAME_KEY>; private String secretKey = <SECRET_KEY>; private String url = "https://clcs.qpyou.cn/chat/api/v1/send-chat-log" public void callCurlPost() { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON_UTF8)); headers.setContentType(MediaType.APPLICATION_JSON); Map<String, Object> parameters = new HashMap<>(); parameters.put("game_key", gameKey); parameters.put("chat_log", "{"chat_count" : N //msg_array list size,"msg_array":[{"time_stamp":"2023-02-20T10:22:10+09 :00", "msg":encrypt_msg(,,....)},{"time_stamp":"2023-02-20T10:22:10+09:00", "msg ":encrypt_msg(,,....)}, ...]}"); JSONObject jsonParam = getJsonStringFromMap(parameters); HttpEntity<JSONObject> requestEntity = new HttpEntity<>(jsonParam, headers); ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class); System.out.println("Response status code: " + response.getStatusCode()); System.out.println("Response body: " + response.getBody()); } // message encryption private String encrypt_msg(int room_num, int lang_code, String chat_msg, int chat_mode, int charnnel_user_id) throws Exception { Map<String,Object> map = new HashMap<String,Object>(); map.put("time_stamp", "2023-02-20T10:22:10+09:00"); //## "%Y-%m-%d %H:%M:%S", map.put("room_num", room_num); map.put("lang_code", lang_code); map.put("chat_msg", chat_msg); map.put("chat_mode", chat_mode); map.put("charnnel_user_id", charnnel_user_id); JSONObject encrypt_json = new JSONObject(map); String encrypt_str = encrypt_json.toJSONString(); return encrypt(encrypt_str, secret_key); } // encryption private String encrypt(String plainText, String key) throws Exception { byte[] keyBytes = key.getBytes("UTF-8"); SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, keySpec); byte[] encryptedBytes = cipher.doFinal(plainText.getBytes("UTF-8")); return Base64.encodeBase64String(encryptedBytes); } private static JSONObject getJsonStringFromMap( Map<String, Object> map) { JSONObject jsonObject = new JSONObject(); for( Map.Entry<String, Object> entry : map.entrySet() ) { String key = entry. getKey(); Object value = entry. getValue(); jsonObject. put(key, value); } return jsonObject; } }
- Curl
//TEST CALL curl -d '{"game_key": company key,"chat_log":{"chat_count" : 1,"msg_array":[{"2023-02-20T10:22:10+09:00", "msg":"Encrypted text"}]}}' -H "Content-Type: application/json" -X POST https://test-clcs.qpyou.cn/chat/api/v1/send-chat-log //HEADER POST https://clcs-qpyou.cn/v1/chat/send-chat-log Host: clcs-qpyou.cn User-Agent: curl/7.43.0 Accept: */* Content-Type: application/json //BODY { "game_key":"abcdefghijklmnop", "chat_log":{ "chat_count" : 2, "msg_array":[ { "time_stamp":"2023-02-20T10:22:10+09:00", "msg":"yBDyG1rCthbkXCSpSgGM+ZfHs/B3bZtnxq7f6BOPX2c1Bk8xRAwF6HbkDeN/9prpqeD......" }, { "time_stamp":"2023-02-20T10:22:10+09:00", "msg":"yBDyG1rCthbkXCSpSgGM+ZfHs/B3bZtnxq7f6BOPX2c1Bk8xRAwF6HbkDeN....." } ] } }
- result