Frequently Asked Questions
Text "SUBSCRIBE" to the designated virtual mobile number (VMN) provided by the campaign organizer. The system will add your number to the subscriber database and send you a confirmation message. You can unsubscribe at any time by texting "STOP".
To opt out of the SMS campaign, simply text "STOP" to the VMN. The application will update your subscription status in the database to "unsubscribed" and confirm your opt-out via SMS. You can resubscribe by texting "SUBSCRIBE".
MessageBird is the Communications Platform as a Service (CPaaS) that handles sending and receiving SMS messages in this application. It provides the API and infrastructure for SMS communication, including webhooks to notify your application about incoming messages.
The admin interface allows broadcasting messages to all active subscribers. The application batches recipients in groups of 50 (MessageBird's limit per request) and sends the message via the MessageBird API using Node.js. The result page provides feedback on the queuing status.
Install the 'messagebird' npm package (`npm install messagebird`). Then, require the package, initialize it with your API key, and use the SDK's `messages.create` method to send messages. Incoming messages are handled by configuring a webhook endpoint with MessageBird that points to a route in your Express app (e.g., `/webhook`).
Subscriber data is stored in a MongoDB database. Each subscriber document contains the phone number, subscription status, and the timestamp of the last status update. A unique index on the phone number field ensures data integrity and efficient lookups.
Localtunnel creates a publicly accessible URL for your locally running application during development, allowing MessageBird webhooks to reach your server. This is necessary because webhooks require a public URL, which your local development environment doesn't have directly.
In the MessageBird Dashboard, go to "Numbers", find your number, and click the "Flow" icon. Create a "Custom Flow" with "SMS" as the trigger. Add a "Forward to URL" step, set the method to "POST", and paste your Localtunnel URL (e.g., https://your-subdomain.loca.lt/webhook) as the destination URL. Publish the flow to activate it.
A Virtual Mobile Number (VMN) is required to receive incoming SMS messages, such as "SUBSCRIBE" and "STOP" commands, and can also serve as the sender ID for your outgoing messages. You'll purchase this from the "Numbers" section in the MessageBird dashboard.
The admin panel is built using a simple HTML form within the Express app. The GET '/' route displays this form, allowing administrators to enter a message to broadcast. Submitting the form triggers a POST '/send' request, which then handles broadcasting the message.
Some countries allow using an alphanumeric Sender ID (like 'MyBrand') instead of a VMN for outgoing messages. Check MessageBird's documentation for supported countries and regulations. You still need a VMN to *receive* messages.
While Localtunnel is suitable for initial testing, Ngrok offers more stable tunnels and URLs, making it a better choice for more extensive development or when dealing with webhooks that require a consistent URL during testing.
The application uses Node.js for the backend runtime, Express as the web framework, MongoDB for data storage, and MessageBird for SMS communication. It also utilizes 'dotenv' for managing environment variables. Utilities like 'localtunnel' are only used for development purposes.
Implement robust error handling using `try...catch` blocks within your webhook route handler and within individual steps involving interactions with both the database and the MessageBird API. Log errors server-side. Return a 200 OK to MessageBird unless you want it to retry specific transient errors.
Secure the admin endpoints ('/' and '/send') with proper authentication and authorization. Implement input validation and sanitization to prevent injection attacks. Use environment variables for sensitive information, enforce HTTPS, apply rate limiting, and ensure adherence to compliance rules and regulations like GDPR and TCPA.
Content Loading Error
We encountered an error while processing this content.