A standalone Spring Boot microservice for sending SMS messages via Twilio.
- Send SMS: Simple REST API to send text messages.
- Logging: Console logs for every request and response.
- Error Handling: Detailed error messages for debugging.
- Java 17 or higher.
- Maven (optional, wrapper included or use IDE).
- Twilio Account (Account SID, Auth Token, and a Twilio Phone Number).
-
Clone the repository:
git clone <https://github.com/ezManish/Twilio-backend.git> cd Twilio-Service
-
Configure Credentials: Copy the example configuration file:
cp src/main/resources/application.properties.example src/main/resources/application.properties
Open
src/main/resources/application.propertiesand fill in your Twilio details:twilio.account_sid=YOUR_ACTUAL_SID twilio.auth_token=YOUR_ACTUAL_TOKEN twilio.phone_number=+1234567890
Note:
application.propertiesis git-ignored to keep your secrets safe.
You can run the application using Maven:
mvn spring-boot:runOr simply run the TwilioSmsApplication.java file from your IDE (VS Code, IntelliJ).
Server runs on: http://localhost:8082
Endpoint: POST /api/sms/send
Request Body (JSON):
{
"to": "+919876543210",
"message": "Hello from Twilio Service!"
}Response:
SMS sent successfully! SID: SMxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
To run the application locally:
-
Configure Environment Variables: Open the
.envfile in the project root and fill in your credentials:TWILIO_ACCOUNT_SID=your_actual_sid TWILIO_AUTH_TOKEN=your_actual_token TWILIO_PHONE_NUMBER=+1234567890
Note: The
.envfile is git-ignored to keep your secrets safe. -
Run the Application:
mvn spring-boot:run
The application will automatically load variables from
.env.
A PowerShell script is included to quickly test the service.
- Start the application.
- Open a new terminal.
- Run the script:
(Replace with your verified phone number).
./test-sms.ps1 -to "+919876543210" -message "Test Message"
- Trial Account Error: If you see an error about an "unverified number", you strictly need to add that phone number to your Verified Caller IDs in the Twilio Console.
- External Access: To access this API from another device (e.g., phone), use your computer's local IP address (run
ipconfigto find it) instead oflocalhost.