Minor improvements for Teams notifications

This commit is contained in:
ViacheslavKlimov 2023-08-07 11:51:47 +03:00
parent 1a93db75e0
commit fb149b720c
4 changed files with 11 additions and 6 deletions

View File

@ -88,7 +88,11 @@ public class MicrosoftTeamsNotificationChannel implements NotificationChannel<Mi
}
state = Base64.encodeBase64String(JacksonUtil.OBJECT_MAPPER.writeValueAsBytes(List.of(stateObject)));
}
uri = systemSecurityService.getBaseUrl(ctx.getTenantId(), null, null) + "/dashboards/" + button.getDashboardId();
String baseUrl = systemSecurityService.getBaseUrl(ctx.getTenantId(), null, null);
if (StringUtils.isEmpty(baseUrl)) {
throw new IllegalStateException("Failed to determine base url to construct dashboard link");
}
uri = baseUrl + "/dashboards/" + button.getDashboardId();
if (state != null) {
uri += "?state=" + state;
}

View File

@ -253,7 +253,7 @@ public class DefaultSystemSecurityService implements SystemSecurityService {
baseUrl = generalSettings.getJsonValue().get("baseUrl").asText();
}
if (StringUtils.isEmpty(baseUrl)) {
if (StringUtils.isEmpty(baseUrl) && httpServletRequest != null) {
baseUrl = MiscUtils.constructBaseUrl(httpServletRequest);
}

View File

@ -51,6 +51,7 @@ import org.thingsboard.server.common.data.notification.targets.slack.SlackNotifi
import org.thingsboard.server.common.data.notification.template.DeliveryMethodNotificationTemplate;
import org.thingsboard.server.common.data.notification.template.EmailDeliveryMethodNotificationTemplate;
import org.thingsboard.server.common.data.notification.template.MicrosoftTeamsDeliveryMethodNotificationTemplate;
import org.thingsboard.server.common.data.notification.template.MicrosoftTeamsDeliveryMethodNotificationTemplate.Button.LinkType;
import org.thingsboard.server.common.data.notification.template.NotificationTemplate;
import org.thingsboard.server.common.data.notification.template.NotificationTemplateConfig;
import org.thingsboard.server.common.data.notification.template.SlackDeliveryMethodNotificationTemplate;
@ -560,6 +561,7 @@ public class NotificationApiTest extends AbstractNotificationApiTest {
var button = new MicrosoftTeamsDeliveryMethodNotificationTemplate.Button();
button.setEnabled(true);
button.setText("Button: " + templateParams);
button.setLinkType(LinkType.LINK);
button.setLink("https://" + templateParams);
template.setButton(button);
NotificationTemplate notificationTemplate = new NotificationTemplate();
@ -578,7 +580,7 @@ public class NotificationApiTest extends AbstractNotificationApiTest {
.templateId(notificationTemplate.getId())
.targets(List.of(target.getUuidId()))
.info(EntityActionNotificationInfo.builder()
.entityId(new DeviceId(UUID.randomUUID())) // to test templatization
.entityId(new DeviceId(UUID.randomUUID()))
.actionType(ActionType.ADDED)
.userId(tenantAdminUserId.getId())
.build())

View File

@ -3106,9 +3106,8 @@
"warning": "Warning",
"webhook-url": "Webhook URL",
"webhook-url-required": "Webhook URL is required",
"channel-name": "Chanel name",
"channel-name-required": "Chanel name is required"
"channel-name": "Channel name",
"channel-name-required": "Channel name is required"
},
"ota-update": {
"add": "Add package",