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.telegram.internal.action;
15 import static org.openhab.binding.telegram.internal.TelegramBindingConstants.PHOTO_EXTENSIONS;
17 import java.io.ByteArrayInputStream;
18 import java.io.IOException;
19 import java.io.InputStream;
20 import java.net.MalformedURLException;
23 import java.nio.charset.StandardCharsets;
24 import java.nio.file.Path;
25 import java.util.Base64;
26 import java.util.concurrent.ExecutionException;
27 import java.util.concurrent.TimeUnit;
29 import org.eclipse.jdt.annotation.NonNullByDefault;
30 import org.eclipse.jdt.annotation.Nullable;
31 import org.eclipse.jetty.client.HttpClient;
32 import org.eclipse.jetty.client.api.Authentication;
33 import org.eclipse.jetty.client.api.AuthenticationStore;
34 import org.eclipse.jetty.client.api.ContentResponse;
35 import org.eclipse.jetty.client.api.Request;
36 import org.eclipse.jetty.client.util.FutureResponseListener;
37 import org.eclipse.jetty.http.HttpHeader;
38 import org.eclipse.jetty.http.HttpMethod;
39 import org.openhab.binding.telegram.internal.TelegramHandler;
40 import org.openhab.core.automation.annotation.ActionInput;
41 import org.openhab.core.automation.annotation.RuleAction;
42 import org.openhab.core.thing.binding.ThingActions;
43 import org.openhab.core.thing.binding.ThingActionsScope;
44 import org.openhab.core.thing.binding.ThingHandler;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
48 import com.pengrad.telegrambot.model.request.InlineKeyboardButton;
49 import com.pengrad.telegrambot.model.request.InlineKeyboardMarkup;
50 import com.pengrad.telegrambot.request.AnswerCallbackQuery;
51 import com.pengrad.telegrambot.request.EditMessageReplyMarkup;
52 import com.pengrad.telegrambot.request.SendAnimation;
53 import com.pengrad.telegrambot.request.SendMessage;
54 import com.pengrad.telegrambot.request.SendPhoto;
55 import com.pengrad.telegrambot.request.SendVideo;
56 import com.pengrad.telegrambot.response.BaseResponse;
57 import com.pengrad.telegrambot.response.SendResponse;
60 * Provides the actions for the Telegram API.
62 * @author Alexander Krasnogolowy - Initial contribution
64 @ThingActionsScope(name = "telegram")
66 public class TelegramActions implements ThingActions {
67 private final Logger logger = LoggerFactory.getLogger(TelegramActions.class);
68 private @Nullable TelegramHandler handler;
70 private boolean evaluateResponse(@Nullable BaseResponse response) {
71 if (response != null && !response.isOk()) {
72 logger.warn("Failed to send telegram message: {}", response.description());
78 private static class BasicResult implements Authentication.Result {
80 private final HttpHeader header;
81 private final URI uri;
82 private final String value;
84 public BasicResult(HttpHeader header, URI uri, String value) {
96 public void apply(@Nullable Request request) {
97 if (request != null) {
98 request.header(this.header, this.value);
103 public String toString() {
104 return String.format("Basic authentication result for %s", this.uri);
108 @RuleAction(label = "send an answer", description = "Send a Telegram answer using the Telegram API.")
109 public boolean sendTelegramAnswer(@ActionInput(name = "chatId") @Nullable Long chatId,
110 @ActionInput(name = "callbackId") @Nullable String callbackId,
111 @ActionInput(name = "messageId") @Nullable Long messageId,
112 @ActionInput(name = "message") @Nullable String message) {
113 if (chatId == null) {
114 logger.warn("chatId not defined; action skipped.");
117 if (messageId == null) {
118 logger.warn("messageId not defined; action skipped.");
121 TelegramHandler localHandler = handler;
122 if (localHandler != null) {
123 if (callbackId != null) {
124 AnswerCallbackQuery answerCallbackQuery = new AnswerCallbackQuery(callbackId);
125 // we could directly set the text here, but this
126 // doesn't result in a real message only in a
127 // little popup or in an alert, so the only purpose
128 // is to stop the progress bar on client side
129 logger.debug("Answering query with callbackId '{}'", callbackId);
130 if (!evaluateResponse(localHandler.execute(answerCallbackQuery))) {
134 EditMessageReplyMarkup editReplyMarkup = new EditMessageReplyMarkup(chatId, messageId.intValue())
135 .replyMarkup(new InlineKeyboardMarkup(new InlineKeyboardButton[0]));// remove reply markup from
137 if (!evaluateResponse(localHandler.execute(editReplyMarkup))) {
140 return message != null ? sendTelegram(chatId, message) : true;
145 @RuleAction(label = "send an answer", description = "Send a Telegram answer using the Telegram API.")
146 public boolean sendTelegramAnswer(@ActionInput(name = "chatId") @Nullable Long chatId,
147 @ActionInput(name = "replyId") @Nullable String replyId,
148 @ActionInput(name = "message") @Nullable String message) {
149 if (replyId == null) {
150 logger.warn("ReplyId not defined; action skipped.");
153 if (chatId == null) {
154 logger.warn("chatId not defined; action skipped.");
157 TelegramHandler localHandler = handler;
158 if (localHandler != null) {
159 String callbackId = localHandler.getCallbackId(chatId, replyId);
160 if (callbackId != null) {
161 logger.debug("AnswerCallbackQuery for chatId {} and replyId {} is the callbackId {}", chatId, replyId,
164 Integer messageId = localHandler.removeMessageId(chatId, replyId);
165 logger.debug("remove messageId {} for chatId {} and replyId {}", messageId, chatId, replyId);
167 return sendTelegramAnswer(chatId, callbackId, messageId != null ? Long.valueOf(messageId) : null, message);
172 @RuleAction(label = "send an answer", description = "Send a Telegram answer using the Telegram API.")
173 public boolean sendTelegramAnswer(@ActionInput(name = "replyId") @Nullable String replyId,
174 @ActionInput(name = "message") @Nullable String message) {
175 TelegramHandler localHandler = handler;
176 if (localHandler != null) {
177 for (Long chatId : localHandler.getReceiverChatIds()) {
178 if (!sendTelegramAnswer(chatId, replyId, message)) {
186 @RuleAction(label = "send a message", description = "Send a Telegram message using the Telegram API.")
187 public boolean sendTelegram(@ActionInput(name = "chatId") @Nullable Long chatId,
188 @ActionInput(name = "message") @Nullable String message) {
189 return sendTelegramGeneral(chatId, message, (String) null);
192 @RuleAction(label = "send a message", description = "Send a Telegram message using the Telegram API.")
193 public boolean sendTelegram(@ActionInput(name = "message") @Nullable String message) {
194 TelegramHandler localHandler = handler;
195 if (localHandler != null) {
196 for (Long chatId : localHandler.getReceiverChatIds()) {
197 if (!sendTelegram(chatId, message)) {
205 @RuleAction(label = "send a message", description = "Send a Telegram using the Telegram API.")
206 public boolean sendTelegramQuery(@ActionInput(name = "chatId") @Nullable Long chatId,
207 @ActionInput(name = "message") @Nullable String message,
208 @ActionInput(name = "replyId") @Nullable String replyId,
209 @ActionInput(name = "buttons") @Nullable String... buttons) {
210 return sendTelegramGeneral(chatId, message, replyId, buttons);
213 @RuleAction(label = "send a message", description = "Send a Telegram using the Telegram API.")
214 public boolean sendTelegramQuery(@ActionInput(name = "message") @Nullable String message,
215 @ActionInput(name = "replyId") @Nullable String replyId,
216 @ActionInput(name = "buttons") @Nullable String... buttons) {
217 TelegramHandler localHandler = handler;
218 if (localHandler != null) {
219 for (Long chatId : localHandler.getReceiverChatIds()) {
220 if (!sendTelegramQuery(chatId, message, replyId, buttons)) {
228 private boolean sendTelegramGeneral(@ActionInput(name = "chatId") @Nullable Long chatId, @Nullable String message,
229 @Nullable String replyId, @Nullable String... buttons) {
230 if (message == null) {
231 logger.warn("Message not defined; action skipped.");
234 if (chatId == null) {
235 logger.warn("chatId not defined; action skipped.");
238 TelegramHandler localHandler = handler;
239 if (localHandler != null) {
240 SendMessage sendMessage = new SendMessage(chatId, message);
241 if (localHandler.getParseMode() != null) {
242 sendMessage.parseMode(localHandler.getParseMode());
244 if (replyId != null) {
245 if (!replyId.contains(" ")) {
246 if (buttons.length > 0) {
247 InlineKeyboardButton[][] keyboard2D = new InlineKeyboardButton[1][];
248 InlineKeyboardButton[] keyboard = new InlineKeyboardButton[buttons.length];
249 keyboard2D[0] = keyboard;
250 for (int i = 0; i < buttons.length; i++) {
251 keyboard[i] = new InlineKeyboardButton(buttons[i]).callbackData(replyId + " " + buttons[i]);
253 InlineKeyboardMarkup keyBoardMarkup = new InlineKeyboardMarkup(keyboard2D);
254 sendMessage.replyMarkup(keyBoardMarkup);
257 "The replyId {} for message {} is given, but no buttons are defined. ReplyMarkup will be ignored.",
261 logger.warn("replyId {} must not contain spaces. ReplyMarkup will be ignored.", replyId);
264 SendResponse retMessage = null;
266 retMessage = localHandler.execute(sendMessage);
267 } catch (Exception e) {
268 logger.warn("Exception occured whilst sending message:{}", e.getMessage());
270 if (!evaluateResponse(retMessage)) {
273 if (replyId != null && retMessage != null) {
274 logger.debug("Adding chatId {}, replyId {} and messageId {}", chatId, replyId,
275 retMessage.message().messageId());
276 localHandler.addMessageId(chatId, replyId, retMessage.message().messageId());
283 @RuleAction(label = "send a message", description = "Send a Telegram using the Telegram API.")
284 public boolean sendTelegram(@ActionInput(name = "chatId") @Nullable Long chatId,
285 @ActionInput(name = "message") @Nullable String message,
286 @ActionInput(name = "args") @Nullable Object... args) {
287 if (message == null) {
290 return sendTelegram(chatId, String.format(message, args));
293 @RuleAction(label = "send a message", description = "Send a Telegram using the Telegram API.")
294 public boolean sendTelegram(@ActionInput(name = "message") @Nullable String message,
295 @ActionInput(name = "args") @Nullable Object... args) {
296 TelegramHandler localHandler = handler;
297 if (localHandler != null) {
298 for (Long chatId : localHandler.getReceiverChatIds()) {
299 if (!sendTelegram(chatId, message, args)) {
307 @RuleAction(label = "send a photo", description = "Send a picture using the Telegram API.")
308 public boolean sendTelegramPhoto(@ActionInput(name = "chatId") @Nullable Long chatId,
309 @ActionInput(name = "photoURL") @Nullable String photoURL,
310 @ActionInput(name = "caption") @Nullable String caption) {
311 return sendTelegramPhoto(chatId, photoURL, caption, null, null);
314 @RuleAction(label = "send a photo", description = "Send a picture using the Telegram API.")
315 public boolean sendTelegramPhoto(@ActionInput(name = "chatId") @Nullable Long chatId,
316 @ActionInput(name = "photoURL") @Nullable String photoURL,
317 @ActionInput(name = "caption") @Nullable String caption,
318 @ActionInput(name = "username") @Nullable String username,
319 @ActionInput(name = "password") @Nullable String password) {
320 if (photoURL == null) {
321 logger.warn("Photo URL not defined; unable to retrieve photo for sending.");
324 if (chatId == null) {
325 logger.warn("chatId not defined; action skipped.");
328 String lowercasePhotoUrl = photoURL.toLowerCase();
329 TelegramHandler localHandler = handler;
330 if (localHandler != null) {
331 final SendPhoto sendPhoto;
332 if (lowercasePhotoUrl.startsWith("http")) {
333 logger.debug("Http based URL for photo provided.");
334 HttpClient client = localHandler.getClient();
335 if (client == null) {
338 Request request = client.newRequest(photoURL).method(HttpMethod.GET).timeout(30, TimeUnit.SECONDS);
339 if (username != null && password != null) {
340 AuthenticationStore auth = client.getAuthenticationStore();
341 URI uri = URI.create(photoURL);
342 auth.addAuthenticationResult(
343 new BasicResult(HttpHeader.AUTHORIZATION, uri, "Basic " + Base64.getEncoder()
344 .encodeToString((username + ":" + password).getBytes(StandardCharsets.UTF_8))));
347 // API has 10mb limit to jpg file size, without this it can only accept 2mb
348 FutureResponseListener listener = new FutureResponseListener(request, 10 * 1024 * 1024);
349 request.send(listener);
350 ContentResponse contentResponse = listener.get();
351 if (contentResponse.getStatus() == 200) {
352 byte[] fileContent = contentResponse.getContent();
353 sendPhoto = new SendPhoto(chatId, fileContent);
355 logger.warn("Download from {} failed with status: {}", photoURL, contentResponse.getStatus());
356 sendTelegram(chatId, caption + ":Download failed with status " + contentResponse.getStatus());
359 } catch (InterruptedException | ExecutionException e) {
360 logger.warn("Download from {} failed with exception: {}", photoURL, e.getMessage());
363 } else if (lowercasePhotoUrl.startsWith("file:")
364 || PHOTO_EXTENSIONS.stream().anyMatch(lowercasePhotoUrl::endsWith)) {
365 logger.debug("Read file from local file system: {}", photoURL);
366 String temp = photoURL;
367 if (!lowercasePhotoUrl.startsWith("file:")) {
368 temp = "file://" + photoURL;
371 sendPhoto = new SendPhoto(chatId, Path.of(new URL(temp).getPath()).toFile());
372 } catch (MalformedURLException e) {
373 logger.warn("Malformed URL: {}", photoURL);
377 logger.debug("Base64 image provided; converting to binary.");
378 final String photoB64Data;
379 if (photoURL.startsWith("data:")) { // support data URI scheme
380 String[] photoURLParts = photoURL.split(",");
381 if (photoURLParts.length > 1) {
382 photoB64Data = photoURLParts[1];
384 logger.warn("The provided base64 string is not a valid data URI scheme");
388 photoB64Data = photoURL;
390 InputStream is = Base64.getDecoder()
391 .wrap(new ByteArrayInputStream(photoB64Data.getBytes(StandardCharsets.UTF_8)));
393 byte[] photoBytes = is.readAllBytes();
394 sendPhoto = new SendPhoto(chatId, photoBytes);
395 } catch (IOException e) {
396 logger.warn("Malformed base64 string: {}", e.getMessage());
400 if (caption != null) {
401 sendPhoto.caption(caption);
403 if (localHandler.getParseMode() != null) {
404 sendPhoto.parseMode(localHandler.getParseMode());
406 return evaluateResponse(localHandler.execute(sendPhoto));
411 @RuleAction(label = "send a photo", description = "Send a Picture using the Telegram API.")
412 public boolean sendTelegramPhoto(@ActionInput(name = "photoURL") @Nullable String photoURL,
413 @ActionInput(name = "caption") @Nullable String caption,
414 @ActionInput(name = "username") @Nullable String username,
415 @ActionInput(name = "password") @Nullable String password) {
416 TelegramHandler localHandler = handler;
417 if (localHandler != null) {
418 for (Long chatId : localHandler.getReceiverChatIds()) {
419 if (!sendTelegramPhoto(chatId, photoURL, caption, username, password)) {
427 @RuleAction(label = "send a photo", description = "Send a Picture using the Telegram API.")
428 public boolean sendTelegramPhoto(@ActionInput(name = "photoURL") @Nullable String photoURL,
429 @ActionInput(name = "caption") @Nullable String caption) {
430 return sendTelegramPhoto(photoURL, caption, null, null);
433 @RuleAction(label = "send animation", description = "Send an Animation using the Telegram API.")
434 public boolean sendTelegramAnimation(@ActionInput(name = "animationURL") @Nullable String animationURL,
435 @ActionInput(name = "caption") @Nullable String caption) {
436 TelegramHandler localHandler = handler;
437 if (localHandler != null) {
438 for (Long chatId : localHandler.getReceiverChatIds()) {
439 if (!sendTelegramAnimation(chatId, animationURL, caption)) {
447 @RuleAction(label = "send animation", description = "Send an Animation using the Telegram API.")
448 public boolean sendTelegramAnimation(@ActionInput(name = "chatId") @Nullable Long chatId,
449 @ActionInput(name = "animationURL") @Nullable String animationURL,
450 @ActionInput(name = "caption") @Nullable String caption) {
451 if (animationURL == null) {
452 logger.warn("Animation URL not defined; unable to retrieve video for sending.");
455 if (chatId == null) {
456 logger.warn("chatId not defined; action skipped.");
459 TelegramHandler localHandler = handler;
460 if (localHandler != null) {
461 final SendAnimation sendAnimation;
462 if (animationURL.toLowerCase().startsWith("http")) {
463 // load image from url
464 logger.debug("Animation URL provided.");
465 HttpClient client = localHandler.getClient();
466 if (client == null) {
469 Request request = client.newRequest(animationURL).method(HttpMethod.GET).timeout(30, TimeUnit.SECONDS);
471 // 50mb limit to file size
472 FutureResponseListener listener = new FutureResponseListener(request, 50 * 1024 * 1024);
473 request.send(listener);
474 ContentResponse contentResponse = listener.get();
475 if (contentResponse.getStatus() == 200) {
476 byte[] fileContent = contentResponse.getContent();
477 sendAnimation = new SendAnimation(chatId, fileContent);
479 logger.warn("Download from {} failed with status: {}", animationURL,
480 contentResponse.getStatus());
481 sendTelegram(chatId, caption + ":Download failed with status " + contentResponse.getStatus());
484 } catch (InterruptedException | ExecutionException e) {
485 logger.warn("Download from {} failed with exception: {}", animationURL, e.getMessage());
489 String temp = animationURL;
490 if (!animationURL.toLowerCase().startsWith("file:")) {
491 temp = "file://" + animationURL;
493 // Load video from local file system
494 logger.debug("Read file from local file system: {}", animationURL);
496 sendAnimation = new SendAnimation(chatId, Path.of(new URL(temp).getPath()).toFile());
497 } catch (MalformedURLException e) {
498 logger.warn("Malformed URL, should start with http or file: {}", animationURL);
502 if (caption != null) {
503 sendAnimation.caption(caption);
505 if (localHandler.getParseMode() != null) {
506 sendAnimation.parseMode(localHandler.getParseMode());
508 return evaluateResponse(localHandler.execute(sendAnimation));
513 @RuleAction(label = "send video", description = "Send a Video using the Telegram API.")
514 public boolean sendTelegramVideo(@ActionInput(name = "videoURL") @Nullable String videoURL,
515 @ActionInput(name = "caption") @Nullable String caption) {
516 TelegramHandler localHandler = handler;
517 if (localHandler != null) {
518 for (Long chatId : localHandler.getReceiverChatIds()) {
519 if (!sendTelegramVideo(chatId, videoURL, caption)) {
527 @RuleAction(label = "send video", description = "Send a Video using the Telegram API.")
528 public boolean sendTelegramVideo(@ActionInput(name = "chatId") @Nullable Long chatId,
529 @ActionInput(name = "videoURL") @Nullable String videoURL,
530 @ActionInput(name = "caption") @Nullable String caption) {
531 final SendVideo sendVideo;
532 if (videoURL == null) {
533 logger.warn("Video URL not defined; unable to retrieve video for sending.");
536 if (chatId == null) {
537 logger.warn("chatId not defined; action skipped.");
540 TelegramHandler localHandler = handler;
541 if (localHandler != null) {
542 if (videoURL.toLowerCase().startsWith("http")) {
543 logger.debug("Video http://URL provided.");
544 HttpClient client = localHandler.getClient();
545 if (client == null) {
548 Request request = client.newRequest(videoURL).method(HttpMethod.GET).timeout(30, TimeUnit.SECONDS);
550 // 50mb limit to file size
551 FutureResponseListener listener = new FutureResponseListener(request, 50 * 1024 * 1024);
552 request.send(listener);
553 ContentResponse contentResponse = listener.get();
554 if (contentResponse.getStatus() == 200) {
555 byte[] fileContent = contentResponse.getContent();
556 sendVideo = new SendVideo(chatId, fileContent);
558 logger.warn("Download from {} failed with status: {}", videoURL, contentResponse.getStatus());
559 sendTelegram(chatId, caption + ":Download failed with status " + contentResponse.getStatus());
562 } catch (InterruptedException | ExecutionException e) {
563 logger.warn("Download from {} failed with exception: {}", videoURL, e.getMessage());
567 String temp = videoURL;
568 if (!videoURL.toLowerCase().startsWith("file:")) {
569 temp = "file://" + videoURL;
571 // Load video from local file system with file://path
572 logger.debug("Read file from local file: {}", videoURL);
574 sendVideo = new SendVideo(chatId, Path.of(new URL(temp).getPath()).toFile());
575 } catch (MalformedURLException e) {
576 logger.warn("Malformed URL, should start with http or file: {}", videoURL);
580 if (caption != null) {
581 sendVideo.caption(caption);
583 if (localHandler.getParseMode() != null) {
584 sendVideo.parseMode(localHandler.getParseMode());
586 return evaluateResponse(localHandler.execute(sendVideo));
591 // legacy delegate methods
592 /* APIs without chatId parameter */
593 public static boolean sendTelegram(ThingActions actions, @Nullable String format, @Nullable Object... args) {
594 return ((TelegramActions) actions).sendTelegram(format, args);
597 public static boolean sendTelegramQuery(ThingActions actions, @Nullable String message, @Nullable String replyId,
598 @Nullable String... buttons) {
599 return ((TelegramActions) actions).sendTelegramQuery(message, replyId, buttons);
602 public static boolean sendTelegramPhoto(ThingActions actions, @Nullable String photoURL, @Nullable String caption) {
603 return ((TelegramActions) actions).sendTelegramPhoto(photoURL, caption, null, null);
606 public static boolean sendTelegramPhoto(ThingActions actions, @Nullable String photoURL, @Nullable String caption,
607 @Nullable String username, @Nullable String password) {
608 return ((TelegramActions) actions).sendTelegramPhoto(photoURL, caption, username, password);
611 public static boolean sendTelegramAnimation(ThingActions actions, @Nullable String animationURL,
612 @Nullable String caption) {
613 return ((TelegramActions) actions).sendTelegramVideo(animationURL, caption);
616 public static boolean sendTelegramVideo(ThingActions actions, @Nullable String videoURL, @Nullable String caption) {
617 return ((TelegramActions) actions).sendTelegramVideo(videoURL, caption);
620 public static boolean sendTelegramAnswer(ThingActions actions, @Nullable String replyId, @Nullable String message) {
621 return ((TelegramActions) actions).sendTelegramAnswer(replyId, message);
624 /* APIs with chatId parameter */
626 public static boolean sendTelegram(ThingActions actions, @Nullable Long chatId, @Nullable String format,
627 @Nullable Object... args) {
628 return ((TelegramActions) actions).sendTelegram(chatId, format, args);
631 public static boolean sendTelegramQuery(ThingActions actions, @Nullable Long chatId, @Nullable String message,
632 @Nullable String replyId, @Nullable String... buttons) {
633 return ((TelegramActions) actions).sendTelegramQuery(chatId, message, replyId, buttons);
636 public static boolean sendTelegramPhoto(ThingActions actions, @Nullable Long chatId, @Nullable String photoURL,
637 @Nullable String caption) {
638 return ((TelegramActions) actions).sendTelegramPhoto(chatId, photoURL, caption, null, null);
641 public static boolean sendTelegramPhoto(ThingActions actions, @Nullable Long chatId, @Nullable String photoURL,
642 @Nullable String caption, @Nullable String username, @Nullable String password) {
643 return ((TelegramActions) actions).sendTelegramPhoto(chatId, photoURL, caption, username, password);
646 public static boolean sendTelegramAnimation(ThingActions actions, @Nullable Long chatId,
647 @Nullable String animationURL, @Nullable String caption) {
648 return ((TelegramActions) actions).sendTelegramVideo(chatId, animationURL, caption);
651 public static boolean sendTelegramVideo(ThingActions actions, @Nullable Long chatId, @Nullable String videoURL,
652 @Nullable String caption) {
653 return ((TelegramActions) actions).sendTelegramVideo(chatId, videoURL, caption);
656 public static boolean sendTelegramAnswer(ThingActions actions, @Nullable Long chatId, @Nullable String replyId,
657 @Nullable String message) {
658 return ((TelegramActions) actions).sendTelegramAnswer(chatId, replyId, message);
661 public static boolean sendTelegramAnswer(ThingActions actions, @Nullable String chatId, @Nullable String replyId,
662 @Nullable String message) {
663 if (actions instanceof TelegramActions) {
664 if (chatId == null) {
667 return ((TelegramActions) actions).sendTelegramAnswer(Long.valueOf(chatId), replyId, message);
669 throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
673 public static boolean sendTelegramAnswer(ThingActions actions, @Nullable Long chatId, @Nullable String callbackId,
674 @Nullable Long messageId, @Nullable String message) {
675 return ((TelegramActions) actions).sendTelegramAnswer(chatId, callbackId, messageId, message);
678 public static boolean sendTelegramAnswer(ThingActions actions, @Nullable String chatId, @Nullable String callbackId,
679 @Nullable String messageId, @Nullable String message) {
680 if (actions instanceof TelegramActions) {
681 if (chatId == null) {
684 return ((TelegramActions) actions).sendTelegramAnswer(Long.valueOf(chatId), callbackId,
685 messageId != null ? Long.parseLong(messageId) : null, message);
687 throw new IllegalArgumentException("Actions is not an instance of TelegramActions");
692 public void setThingHandler(@Nullable ThingHandler handler) {
693 this.handler = (TelegramHandler) handler;
697 public @Nullable ThingHandler getThingHandler() {