Created
August 19, 2016 18:16
-
-
Save mplacona/f254d15483ec01ace4dd942e822e05f8 to your computer and use it in GitHub Desktop.
SMSBackend.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.twilio.sdk.TwilioRestClient; | |
import com.twilio.sdk.resource.instance.Sms; | |
import java.util.HashMap; | |
import java.util.Map; | |
import static spark.Spark.*; | |
public class SMSBackend { | |
public static void main(String[] args) { | |
get("/", (req, res) -> "Hello, World"); | |
TwilioRestClient client = new TwilioRestClient("YOUR_TWILIO_ACCOUNT_SID", "YOUR_TWILIO_AUTH_TOKEN"); | |
post("/sms", (req, res) -> { | |
String body = req.queryParams("Body"); | |
String to = req.queryParams("To"); | |
String from = "YOUR_TWILIO_PHONE_NUMBER"; | |
Map<String, String> callParams = new HashMap<>(); | |
callParams.put("To", to); | |
callParams.put("From", from); | |
callParams.put("Body", body); | |
Sms message = client.getAccount().getSmsFactory().create(callParams); | |
return message.getSid(); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment