Search in sources :

Example 1 with SmsSender

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

the class DefaultSmsService method sendTestSms.

@Override
public void sendTestSms(TestSmsRequest testSmsRequest) throws ThingsboardException {
    SmsSender testSmsSender;
    try {
        testSmsSender = this.smsSenderFactory.createSmsSender(testSmsRequest.getProviderConfiguration());
    } catch (Exception e) {
        throw handleException(e);
    }
    this.sendSms(testSmsSender, testSmsRequest.getNumberTo(), testSmsRequest.getMessage());
    testSmsSender.destroy();
}
Also used : NestedRuntimeException(org.springframework.core.NestedRuntimeException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) SmsSender(org.thingsboard.rule.engine.api.sms.SmsSender)

Example 2 with SmsSender

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

the class DefaultSmsService method updateSmsConfiguration.

@Override
public void updateSmsConfiguration() {
    AdminSettings settings = adminSettingsService.findAdminSettingsByKey(TenantId.SYS_TENANT_ID, "sms");
    if (settings != null) {
        try {
            JsonNode jsonConfig = settings.getJsonValue();
            SmsProviderConfiguration configuration = JacksonUtil.convertValue(jsonConfig, SmsProviderConfiguration.class);
            SmsSender newSmsSender = this.smsSenderFactory.createSmsSender(configuration);
            if (this.smsSender != null) {
                this.smsSender.destroy();
            }
            this.smsSender = newSmsSender;
        } catch (Exception e) {
            log.error("Failed to create SMS sender", e);
        }
    }
}
Also used : SmsProviderConfiguration(org.thingsboard.server.common.data.sms.config.SmsProviderConfiguration) JsonNode(com.fasterxml.jackson.databind.JsonNode) NestedRuntimeException(org.springframework.core.NestedRuntimeException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) AdminSettings(org.thingsboard.server.common.data.AdminSettings) SmsSender(org.thingsboard.rule.engine.api.sms.SmsSender)

Aggregations

NestedRuntimeException (org.springframework.core.NestedRuntimeException)2 SmsSender (org.thingsboard.rule.engine.api.sms.SmsSender)2 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 AdminSettings (org.thingsboard.server.common.data.AdminSettings)1 SmsProviderConfiguration (org.thingsboard.server.common.data.sms.config.SmsProviderConfiguration)1