com.telesign.MessagingClient Maven / Gradle / Ivy
Show all versions of TeleSign-SDK Show documentation
package com.telesign;
import java.io.IOException;
import java.net.Proxy;
import java.security.GeneralSecurityException;
import java.util.HashMap;
import java.util.Map;
/**
* TeleSign's Messaging API allows you to easily send SMS messages. You can send alerts, reminders, and notifications,
* or you can send verification messages containing one-time passcodes (OTP).
*/
public class MessagingClient extends RestClient {
private static final String MESSAGING_RESOURCE = "/v1/messaging";
private static final String MESSAGING_STATUS_RESOURCE = "/v1/messaging/%s";
public MessagingClient(String customerId, String apiKey) {
super(customerId, apiKey);
}
public MessagingClient(String customerId, String apiKey, String restEndpoint) {
super(customerId, apiKey, restEndpoint);
}
public MessagingClient(String customerId,
String apiKey,
String restEndpoint,
Integer connectTimeout,
Integer readTimeout,
Integer writeTimeout,
Proxy proxy,
final String proxyUsername,
final String proxyPassword) {
super(customerId, apiKey, restEndpoint, connectTimeout, readTimeout, writeTimeout, proxy, proxyUsername, proxyPassword);
}
/**
* Send a message to the target phone_number.
*
* See https://developer.telesign.com/docs/messaging-api for detailed API documentation.
*/
public TelesignResponse message(String phoneNumber, String message, String messageType, Map params) throws IOException, GeneralSecurityException {
if (params == null) {
params = new HashMap<>();
}
params.put("phone_number", phoneNumber);
params.put("message", message);
params.put("message_type", messageType);
return this.post(MESSAGING_RESOURCE, params);
}
/**
* Retrieves the current status of the message.
*
* See https://developer.telesign.com/docs/messaging-api for detailed API documentation.
*/
public TelesignResponse status(String referenceId, Map params) throws IOException, GeneralSecurityException {
return this.get(String.format(MESSAGING_STATUS_RESOURCE, referenceId), params);
}
}