Zalo Send Message icon

Zalo Send Message

Gửi tin nhắn qua API Zalo sử dụng kết nối đăng nhập bằng cookie

Overview

This node sends messages through the Zalo API using a login authenticated by cookies. It supports sending text messages, quoting previous messages, mentioning users, and attaching multiple files from URLs or local paths. The node handles both user and group message types and allows setting message urgency levels.

Common scenarios include:

  • Automating customer support replies on Zalo.
  • Broadcasting announcements to groups or individual users.
  • Sending multimedia content such as images, documents, or videos alongside text.
  • Quoting previous messages for context in conversations.
  • Mentioning specific users within group chats.

Example: Sending an urgent message with an attached PDF document and mentioning a user in a group chat.

Properties

Name Meaning
Thread ID The ID of the thread (chat) where the message will be sent.
Type The type of message recipient: either "User" (individual chat) or "Group" (group chat).
Message The text content of the message to send.
Urgency The urgency level of the message. Options are: Default, Important, Urgent.
Quote Message Optional quoted message details to reference in the new message, including Message ID, Sender ID, and Content.
Mentions Details about users mentioned in the message, including User ID, position in the message text, and length of the mention.
Attachments One or more attachments to send with the message. Currently supports public URLs for various file types (images JPG/PNG/GIF, PDF, ZIP, DOC, MP4, MP3, etc.). Multiple attachments can be added.
Multiple URLs Comma-separated list of URLs to send multiple files at once. Supports the same file types as Attachments.
Local File Path Path to a local file to attach. Supports relative or absolute paths for various file types (images, PDFs, videos, audio, etc.).

Output

The node outputs an array of JSON objects, each representing the result of sending a message for each input item. Each output object contains:

  • success: Boolean indicating if the message was sent successfully.
  • response: The raw response from the Zalo API after sending the message.
  • threadId: The ID of the thread where the message was sent.
  • threadType: Numeric code representing the thread type (user or group).
  • messageContent: Object containing the message parameters used (text, urgency, quote, mentions, attachments).

If sending fails and "Continue On Fail" is enabled, the output includes:

  • success: false
  • error: Error message describing the failure.

Binary data is not directly output by this node; attachments are uploaded via URLs or local files but not returned as binary in the output.

Dependencies

  • Requires an API key credential that provides a cookie string, IMEI, and user agent for authenticating with the Zalo API.
  • Uses the external zca-js library for interacting with the Zalo API.
  • Node.js fs and path modules for handling local file paths and file system operations.
  • Utility functions for saving files from URLs and removing temporary files.
  • Network access to download attachment files from provided URLs.
  • Proper configuration of credentials with valid Zalo session cookies is mandatory.

Troubleshooting

  • Timeout errors: Large attachments (>10MB recommended limit) may cause timeouts. The node retries sending messages up to 2 times with increasing delays. For very large files (>20MB), it suggests uploading files separately using a dedicated upload node before sending.
  • File not found or unreadable: Local file paths must be correct and accessible. The node tries multiple resolution strategies (current directory, node directory, workspace root, absolute path). If the file cannot be found or read, an error is logged.
  • Authentication failures: Invalid or expired cookies will cause login errors. Ensure credentials are up-to-date.
  • Network issues: Unstable connections can cause send failures or timeouts.
  • Fallback strategy: If sending a message with attachments fails, the node attempts to send the text message first, then sends attachments individually.
  • Error messages: Errors during sending are logged with detailed messages. Common errors include "timeout", "file not found", or "failed to initialize Zalo API".
  • To resolve issues, verify credentials, reduce attachment sizes, check file paths, and ensure stable network connectivity.

Links and References

Discussion