2 * Copyright (c) 2010-2023 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.binding.webexteams.internal;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.core.automation.annotation.ActionInput;
18 import org.openhab.core.automation.annotation.ActionOutput;
19 import org.openhab.core.automation.annotation.RuleAction;
20 import org.openhab.core.thing.binding.ThingActions;
21 import org.openhab.core.thing.binding.ThingActionsScope;
22 import org.openhab.core.thing.binding.ThingHandler;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * The {@link WebexTeamsActions} class defines rule actions for sending messages
29 * @author Tom Deckers - Initial contribution
31 @ThingActionsScope(name = "webexteams")
33 public class WebexTeamsActions implements ThingActions {
35 private final Logger logger = LoggerFactory.getLogger(WebexTeamsActions.class);
36 private @Nullable WebexTeamsHandler handler;
38 @RuleAction(label = "@text/sendMessageActionLabel", description = "@text/sendMessageActionDescription")
39 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendMessage(
40 @ActionInput(name = "text") @Nullable String text) {
42 logger.warn("Cannot send Message as text is missing.");
46 final WebexTeamsHandler handler = this.handler;
47 if (handler == null) {
48 logger.debug("Handler is null, cannot send message.");
51 return handler.sendMessage(text);
55 @RuleAction(label = "@text/sendMessageAttActionLabel", description = "@text/sendMessageAttActionDescription")
56 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendMessage(
57 @ActionInput(name = "text") @Nullable String text, @ActionInput(name = "attach") @Nullable String attach) {
59 logger.warn("Cannot send Message as text is missing.");
63 logger.warn("Cannot send Message as attach is missing.");
67 final WebexTeamsHandler handler = this.handler;
68 if (handler == null) {
69 logger.debug("Handler is null, cannot send message.");
72 return handler.sendMessage(text, attach);
76 @RuleAction(label = "@text/sendRoomMessageActionLabel", description = "@text/sendRoomMessageActionDescription")
77 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendRoomMessage(
78 @ActionInput(name = "roomId") @Nullable String roomId, @ActionInput(name = "text") @Nullable String text) {
80 logger.warn("Cannot send Message as text is missing.");
84 logger.warn("Cannot send Message as roomId is missing.");
88 final WebexTeamsHandler handler = this.handler;
89 if (handler == null) {
90 logger.debug("Handler is null, cannot send message.");
93 return handler.sendRoomMessage(roomId, text);
97 @RuleAction(label = "@text/sendRoomMessageAttActionLabel", description = "@text/sendRoomMessageAttActionDescription")
98 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendRoomMessage(
99 @ActionInput(name = "roomId") @Nullable String roomId, @ActionInput(name = "text") @Nullable String text,
100 @ActionInput(name = "attach") @Nullable String attach) {
102 logger.warn("Cannot send Message as text is missing.");
105 if (roomId == null) {
106 logger.warn("Cannot send Message as roomId is missing.");
109 if (attach == null) {
110 logger.warn("Cannot send Message as attach is missing.");
113 final WebexTeamsHandler handler = this.handler;
114 if (handler == null) {
115 logger.debug("Handler is null, cannot send message.");
118 return handler.sendRoomMessage(roomId, text, attach);
122 @RuleAction(label = "@text/sendPersonMessageActionLabel", description = "@text/sendPersonMessageActionDescription")
123 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendPersonMessage(
124 @ActionInput(name = "personEmail") @Nullable String personEmail,
125 @ActionInput(name = "text") @Nullable String text) {
127 logger.warn("Cannot send Message as text is missing.");
130 if (personEmail == null) {
131 logger.warn("Cannot send Message as personEmail is missing.");
135 final WebexTeamsHandler handler = this.handler;
136 if (handler == null) {
137 logger.debug("Handler is null, cannot send message.");
140 return handler.sendPersonMessage(personEmail, text);
144 @RuleAction(label = "@text/sendPersonMessageAttActionLabel", description = "@text/sendPersonMessageAttActionDescription")
145 public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendPersonMessage(
146 @ActionInput(name = "personEmail") @Nullable String personEmail,
147 @ActionInput(name = "text") @Nullable String text, @ActionInput(name = "attach") @Nullable String attach) {
149 logger.warn("Cannot send Message as text is missing.");
152 if (personEmail == null) {
153 logger.warn("Cannot send Message as personEmail is missing.");
156 if (attach == null) {
157 logger.warn("Cannot send Message as attach is missing.");
161 final WebexTeamsHandler handler = this.handler;
162 if (handler == null) {
163 logger.debug("Handler is null, cannot send message.");
166 return handler.sendPersonMessage(personEmail, text, attach);
170 public static boolean sendMessage(@Nullable ThingActions actions, @Nullable String text) {
171 if (actions instanceof WebexTeamsActions) {
172 return ((WebexTeamsActions) actions).sendMessage(text);
174 throw new IllegalArgumentException("Instance is not a WebexTeamsActions class.");
178 public static boolean sendMessage(@Nullable ThingActions actions, @Nullable String text, @Nullable String attach) {
179 if (actions instanceof WebexTeamsActions) {
180 return ((WebexTeamsActions) actions).sendMessage(text, attach);
182 throw new IllegalArgumentException("Instance is not a WebexTeamsActions class.");
186 public static boolean sendRoomMessage(@Nullable ThingActions actions, @Nullable String roomId,
187 @Nullable String text) {
188 if (actions instanceof WebexTeamsActions) {
189 return ((WebexTeamsActions) actions).sendRoomMessage(roomId, text);
191 throw new IllegalArgumentException("Instance is not a WebexTeamsActions class.");
195 public static boolean sendRoomMessage(@Nullable ThingActions actions, @Nullable String roomId,
196 @Nullable String text, @Nullable String attach) {
197 if (actions instanceof WebexTeamsActions) {
198 return ((WebexTeamsActions) actions).sendRoomMessage(roomId, text, attach);
200 throw new IllegalArgumentException("Instance is not a WebexTeamsActions class.");
204 public static boolean sendPersonMessage(@Nullable ThingActions actions, @Nullable String personEmail,
205 @Nullable String text) {
206 if (actions instanceof WebexTeamsActions) {
207 return ((WebexTeamsActions) actions).sendPersonMessage(personEmail, text);
209 throw new IllegalArgumentException("Instance is not a WebexTeamsActions class.");
213 public static boolean sendPersonMessage(@Nullable ThingActions actions, @Nullable String personEmail,
214 @Nullable String text, @Nullable String attach) {
215 if (actions instanceof WebexTeamsActions) {
216 return ((WebexTeamsActions) actions).sendPersonMessage(personEmail, text, attach);
218 throw new IllegalArgumentException("Instance is not a WebexTeamsActions class.");
223 public void setThingHandler(@Nullable ThingHandler handler) {
224 if (handler instanceof WebexTeamsHandler) {
225 this.handler = (WebexTeamsHandler) handler;
230 public @Nullable ThingHandler getThingHandler() {