diff --git a/twilio/pom.xml b/twilio/pom.xml new file mode 100644 index 0000000000..13187cfb07 --- /dev/null +++ b/twilio/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + com.baeldung.sms + twilio + 1.0-SNAPSHOT + + + 1.8 + 1.8 + + + + + com.twilio.sdk + twilio + 7.20.0 + + + + diff --git a/twilio/src/main/java/TwilioSmsExample.java b/twilio/src/main/java/TwilioSmsExample.java new file mode 100644 index 0000000000..cf8c162223 --- /dev/null +++ b/twilio/src/main/java/TwilioSmsExample.java @@ -0,0 +1,22 @@ +import com.twilio.Twilio; +import com.twilio.rest.api.v2010.account.Message; +import com.twilio.type.PhoneNumber; + +public class TwilioSmsExample { + // Find your Account Sid and Token at twilio.com/console + public static final String ACCOUNT_SID = "SID"; + public static final String AUTH_TOKEN = "AUTH"; + + // Create a phone number in the Twilio console + public static final String TWILIO_NUMBER = "+12223334444"; + + public static void main(String[] args) { + Twilio.init(ACCOUNT_SID, AUTH_TOKEN); + Message message = Message.creator( + new PhoneNumber("+17778889999"), + new PhoneNumber(TWILIO_NUMBER), + "Sample Twilio SMS using Java") + .create(); + + } +} diff --git a/twilio/src/main/java/TwilioSmsMediaExample.java b/twilio/src/main/java/TwilioSmsMediaExample.java new file mode 100644 index 0000000000..f0b0677198 --- /dev/null +++ b/twilio/src/main/java/TwilioSmsMediaExample.java @@ -0,0 +1,27 @@ +import com.twilio.Twilio; +import com.twilio.converter.Promoter; +import com.twilio.rest.api.v2010.account.Message; +import com.twilio.type.PhoneNumber; + +import java.net.URI; + +public class TwilioSmsMediaExample { + // Find your Account Sid and Token at twilio.com/console + public static final String ACCOUNT_SID = "SID"; + public static final String AUTH_TOKEN = "AUTH"; + + // Create a phone number in the Twilio console + public static final String TWILIO_NUMBER = "+12223334444"; + + public static void main(String[] args) { + Twilio.init(ACCOUNT_SID, AUTH_TOKEN); + Message message = Message.creator( + new PhoneNumber("+17778889999"), + new PhoneNumber(TWILIO_NUMBER), + "Sample Twilio MMS using Java") + .setMediaUrl( + Promoter.listOfOne( + URI.create("http://www.baeldung.com/wp-content/uploads/2017/10/icon-javaseries-home.png"))) + .create(); + } +} diff --git a/twilio/src/main/java/TwilioSmsStatusAsyncExample.java b/twilio/src/main/java/TwilioSmsStatusAsyncExample.java new file mode 100644 index 0000000000..ca55bb1978 --- /dev/null +++ b/twilio/src/main/java/TwilioSmsStatusAsyncExample.java @@ -0,0 +1,34 @@ +import com.google.common.util.concurrent.FutureCallback; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.twilio.Twilio; +import com.twilio.base.ResourceSet; +import com.twilio.rest.api.v2010.account.Message; + +public class TwilioSmsStatusAsyncExample { + // Find your Account Sid and Token at twilio.com/console + public static final String ACCOUNT_SID = "SID"; + public static final String AUTH_TOKEN = "AUTH"; + + // Create a phone number in the Twilio console + public static final String TWILIO_NUMBER = "+12223334444"; + + public static void main(String[] args) { + + Twilio.init(ACCOUNT_SID, AUTH_TOKEN); + ListenableFuture> future = Message.reader().readAsync(); + Futures.addCallback( + future, + new FutureCallback>() { + public void onSuccess(ResourceSet messages) { + for (Message message : messages) { + System.out.println(message.getSid() + " : " + message.getStatus()); + } + } + + public void onFailure(Throwable t) { + System.out.println("Failed to get message status: " + t.getMessage()); + } + }); + } +} diff --git a/twilio/src/main/java/TwilioSmsStatusExample.java b/twilio/src/main/java/TwilioSmsStatusExample.java new file mode 100644 index 0000000000..625af0d848 --- /dev/null +++ b/twilio/src/main/java/TwilioSmsStatusExample.java @@ -0,0 +1,22 @@ +import com.twilio.Twilio; +import com.twilio.base.ResourceSet; +import com.twilio.rest.api.v2010.account.Message; +import com.twilio.type.PhoneNumber; + +public class TwilioSmsStatusExample { + // Find your Account Sid and Token at twilio.com/console + public static final String ACCOUNT_SID = "SID"; + public static final String AUTH_TOKEN = "AUTH"; + + // Create a phone number in the Twilio console + public static final String TWILIO_NUMBER = "+12223334444"; + + public static void main(String[] args) { + + Twilio.init(ACCOUNT_SID, AUTH_TOKEN); + ResourceSet messages = Message.reader().read(); + for (Message message : messages) { + System.out.println(message.getSid() + " : " + message.getStatus()); + } + } +}