Zalo Login Via QR Code icon

Zalo Login Via QR Code

Đăng nhập Zalo bằng QR code và lưu thông tin vào Credential

Overview

This node enables logging into the Zalo messaging platform via a QR code. It generates a unique QR code for a login session identified by a "state" string, which users scan with their Zalo app to authenticate. The node listens for various events during the login process such as QR code generation, scanning, expiration, decline, and successful login. It can optionally send webhook notifications about these events to a specified URL.

Common scenarios where this node is beneficial include:

  • Automating user authentication in applications that integrate with Zalo.
  • Managing multiple Zalo login sessions programmatically.
  • Receiving real-time updates on login status via webhooks for further processing or notifications.

Practical example:

  • A business application wants to allow users to log in using their Zalo account by scanning a QR code displayed on the website. This node generates the QR code and tracks the login status, sending webhook events to update the UI or backend systems accordingly.

Properties

Name Meaning
State Unique identifier for the QR login session (e.g., user1, user2, session1). Used to associate the QR code with a specific user or session.
Proxy Optional HTTP proxy URL (including credentials) to route Zalo API requests through.
Domain Optional domain URL to use for Zalo API requests (default is usually https://zalo.me).
Webhook URL URL to which webhook event notifications will be sent (e.g., QR expired, scanned, declined, login success). Defaults to https://ai.tamanjsc.com/webhook/zalo-login.
Enable Webhook Boolean flag to enable or disable sending webhook notifications for Zalo events.

Output

The node outputs an object containing:

  • json:

    • success: Indicates if the QR code was generated successfully.
    • state: The unique state identifier for the login session.
    • message: Status message describing the current state.
    • fileName: The filename of the generated QR code image (zalo-qr-code.png).
    • usingExistingCredential: Boolean indicating if existing credentials were used.
    • credentialType: Type of credential used ("n8nZaloApi", "zaloApi", or null).
    • userInfo: Contains displayName and avatar URL of the logged-in user (or placeholders if not available yet).
    • zaloApiInfo: Includes imei, userAgent, and zaloUserId related to the Zalo session.
    • webhook: Details about webhook configuration including enabled status, URL, state, and supported event types.
    • Additional fields related to credential creation status and instructions when applicable.
  • binary:

    • data: The QR code image data encoded as PNG, ready to be used or saved.

This output allows downstream nodes to access the QR code image for display and track login progress and user information.

Dependencies

  • Requires an API key credential or cookie-based credential for Zalo API access, though it can generate a QR code without credentials.
  • Optionally requires an API key credential for n8n's own API to automatically create new Zalo credentials after successful login.
  • Uses the external zca-js library for interacting with Zalo SDK.
  • Uses axios for HTTP requests, including sending webhook notifications.
  • If proxy is configured, HTTP requests are routed through the specified proxy server.

Troubleshooting

  • Timeout generating QR code: If the QR code is not generated within 30 seconds, the node throws a timeout error. Check network connectivity and Zalo API availability.
  • Invalid webhook URL: If the webhook URL is invalid or unreachable, webhook notifications will fail. Verify the URL format and endpoint accessibility.
  • QR code expired: The QR code has a limited lifetime. Users must scan it before expiration; otherwise, a new QR code must be generated.
  • Declined QR code: If the user declines the login request on their device, the node logs this event and optionally sends a webhook notification.
  • Credential creation errors: Automatic creation of Zalo credentials via n8n API may fail due to incorrect API key, wrong API URL, or network issues. Manual credential creation might be necessary.
  • No credentials provided: Without credentials, the node only generates a QR code but cannot perform authenticated actions or save login info.

To resolve common errors:

  • Ensure all required credentials and API keys are correctly configured.
  • Confirm proxy settings if used.
  • Validate webhook URLs and ensure the receiving server is operational.
  • Monitor node logs for detailed error messages.

Links and References

Discussion