Frequently Asked Questions
Use the Vonage Messages API with the Express framework in a Node.js application. This involves setting up a project with dependencies like `express`, `@vonage/server-sdk`, and `dotenv`, configuring environment variables, and implementing a POST route to handle SMS sending logic.
The Vonage Messages API is a service for sending various types of messages programmatically. It supports SMS, MMS, WhatsApp, and other channels, offering reliability, global reach, and modern features. It is preferred over the older SMS API.
Express.js simplifies building robust APIs in Node.js. Its minimalist design, widespread adoption, and compatibility with middleware make it a practical choice for handling API requests and responses in an SMS application.
Use the private key path (`VONAGE_PRIVATE_KEY_PATH`) for local development, as it's more manageable. Use the private key content (`VONAGE_PRIVATE_KEY_CONTENT`) in environments where mounting files is difficult, such as some PaaS deployments like Heroku.
Yes, use the E.164 phone number format (e.g., +14155550100) for international SMS. For robust handling and validation of various number formats, use a dedicated library like `libphonenumber-js` or `google-libphonenumber`.
Implement a `try...catch` block around the `vonage.messages.send` function. Log the error details from `err.response.data` if available, and return a user-friendly error message in the API response with a 500 status code.
Trial accounts may require whitelisting destination numbers. This means you can only send to numbers you have verified in your Vonage Dashboard settings under Test Numbers. Messages might also include demo branding and may not support all features.
Store credentials like API keys and private keys in a `.env` file (included in `.gitignore`) for local development. For production, utilize dedicated secrets management solutions like AWS Secrets Manager or environment variable injection.
Standard SMS messages (GSM-7 encoding) are limited to 160 characters. Messages containing non-standard characters (like emojis) use UCS-2 encoding, reducing the limit to 70 characters per segment. Longer messages are split into multiple segments (and billed accordingly).
Use middleware like `express-rate-limit` to prevent abuse or accidental overload. Configure parameters like `windowMs` (time window) and `max` (request limit) to control the rate of incoming requests.
While basic regex can provide some initial checks, always use a dedicated phone number validation library like `libphonenumber-js` or `google-libphonenumber` in production. These libraries ensure accurate parsing, validation, and formatting of international numbers in E.164 format.
Use centralized logging, implement a health check endpoint, and track key metrics like request rate/latency, error rates, and successful/failed SMS submissions. Tools like Prometheus and APM services like Datadog or New Relic are recommended for production monitoring.
Message queues decouple your API response from the SMS sending process, handling large volumes efficiently. They enhance API responsiveness by offloading SMS processing to worker processes, preventing bottlenecks, especially for large-scale or bulk message delivery.
This error occurs when using a trial Vonage account to send SMS to unverified numbers. Add the recipient's number to your whitelisted test numbers in the Vonage Dashboard or upgrade to a paid account.
The status URL receives POST requests from Vonage with updates on message delivery status (e.g., delivered, failed, rejected). This allows real-time tracking and handling of delivery outcomes, providing deeper insights than message submission alone.
Content Loading Error
We encountered an error while processing this content.