BAEL-1745: Twilio SMS article
This commit is contained in:
parent
de3eb20fa4
commit
050cec1aef
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.baeldung.twilio</groupId>
|
||||||
|
<artifactId>sms</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.twilio.sdk</groupId>
|
||||||
|
<artifactId>twilio</artifactId>
|
||||||
|
<version>7.20.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -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 = "YOUR_ACCOUNT_SID";
|
||||||
|
public static final String AUTH_TOKEN = "YOUR_ACCOUNT_TOKEN";
|
||||||
|
|
||||||
|
// Create a phone number in the Twilio console
|
||||||
|
public static final String TWILIO_NUMBER = "+13334445555";
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
|
||||||
|
Message message = Message.creator(
|
||||||
|
new PhoneNumber("+12227779999"),
|
||||||
|
new PhoneNumber(TWILIO_NUMBER),
|
||||||
|
"Sample Twilio SMS using Java")
|
||||||
|
.create();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 = "YOUR_ACCOUNT_SID";
|
||||||
|
public static final String AUTH_TOKEN = "YOUR_ACCOUNT_TOKEN";
|
||||||
|
|
||||||
|
// Create a phone number in the Twilio console
|
||||||
|
public static final String TWILIO_NUMBER = "+13334445555";
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
|
||||||
|
Message message = Message.creator(
|
||||||
|
new PhoneNumber("+12227779999"),
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 = "YOUR_ACCOUNT_SID";
|
||||||
|
public static final String AUTH_TOKEN = "YOUR_AUTH_TOKEN";
|
||||||
|
|
||||||
|
// Create a phone number in the Twilio console
|
||||||
|
public static final String TWILIO_NUMBER = "+13334445555";
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
|
||||||
|
ListenableFuture<ResourceSet<Message>> future = Message.reader().readAsync();
|
||||||
|
Futures.addCallback(
|
||||||
|
future,
|
||||||
|
new FutureCallback<ResourceSet<Message>>() {
|
||||||
|
public void onSuccess(ResourceSet<Message> 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());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 = "YOUR_ACCOUNT_SID";
|
||||||
|
public static final String AUTH_TOKEN = "YOUR_ACCOUNT_TOKEN";
|
||||||
|
|
||||||
|
// Create a phone number in the Twilio console
|
||||||
|
public static final String TWILIO_NUMBER = "+13334445555";
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
|
||||||
|
ResourceSet<Message> messages = Message.reader().read();
|
||||||
|
for (Message message : messages) {
|
||||||
|
System.out.println(message.getSid() + " : " + message.getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue