RedwoodJS & Infobip: Building Two-Way SMS Messaging - code-examples -

Frequently Asked Questions

Your Infobip API Key and Base URL can be found in your Infobip account dashboard. Look for a section labeled 'API Keys,' 'API Credentials,' or a similar name. The specific location might vary based on the Infobip portal's layout.
You can send SMS messages within a RedwoodJS application by creating a service that utilizes the Infobip Node.js SDK. This service interacts with Infobip's API to send messages programmatically. You then expose this service functionality via a GraphQL mutation or a custom API function within your RedwoodJS application. Be sure to configure the necessary environment variables with your Infobip account credentials first.
Infobip is a cloud communications platform that provides the SMS API used by the RedwoodJS application. The integration uses Infobip's Node.js SDK to interact with their services, allowing you to send and receive SMS messages. You'll need an Infobip account and API key to use this integration.
Prisma, a next-generation ORM, is used to store the history of both inbound and outbound SMS messages. Prisma simplifies database interactions, making it easy to create, read, update, and delete records in the database. The schema in `api/db/schema.prisma` needs to include a `SmsMessage` model.
Create a RedwoodJS API function (using the `rw g function` command) to act as your webhook endpoint. This function will receive incoming messages from Infobip. Configure your Infobip account to send inbound SMS webhooks to the public URL of this function. Implement security measures within your RedwoodJS function to verify the origin and integrity of the incoming webhook data.
You need Node.js (LTS recommended), Yarn, an active Infobip account, your Infobip API Key and Base URL, and a provisioned Infobip phone number. Basic RedwoodJS knowledge is also helpful, along with a way to expose your local development server for webhook testing (like ngrok).
Use a tool like ngrok or cloudflared to create a tunnel from your local development environment to a public URL. This makes your RedwoodJS API function accessible to Infobip for webhook delivery during development. Run `ngrok http 8911` if your RedwoodJS API is running locally on port 8911.
Implement robust signature verification using a strong, randomly generated secret shared with Infobip. Use this secret to verify that incoming webhook requests genuinely originate from Infobip, preventing unauthorized access or data manipulation. Always use HTTPS for webhook URLs.
The client interacts with the RedwoodJS frontend, which communicates with the RedwoodJS API. The API interacts with the Infobip service using the Node.js SDK to send SMS messages to the end user's phone. Inbound messages are sent to the RedwoodJS API via webhooks, then stored in a database using Prisma.
Within your inbound webhook handler, parse the incoming message body for keywords like 'STOP' and 'HELP'. Implement the appropriate logic, such as updating user opt-out status or providing help information. This is essential for compliance with regulations like TCPA.
The `SmsMessage` model is used to store details like message direction, sender and recipient numbers, message content, status, Infobip message and bulk IDs, and a processing flag. It is recommended to index the `infobipMessageId`, `sender`, `recipient`, and `createdAt` fields for efficient querying.
Configure the webhook URL in your Infobip account after you have a publicly accessible URL for your RedwoodJS API function. This URL is necessary for Infobip to send inbound SMS messages to your application. This is typically done during the integration phase after the local API endpoint is ready.
Yes, RedwoodJS allows you to use other Prisma-compatible databases like SQLite, MySQL, or MongoDB by modifying the `provider` setting in the `api/db/schema.prisma` file and setting the correct connection string in the `.env` file. However, this guide assumes the default PostgreSQL settings.
Implement `try...catch` blocks in both service and API functions to handle potential errors. Log errors using Redwood's logger and store error details in the database. Return appropriate HTTP status codes from the webhook handler and structured error responses from the sendSms service to manage issues effectively.