You can set environment variables
Posted: Sun Dec 22, 2024 8:45 am
of(System.getenv("GROUP_PHONE_NUMBERS").split(",")); } // more code will go in here } [ this code with imports on GitHub ] The annotation @RestController tells Spring that this class should be scanned for methods that can handle HTTP requests. We'll write one soon. The area Set<String> groupPhoneNumbers on line 4 is initialized in the constructor by reading an environment variable whose value is a string of comma-separated phone numbers in E.164 format . These numbers should include your mobile phone and the phones of all other members of your group (on the right side in the diagrams above).
You can set environment variables directly in your IDE: Screenshot showing how to set environment variables in IntelliJ IDEA IntelliJ IDEA Environment Variable Configuration Method of processing HTTP philippines whatsapp number requests To make it easier to write TwiML correctly, we'll use Twilio's library for Java . Add the following code snippet to the <maven> section <dependencies> of the Mavenpom.xml configuration file at the very top of your project: XML Copy the code <dependency> <groupId>com.twilio.sdk</groupId> <artifactId>twilio</artifactId> <version>8.18.0</version> </dependency> [ view this code in the context of the project on GitHub ] We always recommend using the latest version of the Twilio libraries.
At the time of writing, the latest version is 8.18.0 and you can check for newer versions at mvnrepository.com . You may need to tell your IDE to refresh Maven's changes at this point. Then add this code to your class SmsHandler : Java Copy the code @RequestMapping( value = "/sms", method = {RequestMethod.GET, RequestMethod.POST}, produces = "application/xml") @ResponseBody public String handleSmsWebhook( @RequestParam("From") String fromNumber, @RequestParam("To") String twilioNumber, @RequestParam("Body") String messageBody) { List<Message> outgoingMessages; if (groupPhoneNumbers.contains(fromNumber)) { outgoingMessages = messagesSentFromGroup(fromNumber, twilioNumber, messageBody); } else { outgoingMessages = messagesSentToGroup(fromNumber, twilioNumber, messageBody); } MessagingResponse.
Builder responseBuilder = new MessagingResponse.Builder(); outgoingMessages.forEach(responseBuilder::message); return responseBuilder.build().toXml(); } [ this code with imports on GitHub ] This method starts with many annotations recognized by Spring: @RequestMapping tells Spring that this method should be used for requests GET and POST that the response /sms is .Content-typeapplication/xml @ResponseBody tells Spring that the return value of this method should be used as the body of the HTTP response. The annotations @RequestParam instruct Spring to extract named parameters from the HTTP request and pass them as arguments to the method. This works both for GET and POST even if the parameters are in different parts of the HTTP request.
You can set environment variables directly in your IDE: Screenshot showing how to set environment variables in IntelliJ IDEA IntelliJ IDEA Environment Variable Configuration Method of processing HTTP philippines whatsapp number requests To make it easier to write TwiML correctly, we'll use Twilio's library for Java . Add the following code snippet to the <maven> section <dependencies> of the Mavenpom.xml configuration file at the very top of your project: XML Copy the code <dependency> <groupId>com.twilio.sdk</groupId> <artifactId>twilio</artifactId> <version>8.18.0</version> </dependency> [ view this code in the context of the project on GitHub ] We always recommend using the latest version of the Twilio libraries.
At the time of writing, the latest version is 8.18.0 and you can check for newer versions at mvnrepository.com . You may need to tell your IDE to refresh Maven's changes at this point. Then add this code to your class SmsHandler : Java Copy the code @RequestMapping( value = "/sms", method = {RequestMethod.GET, RequestMethod.POST}, produces = "application/xml") @ResponseBody public String handleSmsWebhook( @RequestParam("From") String fromNumber, @RequestParam("To") String twilioNumber, @RequestParam("Body") String messageBody) { List<Message> outgoingMessages; if (groupPhoneNumbers.contains(fromNumber)) { outgoingMessages = messagesSentFromGroup(fromNumber, twilioNumber, messageBody); } else { outgoingMessages = messagesSentToGroup(fromNumber, twilioNumber, messageBody); } MessagingResponse.
Builder responseBuilder = new MessagingResponse.Builder(); outgoingMessages.forEach(responseBuilder::message); return responseBuilder.build().toXml(); } [ this code with imports on GitHub ] This method starts with many annotations recognized by Spring: @RequestMapping tells Spring that this method should be used for requests GET and POST that the response /sms is .Content-typeapplication/xml @ResponseBody tells Spring that the return value of this method should be used as the body of the HTTP response. The annotations @RequestParam instruct Spring to extract named parameters from the HTTP request and pass them as arguments to the method. This works both for GET and POST even if the parameters are in different parts of the HTTP request.