Zalo Listen Messages icon

Zalo Listen Messages

Lắng nghe tin nhắn mới từ Zalo với long polling

Zalo Listen Messages

AI-generated

Overview

This node listens for new incoming messages from the Zalo messaging platform using a long polling mechanism. It is designed to continuously monitor and capture real-time messages from personal or group chats on Zalo, making it ideal for workflows that require instant reaction to user communications.

Common scenarios where this node is beneficial include:

  • Building chatbots that respond automatically to user messages.
  • Monitoring customer inquiries in Zalo groups or direct messages.
  • Triggering downstream automation based on specific message content or sender.
  • Collecting message data for analytics or logging purposes.

Practical example: A business can use this node to listen for new customer messages on Zalo and automatically send an acknowledgment reply while simultaneously logging the conversation details into a CRM system.


Properties

Name Meaning
Reconnect Interval (Seconds) Time in seconds to wait before attempting to reconnect if the connection to Zalo is lost. Range: 1-60 seconds.
Max Reconnect Attempts Maximum number of reconnection attempts before stopping the listener. Range: 1-50 attempts.
Message Filters Collection of filters to control which messages are processed:
• Only New Messages: Listen only for new messages, ignoring old ones.
• Ignore Self Messages: Skip messages sent by yourself.
• Thread Types: Choose between User Messages and Group Messages.
• Max Messages Per Poll: Limit the number of messages processed per poll cycle (1-100).
Auto Reply Configuration for automatic replies:
• Enable Auto Reply: Turn on/off auto reply feature.
• Reply Template: Message template for auto replies supporting placeholders {{message}} and {{sender}}.
• Reply Delay (Seconds): Delay before sending auto reply (0-30 seconds).
Advanced Options Additional settings:
• Include Message History: Whether to include recent message history in output.
• History Limit: Number of historical messages to include (1-50).
• Debug Mode: Enable detailed logging for troubleshooting.
• Custom User Agent: Override default user agent string used in requests.

Output

The node outputs JSON objects representing each received message with the following structure:

  • messageId: Unique identifier of the message.
  • content: Text content of the message or a placeholder if no text (e.g., attachments or stickers).
  • sender: Display name of the message sender.
  • senderId: Unique ID of the sender.
  • threadId: Identifier of the conversation thread.
  • threadType: Type of thread, either "user" for personal messages or "group" for group chats.
  • timestamp: ISO 8601 formatted timestamp when the message was sent.
  • timestampRaw: Raw timestamp value from the message data.
  • receivedAt: ISO 8601 timestamp when the message was received by the node.
  • isGroup: Boolean indicating if the message is from a group.
  • isSelf: Boolean indicating if the message was sent by the authenticated user.
  • listenerMode: Always "longPolling".
  • rawMessage: The original raw message object from the underlying API.
  • Optional fields related to auto-reply if enabled:
    • autoReplied: Boolean indicating if an auto reply was sent.
    • replyText: The actual text sent as an auto reply.
    • autoReplyThreadId: Thread ID where the auto reply was sent.
    • autoReplyMethod: If fallback method was used for auto reply.
    • autoReplyError / autoReplyFallbackError: Error messages if auto reply failed.

If "Include Message History" is enabled, a history array with recent messages may be included.

The node does not output binary data.


Dependencies

  • Requires valid Zalo API credentials configured in n8n to authenticate and connect to the Zalo platform.
  • Uses an external library (zca-js) to handle Zalo long polling and message listening.
  • Network connectivity to Zalo servers must be stable for continuous operation.
  • Optionally requires another node (like a QR login node) to generate or refresh Zalo session credentials if expired.

Troubleshooting

Common Issues:

  • Connection failures: May occur due to invalid or expired credentials, network issues, or Zalo session expiration.
  • Auto reply failures: Sending automatic replies might fail if the recipient ID is unknown or network errors occur.
  • Message filtering not working as expected: Misconfiguration of filters could cause messages to be ignored unintentionally.

Error Messages and Resolutions:

  • "No Zalo credentials found. Please configure Zalo API credentials first."
    Ensure you have set up and selected valid Zalo API credentials in the node configuration.

  • "Zalo session has expired or is invalid. Please use ZaloLoginQR node to generate new credentials."
    Use the recommended QR login node to refresh your session credentials.

  • "Network connection failed. Please check your internet connection and try again."
    Verify your internet connectivity and firewall settings.

  • "Failed to initialize Zalo API" or "Failed to start long polling"
    Check debug logs if enabled; verify credentials and network status.

  • Auto reply errors are logged but do not stop the node. If auto reply fails, the node attempts a fallback method for personal messages.

Tips:

  • Enable "Debug Mode" in advanced options to get detailed console logs for troubleshooting.
  • Adjust reconnect interval and max reconnect attempts to balance responsiveness and stability.
  • Use message filters carefully to avoid missing important messages.

Links and References

Discussion