Skip to content

Commit

Permalink
[telegram] Add missing @ActionOutput annotation (openhab#17505)
Browse files Browse the repository at this point in the history
Also fix the methods sendTelegramAnimation for DSL rules that were calling sendTelegramVideo actions.

Related to openhab#17504

Signed-off-by: Laurent Garnier <[email protected]>
  • Loading branch information
lolodomo authored and joni1993 committed Oct 15, 2024
1 parent f6fe51c commit e58c227
Showing 1 changed file with 41 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.eclipse.jetty.http.HttpMethod;
import org.openhab.binding.telegram.internal.TelegramHandler;
import org.openhab.core.automation.annotation.ActionInput;
import org.openhab.core.automation.annotation.ActionOutput;
import org.openhab.core.automation.annotation.RuleAction;
import org.openhab.core.thing.binding.ThingActions;
import org.openhab.core.thing.binding.ThingActionsScope;
Expand Down Expand Up @@ -110,7 +111,8 @@ public String toString() {
}

@RuleAction(label = "send an answer", description = "Send a Telegram answer using the Telegram API.")
public boolean sendTelegramAnswer(@ActionInput(name = "chatId") @Nullable Long chatId,
public @ActionOutput(name = "success", type = "java.lang.Boolean") boolean sendTelegramAnswer(
@ActionInput(name = "chatId") @Nullable Long chatId,
@ActionInput(name = "callbackId") @Nullable String callbackId,
@ActionInput(name = "messageId") @Nullable Long messageId,
@ActionInput(name = "message") @Nullable String message) {
Expand Down Expand Up @@ -147,7 +149,8 @@ public boolean sendTelegramAnswer(@ActionInput(name = "chatId") @Nullable Long c
}

@RuleAction(label = "send an answer", description = "Send a Telegram answer using the Telegram API.")
public boolean sendTelegramAnswer(@ActionInput(name = "chatId") @Nullable Long chatId,
public @ActionOutput(name = "success", type = "java.lang.Boolean") boolean sendTelegramAnswer(
@ActionInput(name = "chatId") @Nullable Long chatId,
@ActionInput(name = "replyId") @Nullable String replyId,
@ActionInput(name = "message") @Nullable String message) {
if (replyId == null) {
Expand All @@ -174,7 +177,8 @@ public boolean sendTelegramAnswer(@ActionInput(name = "chatId") @Nullable Long c
}

@RuleAction(label = "send an answer", description = "Send a Telegram answer using the Telegram API.")
public boolean sendTelegramAnswer(@ActionInput(name = "replyId") @Nullable String replyId,
public @ActionOutput(name = "success", type = "java.lang.Boolean") boolean sendTelegramAnswer(
@ActionInput(name = "replyId") @Nullable String replyId,
@ActionInput(name = "message") @Nullable String message) {
TelegramHandler localHandler = handler;
if (localHandler != null) {
Expand All @@ -188,13 +192,15 @@ public boolean sendTelegramAnswer(@ActionInput(name = "replyId") @Nullable Strin
}

@RuleAction(label = "send a message", description = "Send a Telegram message using the Telegram API.")
public boolean sendTelegram(@ActionInput(name = "chatId") @Nullable Long chatId,
public @ActionOutput(name = "success", type = "java.lang.Boolean") boolean sendTelegram(
@ActionInput(name = "chatId") @Nullable Long chatId,
@ActionInput(name = "message") @Nullable String message) {
return sendTelegramGeneral(chatId, message, (String) null);
}

@RuleAction(label = "send a message", description = "Send a Telegram message using the Telegram API.")
public boolean sendTelegram(@ActionInput(name = "message") @Nullable String message) {
public @ActionOutput(name = "success", type = "java.lang.Boolean") boolean sendTelegram(
@ActionInput(name = "message") @Nullable String message) {
TelegramHandler localHandler = handler;
if (localHandler != null) {
for (Long chatId : localHandler.getReceiverChatIds()) {
Expand All @@ -207,15 +213,17 @@ public boolean sendTelegram(@ActionInput(name = "message") @Nullable String mess
}

@RuleAction(label = "send a query", description = "Send a Telegram Query using the Telegram API.")
public boolean sendTelegramQuery(@ActionInput(name = "chatId") @Nullable Long chatId,
public @ActionOutput(name = "success", type = "java.lang.Boolean") boolean sendTelegramQuery(
@ActionInput(name = "chatId") @Nullable Long chatId,
@ActionInput(name = "message") @Nullable String message,
@ActionInput(name = "replyId") @Nullable String replyId,
@ActionInput(name = "buttons") @Nullable String... buttons) {
return sendTelegramGeneral(chatId, message, replyId, buttons);
}

@RuleAction(label = "send a query", description = "Send a Telegram Query using the Telegram API.")
public boolean sendTelegramQuery(@ActionInput(name = "message") @Nullable String message,
public @ActionOutput(name = "success", type = "java.lang.Boolean") boolean sendTelegramQuery(
@ActionInput(name = "message") @Nullable String message,
@ActionInput(name = "replyId") @Nullable String replyId,
@ActionInput(name = "buttons") @Nullable String... buttons) {
TelegramHandler localHandler = handler;
Expand All @@ -229,8 +237,8 @@ public boolean sendTelegramQuery(@ActionInput(name = "message") @Nullable String
return true;
}

private boolean sendTelegramGeneral(@ActionInput(name = "chatId") @Nullable Long chatId, @Nullable String message,
@Nullable String replyId, @Nullable String... buttons) {
private boolean sendTelegramGeneral(@Nullable Long chatId, @Nullable String message, @Nullable String replyId,
@Nullable String... buttons) {
if (message == null) {
logger.warn("Message not defined; action skipped.");
return false;
Expand Down Expand Up @@ -285,7 +293,8 @@ private boolean sendTelegramGeneral(@ActionInput(name = "chatId") @Nullable Long
}

@RuleAction(label = "delete a query", description = "Delete a Query using the Telegram API.")
public boolean deleteTelegramQuery(@ActionInput(name = "replyId") @Nullable String replyId) {
public @ActionOutput(name = "success", type = "java.lang.Boolean") boolean deleteTelegramQuery(
@ActionInput(name = "replyId") @Nullable String replyId) {
if (replyId == null) {
logger.warn("deleteTelegramQuery() - replyId not passed!");
return false;
Expand Down Expand Up @@ -318,7 +327,8 @@ public boolean deleteTelegramQuery(@ActionInput(name = "replyId") @Nullable Stri
} // public boolean deleteTelegramQuery(String replyId)

@RuleAction(label = "send a message", description = "Send a Telegram using the Telegram API.")
public boolean sendTelegram(@ActionInput(name = "chatId") @Nullable Long chatId,
public @ActionOutput(name = "success", type = "java.lang.Boolean") boolean sendTelegram(
@ActionInput(name = "chatId") @Nullable Long chatId,
@ActionInput(name = "message") @Nullable String message,
@ActionInput(name = "args") @Nullable Object... args) {
if (message == null) {
Expand All @@ -328,7 +338,8 @@ public boolean sendTelegram(@ActionInput(name = "chatId") @Nullable Long chatId,
}

@RuleAction(label = "send a message", description = "Send a Telegram using the Telegram API.")
public boolean sendTelegram(@ActionInput(name = "message") @Nullable String message,
public @ActionOutput(name = "success", type = "java.lang.Boolean") boolean sendTelegram(
@ActionInput(name = "message") @Nullable String message,
@ActionInput(name = "args") @Nullable Object... args) {
TelegramHandler localHandler = handler;
if (localHandler != null) {
Expand All @@ -342,14 +353,16 @@ public boolean sendTelegram(@ActionInput(name = "message") @Nullable String mess
}

@RuleAction(label = "send a photo", description = "Send a picture using the Telegram API.")
public boolean sendTelegramPhoto(@ActionInput(name = "chatId") @Nullable Long chatId,
public @ActionOutput(name = "success", type = "java.lang.Boolean") boolean sendTelegramPhoto(
@ActionInput(name = "chatId") @Nullable Long chatId,
@ActionInput(name = "photoURL") @Nullable String photoURL,
@ActionInput(name = "caption") @Nullable String caption) {
return sendTelegramPhoto(chatId, photoURL, caption, null, null);
}

@RuleAction(label = "send a photo", description = "Send a picture using the Telegram API.")
public boolean sendTelegramPhoto(@ActionInput(name = "chatId") @Nullable Long chatId,
public @ActionOutput(name = "success", type = "java.lang.Boolean") boolean sendTelegramPhoto(
@ActionInput(name = "chatId") @Nullable Long chatId,
@ActionInput(name = "photoURL") @Nullable String photoURL,
@ActionInput(name = "caption") @Nullable String caption,
@ActionInput(name = "username") @Nullable String username,
Expand Down Expand Up @@ -452,7 +465,8 @@ public boolean sendTelegramPhoto(@ActionInput(name = "chatId") @Nullable Long ch
}

@RuleAction(label = "send a photo", description = "Send a Picture using the Telegram API.")
public boolean sendTelegramPhoto(@ActionInput(name = "photoURL") @Nullable String photoURL,
public @ActionOutput(name = "success", type = "java.lang.Boolean") boolean sendTelegramPhoto(
@ActionInput(name = "photoURL") @Nullable String photoURL,
@ActionInput(name = "caption") @Nullable String caption,
@ActionInput(name = "username") @Nullable String username,
@ActionInput(name = "password") @Nullable String password) {
Expand All @@ -468,13 +482,15 @@ public boolean sendTelegramPhoto(@ActionInput(name = "photoURL") @Nullable Strin
}

@RuleAction(label = "send a photo", description = "Send a Picture using the Telegram API.")
public boolean sendTelegramPhoto(@ActionInput(name = "photoURL") @Nullable String photoURL,
public @ActionOutput(name = "success", type = "java.lang.Boolean") boolean sendTelegramPhoto(
@ActionInput(name = "photoURL") @Nullable String photoURL,
@ActionInput(name = "caption") @Nullable String caption) {
return sendTelegramPhoto(photoURL, caption, null, null);
}

@RuleAction(label = "send animation", description = "Send an Animation using the Telegram API.")
public boolean sendTelegramAnimation(@ActionInput(name = "animationURL") @Nullable String animationURL,
public @ActionOutput(name = "success", type = "java.lang.Boolean") boolean sendTelegramAnimation(
@ActionInput(name = "animationURL") @Nullable String animationURL,
@ActionInput(name = "caption") @Nullable String caption) {
TelegramHandler localHandler = handler;
if (localHandler != null) {
Expand All @@ -488,7 +504,8 @@ public boolean sendTelegramAnimation(@ActionInput(name = "animationURL") @Nullab
}

@RuleAction(label = "send animation", description = "Send an Animation using the Telegram API.")
public boolean sendTelegramAnimation(@ActionInput(name = "chatId") @Nullable Long chatId,
public @ActionOutput(name = "success", type = "java.lang.Boolean") boolean sendTelegramAnimation(
@ActionInput(name = "chatId") @Nullable Long chatId,
@ActionInput(name = "animationURL") @Nullable String animationURL,
@ActionInput(name = "caption") @Nullable String caption) {
if (animationURL == null) {
Expand Down Expand Up @@ -554,7 +571,8 @@ public boolean sendTelegramAnimation(@ActionInput(name = "chatId") @Nullable Lon
}

@RuleAction(label = "send video", description = "Send a Video using the Telegram API.")
public boolean sendTelegramVideo(@ActionInput(name = "videoURL") @Nullable String videoURL,
public @ActionOutput(name = "success", type = "java.lang.Boolean") boolean sendTelegramVideo(
@ActionInput(name = "videoURL") @Nullable String videoURL,
@ActionInput(name = "caption") @Nullable String caption) {
TelegramHandler localHandler = handler;
if (localHandler != null) {
Expand All @@ -568,7 +586,8 @@ public boolean sendTelegramVideo(@ActionInput(name = "videoURL") @Nullable Strin
}

@RuleAction(label = "send video", description = "Send a Video using the Telegram API.")
public boolean sendTelegramVideo(@ActionInput(name = "chatId") @Nullable Long chatId,
public @ActionOutput(name = "success", type = "java.lang.Boolean") boolean sendTelegramVideo(
@ActionInput(name = "chatId") @Nullable Long chatId,
@ActionInput(name = "videoURL") @Nullable String videoURL,
@ActionInput(name = "caption") @Nullable String caption) {
final SendVideo sendVideo;
Expand Down Expand Up @@ -659,7 +678,7 @@ public static boolean sendTelegramPhoto(ThingActions actions, @Nullable String p

public static boolean sendTelegramAnimation(ThingActions actions, @Nullable String animationURL,
@Nullable String caption) {
return ((TelegramActions) actions).sendTelegramVideo(animationURL, caption);
return ((TelegramActions) actions).sendTelegramAnimation(animationURL, caption);
}

public static boolean sendTelegramVideo(ThingActions actions, @Nullable String videoURL, @Nullable String caption) {
Expand Down Expand Up @@ -702,7 +721,7 @@ public static boolean sendTelegramPhoto(ThingActions actions, @Nullable Long cha

public static boolean sendTelegramAnimation(ThingActions actions, @Nullable Long chatId,
@Nullable String animationURL, @Nullable String caption) {
return ((TelegramActions) actions).sendTelegramVideo(chatId, animationURL, caption);
return ((TelegramActions) actions).sendTelegramAnimation(chatId, animationURL, caption);
}

public static boolean sendTelegramVideo(ThingActions actions, @Nullable Long chatId, @Nullable String videoURL,
Expand Down

0 comments on commit e58c227

Please sign in to comment.