Pango AI MascotPango Chatbot AI
Chatbot ServiceTích hợp GraphQL (Mẫu)
API Gateway

Đăng Nhập Hệ Thống (ExampleExternalLogin)

MUTATION MẪU Yêu cầu Header Checksum MD5

🛡️ Lưu Ý Schema Mẫu: Tài liệu này mô tả định dạng mutation mẫu (Example Mutation). 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.

Xác thực định danh người dùng từ hệ thống đối tác vào Pango Chatbot AI. Kết quả trả về gồm auth_token (JWT) dùng cho các request tiếp theo và thông tin tài khoản người dùng (user_profile).

Yêu Cầu Header Checksum Mẫu

Khi gọi mutation này, bạn bắt buộc phải đính kèm HTTP Header Checksum theo công thức MD5 mẫu được Pango AI Team cung cấp khi bắt đầu hợp tác.

💻 Chi Tiết Truy Vấn & Mã Nguồn Mẫu

GraphQL Mutation & Payload (Mẫu):

GraphQL Mutation

ExampleExternalLogin.gql
mutation ExampleExternalLogin($input: ExampleAuthLoginInput!) {
  exampleExternalLogin(input: $input) {
    auth_token
    user_profile {
      account_id
      email
      full_name
      phone
      avatar_url
      role_name
      account_status
      last_active_time
    }
  }
}

Variables (JSON Mẫu)

Variables
{
  "input": {
    "user_external_id": "usr_partner_123456",
    "partner_app_code": "PORTAL_APP",
    "user_email": "alex.nguyen@example.com",
    "user_full_name": "Alex Nguyen",
    "user_phone": "0901234567",
    "req_timestamp": 1740200000000
  }
}

Phản Hồi Thành Công (JSON Response Mẫu)

Response 200 OK
{
  "data": {
    "exampleExternalLogin": {
      "auth_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c3JfcGFydG5lcl8xMjM0NTYiLCJyb2xlIjoiVVNFUiIsImlhdCI6MTc0MDIwMDAwMH0.sample_token_signature",
      "user_profile": {
        "account_id": "acc_pango_98a76b5c4d",
        "email": "alex.nguyen@example.com",
        "full_name": "Alex Nguyen",
        "phone": "0901234567",
        "avatar_url": "https://example.com/avatars/user-01.png",
        "role_name": "USER",
        "account_status": "ACTIVE",
        "last_active_time": 1740200000000
      }
    }
  }
}

TypeScript / Axios:

exampleExternalLogin.ts
import axios from 'axios';
import md5 from 'crypto-js/md5';

export interface ExampleAuthLoginInput {
  user_external_id: string;
  partner_app_code: string;
  user_email: string;
  user_full_name: string;
  user_phone?: string;
  req_timestamp?: number;
}

export interface ExampleAuthPayload {
  auth_token: string;
  user_profile: {
    account_id: string;
    email: string;
    full_name: string;
    phone?: string;
    avatar_url?: string;
    role_name: string;
    account_status: string;
    last_active_time?: number;
  };
}

/**
 * Đăng nhập người dùng từ hệ thống đối tác vào Pango Chatbot AI (Mã mẫu)
 */
export async function exampleExternalLogin(
  apiUrl: string = process.env.VITE_API_URL!,
  params: ExampleAuthLoginInput
): Promise<ExampleAuthPayload> {
  const req_timestamp = params.req_timestamp || Date.now();
  const input = { ...params, req_timestamp };

  // 1. Tạo Checksum MD5 mẫu: partner_app_code:req_timestamp:user_external_id
  const checkSumString = `${params.partner_app_code}:${req_timestamp}:${params.user_external_id}`;
  const checksum = md5(checkSumString).toString().toLowerCase();

  const query = `
    mutation ExampleExternalLogin($input: ExampleAuthLoginInput!) {
      exampleExternalLogin(input: $input) {
        auth_token
        user_profile {
          account_id
          email
          full_name
          phone
          avatar_url
          role_name
          account_status
          last_active_time
        }
      }
    }
  `;

  const response = await axios.post(
    apiUrl,
    {
      query,
      variables: { input },
      operationName: 'ExampleExternalLogin',
    },
    {
      headers: {
        'Content-Type': 'application/json',
        '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',
        'Checksum': checksum,
      },
    }
  );

  const data = response.data?.data?.exampleExternalLogin;
  if (!data?.auth_token) {
    throw new Error('Đăng nhập thất bại: Không tìm thấy auth_token trong phản hồi.');
  }

  // Lưu auth_token vào LocalStorage / SecureStorage
  localStorage.setItem('access_token', data.auth_token);
  localStorage.setItem('user_info', JSON.stringify(params));

  return data;
}

📑 Bảng Tham Số Mẫu (Example Schema Definition)

ExampleAuthLoginInput

Thuộc Tính MẫuKiểu Dữ LiệuBắt BuộcMô Tả
user_external_idString!CóID duy nhất của người dùng phía đối tác (ví dụ: "usr_partner_123456")
partner_app_codeString!CóMã định danh ứng dụng/kênh đối tác (ví dụ: "PORTAL_APP", "MOBILE_APP")
user_emailString!CóĐịa chỉ Email của người dùng
user_full_nameString!CóTên đầy đủ hiển thị của người dùng
user_phoneStringKhôngSố điện thoại người dùng
req_timestampLong!CóTimestamp mili-giây tại thời điểm tạo request (Date.now())

Dữ Liệu Trả Về (ExampleAuthPayload)

Thuộc Tính MẫuKiểu Dữ LiệuMô Tả
auth_tokenString!Chuỗi JWT Token dùng để xác thực các request sau này
user_profile.account_idString!ID định danh tài khoản trên hệ thống Pango
user_profile.full_nameStringTên hiển thị người dùng
user_profile.emailStringĐịa chỉ email người dùng
user_profile.role_nameString!Vai trò người dùng (ví dụ: "USER")
user_profile.account_statusString!Trạng thái tài khoản ("ACTIVE", "LOCKED")
Pango AI Mascot© 2026 Pango Chatbot AI • Phát triển bởi Pango AI Team
v1.0 Enterprise