Zalo Trigger icon

Zalo Trigger

Starts the workflow when Zalo events occur

Overview

The Zalo Trigger node for n8n starts workflows in response to events from the Zalo platform, specifically for Zalo Official Account (OA) integrations. It supports two main event types: receiving new messages and handling OAuth authentication callbacks. This node is useful for automating processes such as responding to incoming Zalo messages or managing OAuth authentication flows for secure API access.

Practical examples:

  • Automatically process and respond to customer messages sent to your Zalo OA.
  • Handle OAuth authentication to securely connect your Zalo OA with n8n, storing tokens for subsequent API calls.

Properties

Name Type Meaning
Event options The Zalo event to listen for. Options:
• Message Received – triggers on new messages.
• OAuth Callback – handles OAuth callback from Zalo.
Information notice Instructional notice: Configure this webhook URL in your Zalo OA dashboard to receive events.

Output

For "Message Received" Event

  • Outputs the JSON payload received from Zalo when a new message is sent to your OA. The structure of this payload depends on Zalo's webhook specification but typically includes details about the sender, message content, and timestamp.

Example output:

[
  {
    // ...fields as provided by Zalo webhook, e.g.:
    "sender": { "id": "user_id" },
    "message": { "text": "Hello" },
    "timestamp": 1234567890
  }
]

For "OAuth Callback" Event

  • On successful authentication:
    • success: true
    • tokenInfo: Contains accessToken, refreshToken, expiresIn, tokenExpiryDate
    • message: Success message
    • credentialUpdateInstructions: Instructions for updating credentials

Example output:

[
  {
    "success": true,
    "tokenInfo": {
      "accessToken": "string",
      "refreshToken": "string",
      "expiresIn": 3600,
      "tokenExpiryDate": "2024-06-01T12:00:00.000Z"
    },
    "message": "Authentication successful! Tokens stored in workflow data.",
    "credentialUpdateInstructions": "To use these tokens with your Zalo node, update your Zalo API credentials with: ..."
  }
]
  • On authentication failure:
    • success: false
    • error: Error code or message
    • errorDescription: Description of the error (if available)

Example output:

[
  {
    "success": false,
    "error": "invalid_grant",
    "errorDescription": "Authorization code expired"
  }
]

Dependencies

  • External Service: Requires a Zalo Official Account (OA).
  • API Credentials: Needs Zalo API credentials (appId, secretKey) configured in n8n.
  • Environment: Webhook URLs must be registered in the Zalo OA dashboard to receive events.
  • n8n Configuration: The node uses webhooks; ensure your n8n instance is accessible from the internet or via a tunnel for Zalo to deliver events.

Troubleshooting

  • Common Issues:

    • Webhook not triggered: Ensure the webhook URL is correctly set in the Zalo OA dashboard and that your n8n instance is reachable.
    • OAuth errors: If you see errors like No authorization code received or App ID is missing from the request, check your OAuth app configuration and ensure all required parameters are present.
    • Token storage issues: Tokens are stored in memory; restarting n8n will clear them. Update your credentials promptly after authentication.
  • Error Messages:

    • "Error exchanging code for tokens": Indicates an issue during OAuth token exchange. Check your app credentials and the validity of the authorization code.
    • "App ID is missing from the request": The OAuth callback did not include the required App ID. Verify your state parameter encoding and callback setup.
    • "Failed to exchange code for tokens": Network or credential problem during token exchange. Double-check your secret key and app ID.

Links and References

Discussion