Search in sources :

Example 1 with ApiException

use of com.twilio.exception.ApiException in project mxisd by kamax-io.

the class PhoneSmsTwilioConnector method send.

@Override
public void send(String recipient, String content) {
    if (StringUtils.isBlank(cfg.getAccountSid()) || StringUtils.isBlank(cfg.getAuthToken()) || StringUtils.isBlank(cfg.getNumber())) {
        log.error("Twilio connector in not fully configured and is missing mandatory configuration values.");
        throw new NotImplementedException("Phone numbers cannot be validated at this time. Contact your administrator.");
    }
    recipient = "+" + recipient;
    log.info("Sending SMS notification from {} to {} with {} characters", cfg.getNumber(), recipient, content.length());
    try {
        Message.creator(new PhoneNumber("+" + recipient), new PhoneNumber(cfg.getNumber()), content).create();
    } catch (ApiException e) {
        throw new InternalServerError(e);
    }
}
Also used : NotImplementedException(io.kamax.mxisd.exception.NotImplementedException) PhoneNumber(com.twilio.type.PhoneNumber) InternalServerError(io.kamax.mxisd.exception.InternalServerError) ApiException(com.twilio.exception.ApiException)

Aggregations

ApiException (com.twilio.exception.ApiException)1 PhoneNumber (com.twilio.type.PhoneNumber)1 InternalServerError (io.kamax.mxisd.exception.InternalServerError)1 NotImplementedException (io.kamax.mxisd.exception.NotImplementedException)1