The Unimatrix Java SDK provides convenient access to integrate communication capabilities into your Java applications using the Unimatrix HTTP API. The SDK provides support for sending SMS, 2FA verification, and phone number lookup.
Before you begin, you need an Unimatrix account. If you don't have one yet, you can sign up for an Unimatrix account and get free credits to get you started.
Check out the documentation at unimtx.com/docs for a quick overview.
The recommended way to install the Unimatrix SDK for Java is with a dependency management tool such as Maven or Gradle, which is available on Maven Central.
Add this dependency to your project's pom.xml file:
<dependency>
<groupId>com.unimtx</groupId>
<artifactId>uni-sdk</artifactId>
<version>0.3.0</version>
</dependency>Add this dependency to your project's build.gradle file:
implementation "com.unimtx:uni-sdk:0.3.0"The following example shows how to use the Unimatrix Java SDK to interact with Unimatrix services.
import com.unimtx.Uni;
public class Example {
private static String ACCESS_KEY_ID = "your access key id";
private static String ACCESS_KEY_SECRET = "your access key secret";
public static void main(String[] args) {
Uni.init(ACCESS_KEY_ID, ACCESS_KEY_SECRET);
}
}or you can configure your credentials by environment variables:
export UNIMTX_ACCESS_KEY_ID=your_access_key_id
export UNIMTX_ACCESS_KEY_SECRET=your_access_key_secretSend a text message to a single recipient.
import com.unimtx.Uni;
import com.unimtx.UniException;
import com.unimtx.UniResponse;
import com.unimtx.model.UniMessage;
class Example {
public static void main(String[] args) {
Uni.init();
UniMessage message = UniMessage.build()
.setTo("+1206880xxxx") // in E.164 format
.setText("Your verification code is 2048.");
try {
UniResponse res = message.send();
System.out.println(res.data);
} catch (UniException e) {
System.out.println("Error: " + e);
System.out.println("RequestId: " + e.requestId);
}
}
}Send a one-time passcode (OTP) to a recipient. The following example will send a automatically generated verification code to the user.
import com.unimtx.Uni;
import com.unimtx.UniResponse;
import com.unimtx.model.UniOtp;
class Example {
public static void main(String[] args) {
Uni.init();
UniResponse res = UniOtp.build()
.setTo("+1206880xxxx")
.send();
System.out.println(res.data);
}
}Verify the one-time passcode (OTP) that a user provided. The following example will check whether the user-provided verification code is correct.
import com.unimtx.Uni;
import com.unimtx.UniResponse;
import com.unimtx.model.UniOtp;
class Example {
public static void main(String[] args) {
Uni.init();
UniResponse res = UniOtp.build()
.setTo("+1206880xxxx")
.setCode("123456") // the code user provided
.verify();
System.out.println(res.valid);
}
}To find Unimatrix SDKs in other programming languages, check out the list below:
This library is released under the MIT License.