2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.io.openhabcloud;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.core.model.script.engine.action.ActionDoc;
18 import org.openhab.io.openhabcloud.internal.CloudService;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * This class provides static methods that can be used in automation rules
24 * for sending notifications to the native apps.
26 * @author Victor Belov - Initial contribution
27 * @author Kai Kreuzer - migrated code to ESH APIs
28 * @author Dan Cunningham - Extended notification enhancements
31 public class NotificationAction {
33 private static final Logger logger = LoggerFactory.getLogger(NotificationAction.class);
35 public static @Nullable CloudService cloudService;
38 * Sends a simple push notification to mobile devices of user
40 * @param userId the cloud user id of the recipient
41 * @param message the body of the notification
44 @ActionDoc(text = "Sends a push notification to mobile devices of user with userId")
45 public static void sendNotification(String userId, String message) {
46 sendNotification(userId, message, null, null);
50 * Sends an advanced push notification to mobile devices of user
52 * @param userId the cloud user id of the recipient
53 * @param message the body of the notification
54 * @param icon name for the notification
55 * @param severity category for the notification
58 @ActionDoc(text = "Sends a push notification to mobile devices of user with userId")
59 public static void sendNotification(String userId, String message, @Nullable String icon,
60 @Nullable String severity) {
61 sendNotification(userId, message, icon, severity, null, null, null, null, null, null);
65 * Sends an advanced push notification to mobile devices of user
67 * @param userId the cloud user id of the recipient
68 * @param message the body of the notification
69 * @param icon name for the notification
70 * @param severity category for the notification
71 * @param title for the notification
72 * @param onClickAction the action to perform when clicked
73 * @param mediaAttachmentUrl the media to attach to a notification
74 * @param actionButton1 an action button in the format "Title=Action"
75 * @param actionButton2 an action button in the format "Title=Action"
76 * @param actionButton3 an action button in the format "Title=Action"
79 @ActionDoc(text = "Sends a push notification to mobile devices of user with userId")
80 public static void sendNotification(String userId, String message, @Nullable String icon, @Nullable String severity,
81 @Nullable String title, @Nullable String onClickAction, @Nullable String mediaAttachmentUrl,
82 @Nullable String actionButton1, @Nullable String actionButton2, @Nullable String actionButton3) {
83 logger.debug("sending notification '{}' to user {}", message, userId);
84 if (cloudService != null) {
85 cloudService.sendNotification(userId, message, icon, severity, title, onClickAction, mediaAttachmentUrl,
86 actionButton1, actionButton2, actionButton3);
91 * Sends a simple notification to log. Log notifications are not pushed to user
92 * devices but are shown to all account users in notifications log.
94 * @param message the body of the notification
97 @ActionDoc(text = "Sends a log notification which is shown in notifications log to all account users")
98 public static void sendLogNotification(String message) {
99 sendLogNotification(message, null, null);
103 * Sends an advanced notification to log. Log notifications are not pushed to user
104 * devices but are shown to all account users in notifications log.
106 * @param message the body of the notification
107 * @param icon name for the notification
108 * @param severity category for the notification
111 @ActionDoc(text = "Sends a log notification which is shown in notifications log to all account users")
112 public static void sendLogNotification(String message, @Nullable String icon, @Nullable String severity) {
113 logger.debug("sending log notification '{}'", message);
114 if (cloudService != null) {
115 cloudService.sendLogNotification(message, icon, severity);
120 * Sends a simple broadcast notification. Broadcast notifications are pushed to all
121 * mobile devices of all users of the account
123 * @param message the body of the notification
126 @ActionDoc(text = "Sends a broadcast notification to all mobile devices of all account users")
127 public static void sendBroadcastNotification(String message) {
128 sendBroadcastNotification(message, null, null);
132 * Sends an advanced broadcast notification. Broadcast notifications are pushed to all
133 * mobile devices of all users of the account
135 * @param message the body of the notification
136 * @param icon name for the notification
137 * @param severity category for the notification
140 @ActionDoc(text = "Sends a push notification to mobile devices of user with userId")
141 public static void sendBroadcastNotification(String message, @Nullable String icon, @Nullable String severity) {
142 sendBroadcastNotification(message, icon, severity, null, null, null, null, null, null);
146 * Sends an advanced broadcast notification. Broadcast notifications are pushed to all
147 * mobile devices of all users of the account
149 * @param message the body of the notification
150 * @param icon name for the notification
151 * @param severity category for the notification
152 * @param title for the notification
153 * @param onClickAction the action to perform when clicked
154 * @param mediaAttachmentUrl the media to attach to a notification
155 * @param actionButton1 an action button in the format "Title=Action"
156 * @param actionButton2 an action button in the format "Title=Action"
157 * @param actionButton3 an action button in the format "Title=Action"
160 @ActionDoc(text = "Sends a push notification to mobile devices of user with userId")
161 public static void sendBroadcastNotification(String message, @Nullable String icon, @Nullable String severity,
162 @Nullable String title, @Nullable String onClickAction, @Nullable String mediaAttachmentUrl,
163 @Nullable String actionButton1, @Nullable String actionButton2, @Nullable String actionButton3) {
164 logger.debug("sending broadcast notification '{}' to all users", message);
165 if (cloudService != null) {
166 cloudService.sendBroadcastNotification(message, icon, severity, title, onClickAction, mediaAttachmentUrl,
167 actionButton1, actionButton2, actionButton3);