Chatbot ServiceTích hợp GraphQL (Mẫu)
API Gateway
Chi Tiết Phiên Chat (ExampleChatSessionDetail)
QUERY MẪU
Yêu cầu Bearer Token
ExampleChatSessionDetail.gql
Variables
Response 200 OK
exampleFetchChatSessionDetail.ts
🛡️ Lưu Ý Schema Mẫu: Tài liệu này mô tả định dạng truy vấn mẫu (Example Query). Cấu trúc schema và tên trường chính thức sẽ được cấp riêng trong tài liệu hợp tác.
Truy vấn toàn bộ tin nhắn thuộc về một phiên làm việc cụ thể (session_id). Thường dùng khi ứng dụng có màn hình danh sách các phiên tư vấn cũ và người dùng bấm vào xem lại chi tiết một phiên độc lập.
💻 Chi Tiết Truy Vấn & Mã Nguồn Mẫu
GraphQL Query & Payload (Mẫu):
GraphQL Query
query ExampleChatSessionDetail($input: ExampleSessionDetailInput!) {
exampleChatSessionDetail(input: $input) {
session_id
app_channel
conversation_messages {
msg_id
session_id
sender_role
sender_name
content_text
created_timestamp
delivery_status
}
}
}Variables (JSON Mẫu)
{
"input": {
"session_id": "sess_89f1a23b4c5d6e7f",
"cursor_timestamp": null,
"page_size": 50
}
}Phản Hồi Thành Công (JSON Response Mẫu)
{
"data": {
"exampleChatSessionDetail": {
"session_id": "sess_89f1a23b4c5d6e7f",
"app_channel": "WEB_APP",
"conversation_messages": [
{
"msg_id": "msg_ast_01j89a8bc43e",
"session_id": "sess_89f1a23b4c5d6e7f",
"sender_role": "ASSISTANT",
"sender_name": "Pango AI Assistant",
"content_text": "Pango AI hỗ trợ đa dạng các giải pháp tích hợp bao gồm Web Chat Widget và SDK nhúng Mobile App...",
"created_timestamp": 1740200015000,
"delivery_status": "COMPLETED"
}
]
}
}
}TypeScript / Axios:
import axios from 'axios';
export interface ExampleSessionDetailInput {
session_id: string;
cursor_timestamp?: number | null;
page_size?: number;
}
export interface ExampleSessionMessage {
msg_id: string;
session_id: string;
sender_role: 'USER' | 'ASSISTANT' | 'SYSTEM';
sender_name: string;
content_text: string;
created_timestamp: number;
delivery_status: string;
}
/**
* Tải danh sách tin nhắn theo Session ID chỉ định (Mã mẫu)
*/
export async function exampleFetchChatSessionDetail(
apiUrl: string = process.env.VITE_API_URL!,
token: string,
sessionId: string,
cursorTimestamp?: number | null,
pageSize: number = 50
): Promise<ExampleSessionMessage[]> {
const query = `
query ExampleChatSessionDetail($input: ExampleSessionDetailInput!) {
exampleChatSessionDetail(input: $input) {
session_id
app_channel
conversation_messages {
msg_id
session_id
sender_role
sender_name
content_text
created_timestamp
delivery_status
}
}
}
`;
const response = await axios.post(
apiUrl,
{
query,
variables: {
input: {
session_id: sessionId,
cursor_timestamp: cursorTimestamp || null,
page_size: pageSize,
},
},
operationName: 'ExampleChatSessionDetail',
},
{
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`,
'x-org-id': process.env.VITE_ORG_ID || 'org_sample_demo',
'x-client-type': 'app',
'x-external-private-key': process.env.VITE_EXTERNAL_PRIVATE_KEY || 'your_secret_key',
},
}
);
return response.data?.data?.exampleChatSessionDetail?.conversation_messages || [];
}