Frequently Asked Questions
Use the Vonage Messages API and Node.js SDK. Install the @vonage/server-sdk package, initialize the Vonage client with your API credentials, and then use the messages.send() method, providing the recipient's number, your Vonage number, and the message text. This allows you to programmatically send SMS messages from your Node.js application.
A Vonage Delivery Receipt (DLR) is a webhook notification that provides real-time updates on the delivery status of your SMS messages. These updates include statuses like 'delivered', 'rejected', 'failed', or 'undeliverable', giving you insights into whether your message reached the recipient's handset or encountered issues along the way. The information is crucial for applications requiring delivery confirmation.
While Vonage confirms message submission, it doesn't guarantee delivery. Webhooks offer asynchronous delivery updates. The /webhooks/status endpoint in your app receives these updates, allowing you to react to successful deliveries or handle failures without blocking your main application flow.
Use the Vonage Messages API when you need to send and receive messages programmatically across different channels, including SMS. It's ideal for applications that require confirmation that messages have been successfully delivered to the recipient's device, providing reliable message delivery handling.
Create a Vonage application in the Vonage Dashboard, enable the 'Messages' capability, and configure the 'Status URL' to point to your Express app's webhook route (e.g., YOUR_BASE_URL/webhooks/status). When Vonage sends a DLR POST request, your app must respond with '200 OK' to acknowledge receipt, ensuring Vonage doesn't retry.
ngrok creates a public tunnel to your local development server. This is crucial for testing webhooks during development, as Vonage needs a publicly accessible URL to send DLR callbacks to your /webhooks/status endpoint when running locally.
Log in to your Vonage API Dashboard. Your API key and API secret are displayed on the main homepage. Copy these values and paste them into your .env file (or other secure storage mechanism) as VONAGE_API_KEY and VONAGE_API_SECRET respectively.
The Vonage private key, downloaded when you create a Vonage Application, is crucial for authenticating your application with the Messages API. It's used along with your Application ID to ensure secure API access. Never commit this key to Git; use environment variables or a secure secret store.
A 401 Unauthorized error usually indicates incorrect or missing Vonage API credentials. Double-check your VONAGE_API_KEY, VONAGE_API_SECRET, VONAGE_APPLICATION_ID, and VONAGE_PRIVATE_KEY_PATH in your .env file. Verify they match the values in your Vonage Dashboard, and that the private key file exists and is readable.
Check that your webhook endpoint (/webhooks/status) is publicly accessible (ngrok for development). Ensure it responds with a 200 OK within a few seconds. Verify your Vonage Application's 'Status URL' is correctly set to the public URL, and the default SMS setting is 'Messages API', not 'SMS API'.
For enhanced security, use Signed Webhooks by configuring a webhook signing key in your Vonage Application. Your webhook handler should verify the signature in the request header using this key, preventing spoofing. See the Vonage documentation for details on Signed Webhooks.
Statuses like 'delivered' mean the message reached the handset. 'rejected' or 'failed' indicate delivery failures. 'undeliverable' suggests a permanent issue, while 'expired' means the message timed out before successful delivery. Check Vonage DLR documentation for a comprehensive list of statuses.
Yes, using an invalid or test phone number is a good way to test failure paths and see how your application handles DLR statuses like 'failed', 'rejected', or 'undeliverable', providing insights into your application's error handling.
Your /webhooks/status endpoint should handle potential errors (e.g., database issues) gracefully. Use try...catch blocks. Always return a 200 OK to Vonage first, even if your internal processing fails, to avoid Vonage webhook retries. Log the error and handle it separately, potentially using a retry queue.