Search in sources :

Example 1 with SmsException

use of org.thingsboard.rule.engine.api.sms.exception.SmsException in project thingsboard by thingsboard.

the class AwsSmsSender method sendSms.

@Override
public int sendSms(String numberTo, String message) throws SmsException {
    numberTo = this.validatePhoneNumber(numberTo);
    message = this.prepareMessage(message);
    try {
        PublishRequest publishRequest = new PublishRequest().withMessageAttributes(SMS_ATTRIBUTES).withPhoneNumber(numberTo).withMessage(message);
        this.snsClient.publish(publishRequest);
        return this.countMessageSegments(message);
    } catch (Exception e) {
        throw new SmsSendException("Failed to send SMS message - " + e.getMessage(), e);
    }
}
Also used : PublishRequest(com.amazonaws.services.sns.model.PublishRequest) SmsSendException(org.thingsboard.rule.engine.api.sms.exception.SmsSendException) SmsException(org.thingsboard.rule.engine.api.sms.exception.SmsException) SmsSendException(org.thingsboard.rule.engine.api.sms.exception.SmsSendException)

Example 2 with SmsException

use of org.thingsboard.rule.engine.api.sms.exception.SmsException in project thingsboard by thingsboard.

the class TwilioSmsSender method sendSms.

@Override
public int sendSms(String numberTo, String message) throws SmsException {
    numberTo = this.validatePhoneNumber(numberTo);
    message = this.prepareMessage(message);
    try {
        String numSegments = Message.creator(new PhoneNumber(numberTo), new PhoneNumber(this.numberFrom), message).create(this.twilioRestClient).getNumSegments();
        return Integer.valueOf(numSegments);
    } catch (Exception e) {
        throw new SmsSendException("Failed to send SMS message - " + e.getMessage(), e);
    }
}
Also used : PhoneNumber(com.twilio.type.PhoneNumber) SmsParseException(org.thingsboard.rule.engine.api.sms.exception.SmsParseException) SmsSendException(org.thingsboard.rule.engine.api.sms.exception.SmsSendException) SmsException(org.thingsboard.rule.engine.api.sms.exception.SmsException) SmsSendException(org.thingsboard.rule.engine.api.sms.exception.SmsSendException)

Aggregations

SmsException (org.thingsboard.rule.engine.api.sms.exception.SmsException)2 SmsSendException (org.thingsboard.rule.engine.api.sms.exception.SmsSendException)2 PublishRequest (com.amazonaws.services.sns.model.PublishRequest)1 PhoneNumber (com.twilio.type.PhoneNumber)1 SmsParseException (org.thingsboard.rule.engine.api.sms.exception.SmsParseException)1