Developer Guide: RedwoodJS SMS with Vonage Delivery Status - code-examples -

Frequently Asked Questions

Use the Vonage Messages API and a RedwoodJS function. Install the Vonage Server SDK, create an API endpoint, and use the SDK's `messages.send()` method. Ensure your Vonage application is configured with the correct credentials and a linked virtual number.
The Vonage Messages API allows RedwoodJS apps to send and receive SMS messages and handle delivery statuses. It offers features like delivery receipts and two-way communication.
Prisma is RedwoodJS's default ORM, simplifying database interactions. The `SmsMessage` model in the Prisma schema stores message details, statuses, and Vonage IDs.
Ngrok is essential during development to expose your local RedwoodJS API for receiving Vonage webhooks. For production, use your platform's public URL/ingress.
Yes, configure a Vonage virtual number and set the inbound webhook URL in your Vonage Application settings. Create a RedwoodJS function to handle incoming messages at the specified endpoint.
Create a RedwoodJS function at the status webhook URL defined in your Vonage Application settings. This function will receive status updates (e.g., 'delivered', 'failed') and can update your database accordingly.
The `vonageMessageId`, returned by the Vonage API, uniquely identifies each message. It's crucial for correlating delivery status updates with the original outbound message in your database.
In your Vonage Application settings, set the Inbound and Status URLs to your public RedwoodJS API endpoints (e.g., `/api/webhooks/inbound`). Use `ngrok` for local development and your platform's URL for production.
Vonage relies on a quick `200 OK` response to acknowledge webhook receipt. Failure to do so can lead to Vonage retrying the webhook, potentially causing duplicate processing.
Store your private key file securely, never commit it to version control, and add it to `.gitignore`. For production, prefer using environment variables or secret stores managed by your platform.
Be mindful of how `process.cwd()` resolves in built functions. Ensure the `VONAGE_PRIVATE_KEY_PATH` is correctly set in your .env file. Consider reading the content of the key into an environment variable for improved portability.
Double-check your Vonage application setup, including the webhook URLs and linked number. Verify ngrok is running correctly during development. Use the ngrok interface to inspect incoming requests.
Ensure your database is running and accessible from the Redwood API. Verify the DATABASE_URL in your .env file is correct and Prisma migrations were applied successfully.
Vonage expects numbers in E.164 format (e.g., +14155551212). Use a library like `libphonenumber-js` or ensure your input is properly formatted before sending to Vonage.