Zalo User Login

Generate QR Code for Zalo login

Generate QR + Wait for Login

AI-generated

Overview

This node facilitates user login to the Zalo platform by generating a QR code that can be scanned with the Zalo mobile app. It supports three main operations:

  • Generate QR Code: Immediately generates a QR code for login.
  • Check Login Status: Checks if the user has successfully logged in after scanning the QR code.
  • Generate QR + Wait for Login: Generates a QR code and waits (polls) until the user logs in or a timeout occurs.

This node is useful when you want to authenticate a Zalo user session interactively via QR code scanning, enabling subsequent API calls authenticated as that user. For example, it can be used in workflows that require user authentication without manual credential entry, such as automating messaging or data retrieval from Zalo accounts.

Properties

Name Meaning
Operation Choose the mode of operation:
- Generate QR Code
- Check Login Status
- Generate QR + Wait for Login
QR Code Timeout (seconds) Timeout duration (in seconds) for QR code scanning before expiration. Applies to "Generate QR Code" and "Generate QR + Wait for Login" operations. Default is 60 seconds.
Debug Mode Enable debug information in the output. Available only for the "Check Login Status" operation.

Output

The node outputs JSON data and, when applicable, binary data containing the QR code image.

  • For Generate QR Code and Generate QR + Wait for Login:

    • json includes:
      • success: Boolean indicating if the operation succeeded.
      • message: Informational message about the operation status.
      • operation: The operation performed.
      • qrTimeout: The timeout value used.
      • timestamp: ISO timestamp of the operation.
      • status: Status string such as "qr_ready" or "waiting_for_scan".
      • nextSteps: Instructions on how to proceed after QR generation.
      • For "Generate QR + Wait for Login", once login succeeds, the output contains a cookie string and instructions for creating credentials.
    • binary.qrCode: Contains the QR code image data in PNG format with fields:
      • data: Base64-encoded PNG image data.
      • mimeType: "image/png".
      • fileName: "zalo_qr_code.png".
      • fileExtension: "png".
  • For Check Login Status:

    • json includes:
      • cookie: A string representing the session cookie if login was successful, or status messages like "No session found" or error descriptions.
      • instructions: Steps to create new credentials using the session cookie.
      • If debug mode is enabled, additional debug information about session file existence, parsing, and cookie extraction is included.
  • On errors, the output JSON contains:

    • success: false
    • error: Error message string.
    • message: "Operation failed"
    • timestamp: ISO timestamp.

Dependencies

  • Requires the external zca-js library for interacting with Zalo's login API.
  • Uses Node.js built-in modules fs and path for file system operations.
  • Stores session data and QR code images locally in files (zalo_session.json and qr.png) within the current working directory.
  • No explicit API keys are required; authentication is done via QR code scanning and session cookies.
  • Ensure the n8n environment has write permissions to the working directory for storing session and QR code files.

Troubleshooting

  • Common Issues:

    • QR code file not generated or missing: Could be due to permission issues or failure in the external library call.
    • Session file missing or corrupted: The node expects a valid zalo_session.json file created after successful login.
    • Timeout waiting for login: The user did not scan the QR code within the specified timeout period.
    • Parsing errors reading session file: May occur if the session file is manually edited or corrupted.
  • Error Messages and Resolutions:

    • "Failed to generate QR code file": Indicates the QR code image was not created; check file system permissions and ensure the external library is functioning.
    • "Login failed or in progress": User has not completed login; try scanning the QR code again or generate a new one.
    • "No session found": No prior login session exists; run the "Generate QR Code" operation first.
    • "Timeout": QR code expired before scanning; regenerate the QR code and scan promptly.
    • "Error reading session": Session file could not be read or parsed; regenerate the QR code and login.

Links and References

Discussion