-
-
Save manniru/b39eb23eeeee85e917b3 to your computer and use it in GitHub Desktop.
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
| package com.twilio; | |
| import javax.servlet.http.HttpServlet; | |
| import javax.servlet.http.HttpServletRequest; | |
| import javax.servlet.http.HttpServletResponse; | |
| import java.io.IOException; | |
| import java.util.Map; | |
| import java.util.HashMap; | |
| import com.twilio.sdk.resource.instance.Account; | |
| import com.twilio.sdk.TwilioRestClient; | |
| import com.twilio.sdk.TwilioRestException; | |
| import com.twilio.sdk.resource.factory.SmsFactory; | |
| import com.twilio.sdk.resource.instance.Sms; | |
| public class TwilioServlet extends HttpServlet { | |
| /* Find your sid and token at twilio.com/user/account */ | |
| public static final String ACCOUNT_SID = "AC123"; | |
| public static final String AUTH_TOKEN = "456bef"; | |
| //Handle an incoming HTTP Request | |
| public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { | |
| //Create a Twilio REST client | |
| TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN); | |
| Account account = client.getAccount(); | |
| //Use the API to send a text message | |
| SmsFactory smsFactory = account.getSmsFactory(); | |
| Map<String, String> smsParams = new HashMap<String, String>(); | |
| smsParams.put("To", "+14105551234"); | |
| smsParams.put("From", "(410) 555-6789"); // Replace with a Twilio phone number in your account | |
| smsParams.put("Body", "Where's Wallace?"); | |
| Sms sms = smsFactory.create(smsParams); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment