You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/01/02 07:59:04 UTC
[camel] branch master updated: CAMEL-13223: telegram - Implement
methods to update messages (#3455)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 9b7a4a3 CAMEL-13223: telegram - Implement methods to update messages (#3455)
9b7a4a3 is described below
commit 9b7a4a3d08edf7bc58af63bbdd401e72c1d6ccaf
Author: Miguel Caetano Serra <se...@gmail.com>
AuthorDate: Thu Jan 2 07:58:51 2020 +0000
CAMEL-13223: telegram - Implement methods to update messages (#3455)
* CAMEL-13223: Edit message text
* CAMEL-13223: Edit caption text
* CAMEL-13223: Edit media message
* CAMEL-13223: Delete message
* CAMEL-13223: EditMessageReplyMarkup
---
.../src/main/docs/telegram-component.adoc | 5 +
.../telegram/model/EditMessageCaptionMessage.java | 134 +++++++++
...eKeyboardButton.java => EditMessageDelete.java} | 67 ++---
.../telegram/model/EditMessageMediaMessage.java | 120 ++++++++
.../model/EditMessageReplyMarkupMessage.java | 111 ++++++++
.../telegram/model/EditMessageTextMessage.java | 149 ++++++++++
.../component/telegram/model/IncomingMessage.java | 46 +++
.../telegram/model/IncomingMessageEntity.java | 90 ++++++
.../telegram/model/InlineKeyboardButton.java | 114 +++++++-
.../telegram/model/InlineKeyboardMarkup.java | 88 ++++++
.../camel/component/telegram/model/InputMedia.java | 83 ++++++
.../telegram/model/InputMediaAnimation.java | 82 ++++++
.../component/telegram/model/InputMediaAudio.java | 82 ++++++
...ineKeyboardButton.java => InputMediaPhoto.java} | 67 ++---
.../component/telegram/model/InputMediaVideo.java | 96 +++++++
.../camel/component/telegram/model/LoginUrl.java | 122 ++++++++
.../component/telegram/model/MessageResult.java | 24 +-
.../service/TelegramServiceRestBotAPIAdapter.java | 23 +-
.../telegram/integration/TelegramServiceTest.java | 312 ++++++++++++++++++++-
19 files changed, 1691 insertions(+), 124 deletions(-)
diff --git a/components/camel-telegram/src/main/docs/telegram-component.adoc b/components/camel-telegram/src/main/docs/telegram-component.adoc
index b03a054..bf0291d 100644
--- a/components/camel-telegram/src/main/docs/telegram-component.adoc
+++ b/components/camel-telegram/src/main/docs/telegram-component.adoc
@@ -227,6 +227,11 @@ The following message bodies are allowed for a producer endpoint (messages of ty
| `OutgoingVideoMessage` | To send a mp4 video to a chat
| `OutgoingDocumentMessage` | To send a file to a chat (any media type)
| `OutgoingStickerMessage` | To send a sticker to a chat (WEBP)
+| `EditMessageTextMessage` | To edit text and game messages (editMessageText)
+| `EditMessageCaptionMessage` | To edit captions of messages (editMessageCaption)
+| `EditMessageMediaMessage` | To edit animation, audio, document, photo, or video messages. (editMessageMedia)
+| `EditMessageReplyMarkupMessage` | To edit only the reply markup of message. (editMessageReplyMarkup)
+| `EditMessageDelete` | To delete a message, including service messages. (deleteMessage)
| `SendLocationMessage` | To send a location (setSendLocation)
| `EditMessageLiveLocationMessage` | To send changes to a live location (editMessageLiveLocation)
| `StopMessageLiveLocationMessage` | To stop updating a live location message sent by the bot or via the bot (for inline bots) before live_period expires (stopMessageLiveLocation)
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/EditMessageCaptionMessage.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/EditMessageCaptionMessage.java
new file mode 100644
index 0000000..a88e03e
--- /dev/null
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/EditMessageCaptionMessage.java
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.telegram.model;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Message to edit captions of messages.
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class EditMessageCaptionMessage extends OutgoingMessage {
+
+ @JsonProperty("message_id")
+ private Integer messageId;
+
+ @JsonProperty("inline_message_id")
+ private String inlineMessageId;
+
+ private String caption;
+
+ @JsonProperty("parse_mode")
+ private String parseMode;
+
+ @JsonProperty("reply_markup")
+ private InlineKeyboardMarkup replyMarkup;
+
+ /**
+ * Builds {@link EditMessageCaptionMessage} instance.
+ *
+ * @param chatId Unique identifier for the target chat or username of the target channel.
+ * @param messageId Identifier of the message to edit. Required if inline_message_id is not specified.
+ * @param inlineMessageId Required if chat_id and message_id are not specified.
+ * Identifier of the inline message.
+ * @param caption New caption of the message.
+ * @param parseMode Send Markdown or HTML, if you want Telegram apps to show bold, italic,
+ * fixed-width text or inline URLs in your bot's message.
+ * @param replyMarkup An inline keyboard that appears right next to the message it belongs to.
+ */
+ public EditMessageCaptionMessage(String chatId, Integer messageId, String inlineMessageId, String caption,
+ String parseMode, InlineKeyboardMarkup replyMarkup) {
+ this.chatId = chatId;
+ this.messageId = messageId;
+ this.inlineMessageId = inlineMessageId;
+ this.caption = caption;
+ this.parseMode = parseMode;
+ this.replyMarkup = replyMarkup;
+ }
+
+ public Integer getMessageId() {
+ return messageId;
+ }
+
+ public String getInlineMessageId() {
+ return inlineMessageId;
+ }
+
+ public String getCaption() {
+ return caption;
+ }
+
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public InlineKeyboardMarkup getReplyMarkup() {
+ return replyMarkup;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static final class Builder {
+ protected String chatId;
+ private Integer messageId;
+ private String inlineMessageId;
+ private String caption;
+ private String parseMode;
+ private InlineKeyboardMarkup replyMarkup;
+
+ private Builder() {
+ }
+
+ public Builder messageId(Integer messageId) {
+ this.messageId = messageId;
+ return this;
+ }
+
+ public Builder inlineMessageId(String inlineMessageId) {
+ this.inlineMessageId = inlineMessageId;
+ return this;
+ }
+
+ public Builder caption(String caption) {
+ this.caption = caption;
+ return this;
+ }
+
+ public Builder parseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
+ }
+
+ public Builder replyMarkup(InlineKeyboardMarkup replyMarkup) {
+ this.replyMarkup = replyMarkup;
+ return this;
+ }
+
+ public Builder chatId(String chatId) {
+ this.chatId = chatId;
+ return this;
+ }
+
+ public EditMessageCaptionMessage build() {
+ return new EditMessageCaptionMessage(
+ chatId, messageId, inlineMessageId, caption, parseMode, replyMarkup);
+ }
+ }
+}
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InlineKeyboardButton.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/EditMessageDelete.java
similarity index 54%
copy from components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InlineKeyboardButton.java
copy to components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/EditMessageDelete.java
index 0378d60..fcd7c2f 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InlineKeyboardButton.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/EditMessageDelete.java
@@ -17,56 +17,37 @@
package org.apache.camel.component.telegram.model;
import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+/**
+ * Message to delete a message, including service messages.
+ */
@JsonInclude(JsonInclude.Include.NON_NULL)
-public class InlineKeyboardButton {
-
- private String text;
-
- public InlineKeyboardButton() {
-
- }
-
- public InlineKeyboardButton(String text) {
-
- this.text = text;
- }
-
- public String getText() {
-
- return text;
+public class EditMessageDelete extends OutgoingMessage {
+
+ @JsonProperty("message_id")
+ private Integer messageId;
+
+ /**
+ * Builds {@link EditMessageDelete} instance.
+ *
+ * @param chatId Unique identifier for the target chat or username of the target channel.
+ * @param messageId Identifier of the message to delete
+ */
+ public EditMessageDelete(String chatId, Integer messageId) {
+ super.setChatId(chatId);
+ this.messageId = messageId;
}
- public void setText(String text) {
-
- this.text = text;
+ public Integer getMessageId() {
+ return messageId;
}
@Override
public String toString() {
- final StringBuilder sb = new StringBuilder("InlineKeyboardButton{");
- sb.append("text='").append(text);
- sb.append('}');
- return sb.toString();
- }
-
- public static Builder builder() {
-
- return new Builder();
- }
-
- public static class Builder {
-
- private String text;
-
- public Builder text(String text) {
-
- this.text = text;
- return this;
- }
-
- public InlineKeyboardButton build() {
- return new InlineKeyboardButton(text);
- }
+ return "EditMessageDelete{"
+ + "messageId=" + messageId
+ + ", chatId='" + chatId + '\''
+ + '}';
}
}
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/EditMessageMediaMessage.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/EditMessageMediaMessage.java
new file mode 100644
index 0000000..4b14945
--- /dev/null
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/EditMessageMediaMessage.java
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.telegram.model;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Message to edit animation, audio, document, photo, or video messages.
+ * If a message is a part of a message album, then it can be edited only to a photo or a video.
+ * Otherwise, message type can be changed arbitrarily.
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class EditMessageMediaMessage extends OutgoingMessage {
+
+ @JsonProperty("message_id")
+ private Integer messageId;
+
+ @JsonProperty("inline_message_id")
+ private String inlineMessageId;
+
+ private InputMedia media;
+
+ @JsonProperty("reply_markup")
+ private InlineKeyboardMarkup replyMarkup;
+
+ /**
+ * Builds {@link EditMessageMediaMessage} instance.
+ *
+ * @param chatId Unique identifier for the target chat or username of the target channel.
+ * @param messageId Identifier of the message to edit. Required if inline_message_id is not specified.
+ * @param inlineMessageId Required if chat_id and message_id are not specified.
+ * Identifier of the inline message.
+ * @param media The media to send.
+ * @param replyMarkup An inline keyboard that appears right next to the message it belongs to.
+ */
+ public EditMessageMediaMessage(String chatId, Integer messageId, String inlineMessageId, InputMedia media,
+ InlineKeyboardMarkup replyMarkup) {
+ this.chatId = chatId;
+ this.messageId = messageId;
+ this.inlineMessageId = inlineMessageId;
+ this.media = media;
+ this.replyMarkup = replyMarkup;
+ }
+
+ public Integer getMessageId() {
+ return messageId;
+ }
+
+ public String getInlineMessageId() {
+ return inlineMessageId;
+ }
+
+ public InlineKeyboardMarkup getReplyMarkup() {
+ return replyMarkup;
+ }
+
+ public InputMedia getMedia() {
+ return media;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static final class Builder {
+ protected String chatId;
+ private Integer messageId;
+ private String inlineMessageId;
+ private InputMedia media;
+ private InlineKeyboardMarkup replyMarkup;
+
+ private Builder() {
+ }
+
+ public Builder messageId(Integer messageId) {
+ this.messageId = messageId;
+ return this;
+ }
+
+ public Builder inlineMessageId(String inlineMessageId) {
+ this.inlineMessageId = inlineMessageId;
+ return this;
+ }
+
+ public Builder media(InputMedia media) {
+ this.media = media;
+ return this;
+ }
+
+ public Builder replyMarkup(InlineKeyboardMarkup replyMarkup) {
+ this.replyMarkup = replyMarkup;
+ return this;
+ }
+
+ public Builder chatId(String chatId) {
+ this.chatId = chatId;
+ return this;
+ }
+
+ public EditMessageMediaMessage build() {
+ return new EditMessageMediaMessage(
+ chatId, messageId, inlineMessageId, media, replyMarkup);
+ }
+ }
+}
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/EditMessageReplyMarkupMessage.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/EditMessageReplyMarkupMessage.java
new file mode 100644
index 0000000..5bbcee8
--- /dev/null
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/EditMessageReplyMarkupMessage.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.telegram.model;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Message to edit only the reply markup of messages.
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class EditMessageReplyMarkupMessage extends OutgoingMessage {
+
+ @JsonProperty("message_id")
+ private Integer messageId;
+
+ @JsonProperty("inline_message_id")
+ private String inlineMessageId;
+
+ @JsonProperty("reply_markup")
+ private InlineKeyboardMarkup replyMarkup;
+
+ /**
+ * Builds {@link EditMessageReplyMarkupMessage} instance.
+ *
+ * @param chatId Unique identifier for the target chat or username of the target channel.
+ * @param messageId Identifier of the message to edit. Required if inline_message_id is not specified.
+ * @param inlineMessageId Required if chat_id and message_id are not specified.
+ * Identifier of the inline message.
+ * @param replyMarkup An inline keyboard that appears right next to the message it belongs to.
+ */
+ public EditMessageReplyMarkupMessage(String chatId, Integer messageId, String inlineMessageId,
+ InlineKeyboardMarkup replyMarkup) {
+ this.chatId = chatId;
+ this.messageId = messageId;
+ this.inlineMessageId = inlineMessageId;
+ this.replyMarkup = replyMarkup;
+ }
+
+ public Integer getMessageId() {
+ return messageId;
+ }
+
+ public String getInlineMessageId() {
+ return inlineMessageId;
+ }
+
+ public InlineKeyboardMarkup getReplyMarkup() {
+ return replyMarkup;
+ }
+
+ public static final class Builder {
+ protected String chatId;
+ private Integer messageId;
+ private String inlineMessageId;
+ private InlineKeyboardMarkup replyMarkup;
+
+ public Builder() {
+ }
+
+ public Builder messageId(Integer messageId) {
+ this.messageId = messageId;
+ return this;
+ }
+
+ public Builder inlineMessageId(String inlineMessageId) {
+ this.inlineMessageId = inlineMessageId;
+ return this;
+ }
+
+ public Builder replyMarkup(InlineKeyboardMarkup replyMarkup) {
+ this.replyMarkup = replyMarkup;
+ return this;
+ }
+
+ public Builder chatId(String chatId) {
+ this.chatId = chatId;
+ return this;
+ }
+
+ public EditMessageReplyMarkupMessage build() {
+ return new EditMessageReplyMarkupMessage(chatId, messageId, inlineMessageId, replyMarkup);
+ }
+ }
+
+
+ @Override
+ public String toString() {
+ return "EditMessageReplyMarkupMessage{"
+ + "messageId=" + messageId
+ + ", inlineMessageId='" + inlineMessageId + '\''
+ + ", replyMarkup=" + replyMarkup
+ + ", chatId='" + chatId + '\''
+ + '}';
+ }
+}
+
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/EditMessageTextMessage.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/EditMessageTextMessage.java
new file mode 100644
index 0000000..df6b20b
--- /dev/null
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/EditMessageTextMessage.java
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.telegram.model;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Message to edit text and game messages.
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class EditMessageTextMessage extends OutgoingMessage {
+
+ @JsonProperty("message_id")
+ private Integer messageId;
+
+ @JsonProperty("inline_message_id")
+ private String inlineMessageId;
+
+ private String text;
+
+ @JsonProperty("parse_mode")
+ private String parseMode;
+
+ @JsonProperty("disable_web_page_preview")
+ private Boolean disableWebPagePreview;
+
+ @JsonProperty("reply_markup")
+ private InlineKeyboardMarkup replyMarkup;
+
+ /**
+ * Builds {@link EditMessageTextMessage} instance.
+ *
+ * @param chatId Unique identifier for the target chat or username of the target channel.
+ * @param messageId Identifier of the message to edit. Required if inline_message_id is not specified.
+ * @param inlineMessageId Required if chat_id and message_id are not specified.
+ * Identifier of the inline message.
+ * @param text New text of the message.
+ * @param parseMode Send Markdown or HTML, if you want Telegram apps to show bold, italic,
+ * fixed-width text or inline URLs in your bot's message.
+ * @param disableWebPagePreview Disables link previews for links in this message.
+ * @param replyMarkup An inline keyboard that appears right next to the message it belongs to.
+ */
+ public EditMessageTextMessage(String chatId, Integer messageId, String inlineMessageId, String text,
+ String parseMode, Boolean disableWebPagePreview, InlineKeyboardMarkup replyMarkup) {
+ this.chatId = chatId;
+ this.messageId = messageId;
+ this.inlineMessageId = inlineMessageId;
+ this.text = text;
+ this.parseMode = parseMode;
+ this.disableWebPagePreview = disableWebPagePreview;
+ this.replyMarkup = replyMarkup;
+ }
+
+ public Integer getMessageId() {
+ return messageId;
+ }
+
+ public String getInlineMessageId() {
+ return inlineMessageId;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public Boolean getDisableWebPagePreview() {
+ return disableWebPagePreview;
+ }
+
+ public InlineKeyboardMarkup getReplyMarkup() {
+ return replyMarkup;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static final class Builder {
+ protected String chatId;
+ private Integer messageId;
+ private String inlineMessageId;
+ private String text;
+ private String parseMode;
+ private Boolean disableWebPagePreview;
+ private InlineKeyboardMarkup replyMarkup;
+
+ private Builder() {
+ }
+
+ public Builder messageId(Integer messageId) {
+ this.messageId = messageId;
+ return this;
+ }
+
+ public Builder inlineMessageId(String inlineMessageId) {
+ this.inlineMessageId = inlineMessageId;
+ return this;
+ }
+
+ public Builder text(String text) {
+ this.text = text;
+ return this;
+ }
+
+ public Builder parseMode(String parseMode) {
+ this.parseMode = parseMode;
+ return this;
+ }
+
+ public Builder disableWebPagePreview(Boolean disableWebPagePreview) {
+ this.disableWebPagePreview = disableWebPagePreview;
+ return this;
+ }
+
+ public Builder replyMarkup(InlineKeyboardMarkup replyMarkup) {
+ this.replyMarkup = replyMarkup;
+ return this;
+ }
+
+ public Builder chatId(String chatId) {
+ this.chatId = chatId;
+ return this;
+ }
+
+ public EditMessageTextMessage build() {
+ return new EditMessageTextMessage(
+ chatId, messageId, inlineMessageId, text, parseMode, disableWebPagePreview, replyMarkup);
+ }
+ }
+}
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingMessage.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingMessage.java
index 1fa6d7e..c33eaae4 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingMessage.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingMessage.java
@@ -59,6 +59,16 @@ public class IncomingMessage implements Serializable {
@JsonProperty("location")
private Location location;
+ private List<IncomingMessageEntity> entities;
+
+ @JsonProperty("caption_entities")
+ private List<IncomingMessageEntity> captionEntities;
+
+ @JsonProperty("reply_markup")
+ private InlineKeyboardMarkup replyMarkup;
+
+ private String caption;
+
public IncomingMessage() {
}
@@ -150,6 +160,38 @@ public class IncomingMessage implements Serializable {
this.location = location;
}
+ public List<IncomingMessageEntity> getEntities() {
+ return entities;
+ }
+
+ public void setEntities(List<IncomingMessageEntity> entities) {
+ this.entities = entities;
+ }
+
+ public String getCaption() {
+ return caption;
+ }
+
+ public void setCaption(String caption) {
+ this.caption = caption;
+ }
+
+ public List<IncomingMessageEntity> getCaptionEntities() {
+ return captionEntities;
+ }
+
+ public void setCaptionEntities(List<IncomingMessageEntity> captionEntities) {
+ this.captionEntities = captionEntities;
+ }
+
+ public InlineKeyboardMarkup getReplyMarkup() {
+ return replyMarkup;
+ }
+
+ public void setReplyMarkup(InlineKeyboardMarkup replyMarkup) {
+ this.replyMarkup = replyMarkup;
+ }
+
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("IncomingMessage{");
@@ -164,6 +206,10 @@ public class IncomingMessage implements Serializable {
sb.append(", document=").append(document);
sb.append(", sticker=").append(sticker);
sb.append(", location=").append(location);
+ sb.append(", entities=").append(entities);
+ sb.append(", caption=").append(caption);
+ sb.append(", captionEntities=").append(captionEntities);
+ sb.append(", replyMarkup=").append(replyMarkup);
sb.append('}');
return sb.toString();
}
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingMessageEntity.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingMessageEntity.java
new file mode 100644
index 0000000..2bdbb03
--- /dev/null
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingMessageEntity.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.telegram.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+/**
+ * This object represents one special entity in a text message. For example, hashtags, usernames, URLs, etc.
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class IncomingMessageEntity {
+
+ private String type;
+
+ private Integer offset;
+
+ private Integer length;
+
+ private String url;
+
+ private User user;
+
+ public IncomingMessageEntity() {
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public Integer getOffset() {
+ return offset;
+ }
+
+ public void setOffset(Integer offset) {
+ this.offset = offset;
+ }
+
+ public Integer getLength() {
+ return length;
+ }
+
+ public void setLength(Integer length) {
+ this.length = length;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public User getUser() {
+ return user;
+ }
+
+ public void setUser(User user) {
+ this.user = user;
+ }
+
+ @Override
+ public String toString() {
+ return "MessageEntity{"
+ + "type='" + type + '\''
+ + ", offset=" + offset
+ + ", length=" + length
+ + ", url='" + url + '\''
+ + ", user=" + user
+ + '}';
+ }
+}
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InlineKeyboardButton.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InlineKeyboardButton.java
index 0378d60..ea70766 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InlineKeyboardButton.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InlineKeyboardButton.java
@@ -16,38 +16,79 @@
*/
package org.apache.camel.component.telegram.model;
+import java.io.Serializable;
+import java.util.Objects;
+
import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Represents one button of an inline keyboard. You must use exactly one of the optional fields.
+ */
@JsonInclude(JsonInclude.Include.NON_NULL)
-public class InlineKeyboardButton {
+public class InlineKeyboardButton implements Serializable {
+
+ private static final long serialVersionUID = -5386858930543292655L;
private String text;
+ private String url;
+
+ @JsonProperty("login_url")
+ private LoginUrl loginUrl;
+
+ @JsonProperty("callback_data")
+ private String callbackData;
+
public InlineKeyboardButton() {
}
- public InlineKeyboardButton(String text) {
-
+ /**
+ * Builds {@link InlineKeyboardButton} instance.
+ *
+ * @param text Label text on the button
+ * @param url Optional. HTTP or tg:// url to be opened when button is pressed
+ * @param loginUrl Optional. An HTTP URL used to automatically authorize the user.
+ * @param callbackData Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes
+ */
+ public InlineKeyboardButton(String text, String url, LoginUrl loginUrl, String callbackData) {
this.text = text;
+ this.url = url;
+ this.callbackData = callbackData;
}
public String getText() {
-
return text;
}
public void setText(String text) {
-
this.text = text;
}
- @Override
- public String toString() {
- final StringBuilder sb = new StringBuilder("InlineKeyboardButton{");
- sb.append("text='").append(text);
- sb.append('}');
- return sb.toString();
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public LoginUrl getLoginUrl() {
+ return loginUrl;
+ }
+
+ public void setLoginUrl(LoginUrl loginUrl) {
+ this.loginUrl = loginUrl;
+ }
+
+ public String getCallbackData() {
+ return callbackData;
+ }
+
+ public void setCallbackData(String callbackData) {
+ this.callbackData = callbackData;
}
public static Builder builder() {
@@ -58,15 +99,62 @@ public class InlineKeyboardButton {
public static class Builder {
private String text;
+ private String url;
+ private String callbackData;
+ private LoginUrl loginUrl;
public Builder text(String text) {
-
this.text = text;
return this;
}
+ public Builder url(String url) {
+ this.url = url;
+ return this;
+ }
+
+ public Builder callbackData(String callbackData) {
+ this.callbackData = callbackData;
+ return this;
+ }
+
+ public Builder loginUrl(LoginUrl loginUrl) {
+ this.loginUrl = loginUrl;
+ return this;
+ }
+
public InlineKeyboardButton build() {
- return new InlineKeyboardButton(text);
+ return new InlineKeyboardButton(text, url, loginUrl, callbackData);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "InlineKeyboardButton{"
+ + "text='" + text + '\''
+ + ", url='" + url + '\''
+ + ", loginUrl=" + loginUrl
+ + ", callbackData='" + callbackData + '\''
+ + '}';
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
}
+ InlineKeyboardButton that = (InlineKeyboardButton) o;
+ return Objects.equals(text, that.text)
+ && Objects.equals(url, that.url)
+ && Objects.equals(loginUrl, that.loginUrl)
+ && Objects.equals(callbackData, that.callbackData);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(text, url, loginUrl, callbackData);
}
}
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InlineKeyboardMarkup.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InlineKeyboardMarkup.java
new file mode 100644
index 0000000..ecad81c
--- /dev/null
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InlineKeyboardMarkup.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.telegram.model;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * This object represents an inline keyboard that appears right next to the message it belongs to.
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class InlineKeyboardMarkup implements Serializable {
+
+ private static final long serialVersionUID = -8608993809697387977L;
+
+ @JsonProperty("inline_keyboard")
+ private List<List<InlineKeyboardButton>> inlineKeyboard;
+
+ /**
+ * Builds {@link InlineKeyboardMarkup} instance.
+ *
+ * @param inlineKeyboard Array of {@link InlineKeyboardButton} rows
+ */
+ public InlineKeyboardMarkup(List<List<InlineKeyboardButton>> inlineKeyboard) {
+ this.inlineKeyboard = inlineKeyboard;
+ }
+
+ public InlineKeyboardMarkup() {
+ }
+
+ public List<List<InlineKeyboardButton>> getInlineKeyboard() {
+ return inlineKeyboard;
+ }
+
+ public void setInlineKeyboard(List<List<InlineKeyboardButton>> inlineKeyboard) {
+ this.inlineKeyboard = inlineKeyboard;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static final class Builder {
+ private List<List<InlineKeyboardButton>> inlineKeyboard = new ArrayList<>();
+
+ private Builder() {
+ }
+
+ public Builder inlineKeyboard(List<List<InlineKeyboardButton>> inlineKeyboard) {
+ this.inlineKeyboard = inlineKeyboard;
+ return this;
+ }
+
+ public Builder addRow(List<InlineKeyboardButton> inlineKeyboardButtons) {
+ inlineKeyboard.add(inlineKeyboardButtons);
+ return this;
+ }
+
+ public InlineKeyboardMarkup build() {
+ return new InlineKeyboardMarkup(inlineKeyboard);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "InlineKeyboardMarkup{"
+ + "inlineKeyboard=" + inlineKeyboard
+ + '}';
+ }
+}
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InputMedia.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InputMedia.java
new file mode 100644
index 0000000..5f49ccc
--- /dev/null
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InputMedia.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.telegram.model;
+
+import java.io.Serializable;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+
+/**
+ * Represents the content of a media message to be sent.
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public abstract class InputMedia implements Serializable {
+
+ private static final long serialVersionUID = 7249606337728192452L;
+
+ private String type;
+
+ private String media;
+
+ private String caption;
+
+ @JsonProperty("parse_mode")
+ private String parseMode;
+
+ protected InputMedia() {
+ }
+
+ protected InputMedia(String type, String media, String caption, String parseMode) {
+ this.type = type;
+ this.media = media;
+ this.caption = caption;
+ this.parseMode = parseMode;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ protected void setType(String type) {
+ this.type = type;
+ }
+
+ public String getMedia() {
+ return media;
+ }
+
+ public void setMedia(String media) {
+ this.media = media;
+ }
+
+ public String getCaption() {
+ return caption;
+ }
+
+ public void setCaption(String caption) {
+ this.caption = caption;
+ }
+
+ public String getParseMode() {
+ return parseMode;
+ }
+
+ public void setParseMode(String parseMode) {
+ this.parseMode = parseMode;
+ }
+}
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InputMediaAnimation.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InputMediaAnimation.java
new file mode 100644
index 0000000..4755298
--- /dev/null
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InputMediaAnimation.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.telegram.model;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+
+/**
+ * Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent.
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class InputMediaAnimation extends InputMedia {
+
+ private static final String TYPE = "animation";
+
+ private Integer width;
+
+ private Integer height;
+
+ private Integer duration;
+
+ /**
+ * Builds {@link InputMediaAnimation} instance.
+ *
+ * @param media File to send. Pass a file_id to send a file that exists on the Telegram servers, or pass an
+ * HTTP URL for Telegram to get a file from the Internet
+ * @param caption Optional. Caption of the video to be sent, 0-1024 characters
+ * @param parseMode Optional. Send 'Markdown' or 'HTML', if you want Telegram apps to show bold, italic,
+ * fixed-width text or inline URLs in the media caption.
+ * @param width Optional. width.
+ * @param height Optional. height.
+ * @param duration Optional. duration.
+ */
+ public InputMediaAnimation(String media, String caption, String parseMode, Integer width, Integer height,
+ Integer duration) {
+ super(TYPE, media, caption, parseMode);
+ this.width = width;
+ this.height = height;
+ this.duration = duration;
+ }
+
+ public InputMediaAnimation() {
+ super.setType(TYPE);
+ }
+
+ public Integer getWidth() {
+ return width;
+ }
+
+ public void setWidth(Integer width) {
+ this.width = width;
+ }
+
+ public Integer getHeight() {
+ return height;
+ }
+
+ public void setHeight(Integer heigth) {
+ this.height = heigth;
+ }
+
+ public Integer getDuration() {
+ return duration;
+ }
+
+ public void setDuration(Integer duration) {
+ this.duration = duration;
+ }
+}
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InputMediaAudio.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InputMediaAudio.java
new file mode 100644
index 0000000..a4b59e4
--- /dev/null
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InputMediaAudio.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.telegram.model;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+
+/**
+ * Represents an audio file to be treated as music to be sent.
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class InputMediaAudio extends InputMedia {
+
+ private static final String TYPE = "audio";
+
+ private Integer duration;
+
+ private String performer;
+
+ private String title;
+
+ /**
+ * Builds {@link InputMediaAudio} instance.
+ *
+ * @param media File to send. Pass a file_id to send a file that exists on the Telegram servers, or pass an
+ * HTTP URL for Telegram to get a file from the Internet
+ * @param caption Optional. Caption of the video to be sent, 0-1024 characters
+ * @param parseMode Optional. Send 'Markdown' or 'HTML', if you want Telegram apps to show bold, italic,
+ * fixed-width text or inline URLs in the media caption.
+ * @param duration Optional. width.
+ * @param performer Optional. performer.
+ * @param title Optional. title.
+ */
+ public InputMediaAudio(String media, String caption, String parseMode, Integer duration, String performer,
+ String title) {
+ super(TYPE, media, caption, parseMode);
+ this.duration = duration;
+ this.performer = performer;
+ this.title = title;
+ }
+
+ public InputMediaAudio() {
+ super.setType(TYPE);
+ }
+
+ public Integer getDuration() {
+ return duration;
+ }
+
+ public void setDuration(Integer duration) {
+ this.duration = duration;
+ }
+
+ public String getPerformer() {
+ return performer;
+ }
+
+ public void setPerformer(String performer) {
+ this.performer = performer;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+}
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InlineKeyboardButton.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InputMediaPhoto.java
similarity index 52%
copy from components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InlineKeyboardButton.java
copy to components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InputMediaPhoto.java
index 0378d60..410ff93 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InlineKeyboardButton.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InputMediaPhoto.java
@@ -18,55 +18,28 @@ package org.apache.camel.component.telegram.model;
import com.fasterxml.jackson.annotation.JsonInclude;
+/**
+ * Represents a photo to be sent.
+ */
@JsonInclude(JsonInclude.Include.NON_NULL)
-public class InlineKeyboardButton {
-
- private String text;
-
- public InlineKeyboardButton() {
-
- }
-
- public InlineKeyboardButton(String text) {
-
- this.text = text;
- }
-
- public String getText() {
-
- return text;
- }
-
- public void setText(String text) {
-
- this.text = text;
- }
-
- @Override
- public String toString() {
- final StringBuilder sb = new StringBuilder("InlineKeyboardButton{");
- sb.append("text='").append(text);
- sb.append('}');
- return sb.toString();
+public class InputMediaPhoto extends InputMedia {
+
+ private static final String TYPE = "photo";
+
+ /**
+ * Builds {@link InputMediaPhoto} instance.
+ *
+ * @param media File to send. Pass a file_id to send a file that exists on the Telegram servers, or pass an
+ * HTTP URL for Telegram to get a file from the Internet
+ * @param caption Optional. Caption of the video to be sent, 0-1024 characters
+ * @param parseMode Optional. Send 'Markdown' or 'HTML', if you want Telegram apps to show bold, italic,
+ * fixed-width text or inline URLs in the media caption.
+ */
+ public InputMediaPhoto(String media, String caption, String parseMode) {
+ super(TYPE, media, caption, parseMode);
}
- public static Builder builder() {
-
- return new Builder();
- }
-
- public static class Builder {
-
- private String text;
-
- public Builder text(String text) {
-
- this.text = text;
- return this;
- }
-
- public InlineKeyboardButton build() {
- return new InlineKeyboardButton(text);
- }
+ public InputMediaPhoto() {
+ super.setType(TYPE);
}
}
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InputMediaVideo.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InputMediaVideo.java
new file mode 100644
index 0000000..e4b8b66
--- /dev/null
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/InputMediaVideo.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.telegram.model;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Represents a video to be sent.
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class InputMediaVideo extends InputMedia {
+
+ private static final String TYPE = "video";
+
+ private Integer width;
+
+ private Integer height;
+
+ private Integer duration;
+
+ @JsonProperty("supports_streaming")
+ private String supportsStreaming;
+
+ /**
+ * Builds {@link InputMediaVideo} instance.
+ *
+ * @param media File to send. Pass a file_id to send a file that exists on the Telegram servers,
+ * or pass an HTTP URL for Telegram to get a file from the Internet
+ * @param caption Optional. Caption of the video to be sent, 0-1024 characters
+ * @param parseMode Optional. Send 'Markdown' or 'HTML', if you want Telegram apps to show bold, italic,
+ * fixed-width text or inline URLs in the media caption.
+ * @param width Optional. Video width
+ * @param height Optional. Video height
+ * @param duration Optional. Video duration
+ * @param supportsStreaming Optional. Pass True, if the uploaded video is suitable for streaming
+ */
+ public InputMediaVideo(String media, String caption, String parseMode, Integer width,
+ Integer height, Integer duration, String supportsStreaming) {
+ super(TYPE, media, caption, parseMode);
+ this.width = width;
+ this.height = height;
+ this.duration = duration;
+ this.supportsStreaming = supportsStreaming;
+ }
+
+ public InputMediaVideo() {
+ super.setType(TYPE);
+ }
+
+ public Integer getWidth() {
+ return width;
+ }
+
+ public void setWidth(Integer width) {
+ this.width = width;
+ }
+
+ public Integer getHeight() {
+ return height;
+ }
+
+ public void setHeight(Integer height) {
+ this.height = height;
+ }
+
+ public Integer getDuration() {
+ return duration;
+ }
+
+ public void setDuration(Integer duration) {
+ this.duration = duration;
+ }
+
+ public String getSupportsStreaming() {
+ return supportsStreaming;
+ }
+
+ public void setSupportsStreaming(String supportsStreaming) {
+ this.supportsStreaming = supportsStreaming;
+ }
+}
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/LoginUrl.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/LoginUrl.java
new file mode 100644
index 0000000..204af90
--- /dev/null
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/LoginUrl.java
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.telegram.model;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+
+/**
+ * Represents a parameter of the inline keyboard button used to automatically authorize a user.
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class LoginUrl implements Serializable {
+
+ private static final long serialVersionUID = 4046971763350434361L;
+
+ private String url;
+ @JsonProperty("forward_text")
+ private String forwardText;
+ @JsonProperty("bot_username")
+ private String botUsername;
+ @JsonProperty("request_write_access")
+ private Boolean requestWriteAccess;
+
+ /**
+ * Builds {@link LoginUrl} instance.
+ *
+ * @param url An HTTP URL to be opened with user authorization data added to the query string
+ * when the button is pressed
+ * @param forwardText Optional. New text of the button in forwarded messages.
+ * @param botUsername Optional. Username of a bot, which will be used for user authorization.
+ * @param requestWriteAccess Optional. Pass True to request the permission for your bot to send messages to the user.
+ */
+ public LoginUrl(String url, String forwardText, String botUsername, Boolean requestWriteAccess) {
+ this.url = url;
+ this.forwardText = forwardText;
+ this.botUsername = botUsername;
+ this.requestWriteAccess = requestWriteAccess;
+ }
+
+ public LoginUrl() {
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getForwardText() {
+ return forwardText;
+ }
+
+ public void setForwardText(String forwardText) {
+ this.forwardText = forwardText;
+ }
+
+ public String getBotUsername() {
+ return botUsername;
+ }
+
+ public void setBotUsername(String botUsername) {
+ this.botUsername = botUsername;
+ }
+
+ public Boolean getRequestWriteAccess() {
+ return requestWriteAccess;
+ }
+
+ public void setRequestWriteAccess(Boolean requestWriteAccess) {
+ this.requestWriteAccess = requestWriteAccess;
+ }
+
+ @Override
+ public String toString() {
+ return "LoginUrl{"
+ + "url='" + url + '\''
+ + ", forwardText='" + forwardText + '\''
+ + ", botUsername='" + botUsername + '\''
+ + ", requestWriteAccess=" + requestWriteAccess
+ + '}';
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ LoginUrl loginUrl = (LoginUrl) o;
+ return Objects.equals(url, loginUrl.url)
+ && Objects.equals(forwardText, loginUrl.forwardText)
+ && Objects.equals(botUsername, loginUrl.botUsername)
+ && Objects.equals(requestWriteAccess, loginUrl.requestWriteAccess);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(url, forwardText, botUsername, requestWriteAccess);
+ }
+}
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/MessageResult.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/MessageResult.java
index 78f27b8..5301ffa 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/MessageResult.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/MessageResult.java
@@ -19,7 +19,10 @@ package org.apache.camel.component.telegram.model;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonSetter;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
@JsonIgnoreProperties(ignoreUnknown = true)
public class MessageResult implements Serializable {
@@ -28,9 +31,10 @@ public class MessageResult implements Serializable {
private boolean ok;
- @JsonProperty("result")
private IncomingMessage message;
+ private boolean result;
+
public MessageResult() {
}
@@ -50,6 +54,22 @@ public class MessageResult implements Serializable {
this.message = message;
}
+ @JsonSetter("result")
+ public void setResult(JsonNode result) throws JsonProcessingException {
+ if (result != null) {
+ if (result.isBoolean()) {
+ this.result = result.asBoolean();
+ } else if (result.isObject()) {
+ ObjectMapper objectMapper = new ObjectMapper();
+ this.message = objectMapper.treeToValue(result, IncomingMessage.class);
+ }
+ }
+ }
+
+ public boolean isResult() {
+ return result;
+ }
+
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("MessageResult{");
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/TelegramServiceRestBotAPIAdapter.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/TelegramServiceRestBotAPIAdapter.java
index 3373c9b..6b9ca24 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/TelegramServiceRestBotAPIAdapter.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/TelegramServiceRestBotAPIAdapter.java
@@ -34,7 +34,12 @@ import io.netty.handler.codec.http.HttpHeaders;
import org.apache.camel.AsyncCallback;
import org.apache.camel.Exchange;
import org.apache.camel.component.telegram.TelegramService;
+import org.apache.camel.component.telegram.model.EditMessageCaptionMessage;
+import org.apache.camel.component.telegram.model.EditMessageDelete;
import org.apache.camel.component.telegram.model.EditMessageLiveLocationMessage;
+import org.apache.camel.component.telegram.model.EditMessageMediaMessage;
+import org.apache.camel.component.telegram.model.EditMessageReplyMarkupMessage;
+import org.apache.camel.component.telegram.model.EditMessageTextMessage;
import org.apache.camel.component.telegram.model.MessageResult;
import org.apache.camel.component.telegram.model.OutgoingAudioMessage;
import org.apache.camel.component.telegram.model.OutgoingDocumentMessage;
@@ -98,6 +103,16 @@ public class TelegramServiceRestBotAPIAdapter implements TelegramService {
new OutgoingPlainMessageHandler(asyncHttpClient, bufferSize, mapper, baseUri + "/stopMessageLiveLocation"));
m.put(SendVenueMessage.class,
new OutgoingPlainMessageHandler(asyncHttpClient, bufferSize, mapper, baseUri + "/sendVenue"));
+ m.put(EditMessageTextMessage.class,
+ new OutgoingPlainMessageHandler(asyncHttpClient, bufferSize, mapper, baseUri + "/editMessageText"));
+ m.put(EditMessageCaptionMessage.class,
+ new OutgoingPlainMessageHandler(asyncHttpClient, bufferSize, mapper, baseUri + "/editMessageCaption"));
+ m.put(EditMessageMediaMessage.class,
+ new OutgoingPlainMessageHandler(asyncHttpClient, bufferSize, mapper, baseUri + "/editMessageMedia"));
+ m.put(EditMessageDelete.class,
+ new OutgoingPlainMessageHandler(asyncHttpClient, bufferSize, mapper, baseUri + "/deleteMessage"));
+ m.put(EditMessageReplyMarkupMessage.class,
+ new OutgoingPlainMessageHandler(asyncHttpClient, bufferSize, mapper, baseUri + "/editMessageReplyMarkup"));
this.handlers = m;
}
@@ -174,7 +189,7 @@ public class TelegramServiceRestBotAPIAdapter implements TelegramService {
.get(message.getClass());
if (handler == null) {
throw new IllegalArgumentException(
- "Unsupported message type " + (message != null ? message.getClass().getName() : null));
+ "Unsupported message type " + (message.getClass().getName()));
}
handler.sendMessage(exchange, callback, message);
}
@@ -189,7 +204,6 @@ public class TelegramServiceRestBotAPIAdapter implements TelegramService {
protected void addBody(RequestBuilder builder, OutgoingMessage message) {
try {
final String body = mapper.writeValueAsString(message);
- LOG.warn("sending " + body);
builder.setBody(body);
} catch (JsonProcessingException e) {
throw new RuntimeException("Could not serialize " + message);
@@ -421,8 +435,7 @@ public class TelegramServiceRestBotAPIAdapter implements TelegramService {
}
@Override
- public State onStatusReceived(HttpResponseStatus responseStatus)
- throws Exception {
+ public State onStatusReceived(HttpResponseStatus responseStatus) {
if (LOG.isTraceEnabled()) {
LOG.trace("{} onStatusReceived {}", exchange.getExchangeId(), responseStatus);
}
@@ -432,7 +445,7 @@ public class TelegramServiceRestBotAPIAdapter implements TelegramService {
}
@Override
- public State onHeadersReceived(HttpHeaders headers) throws Exception {
+ public State onHeadersReceived(HttpHeaders headers) {
contentEncoding = headers.get("Content-Encoding");
contentType = headers.get("Content-Type");
charset = withDefault(extractContentTypeCharsetAttribute(contentType), StandardCharsets.UTF_8);
diff --git a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/integration/TelegramServiceTest.java b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/integration/TelegramServiceTest.java
index f5e3988..d3f81c5 100644
--- a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/integration/TelegramServiceTest.java
+++ b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/integration/TelegramServiceTest.java
@@ -18,12 +18,25 @@ package org.apache.camel.component.telegram.integration;
import java.io.IOException;
import java.util.Arrays;
+import java.util.Collections;
import org.apache.camel.component.telegram.TelegramParseMode;
+import org.apache.camel.component.telegram.model.EditMessageCaptionMessage;
+import org.apache.camel.component.telegram.model.EditMessageDelete;
+import org.apache.camel.component.telegram.model.EditMessageMediaMessage;
+import org.apache.camel.component.telegram.model.EditMessageReplyMarkupMessage;
+import org.apache.camel.component.telegram.model.EditMessageTextMessage;
import org.apache.camel.component.telegram.model.IncomingMessage;
import org.apache.camel.component.telegram.model.InlineKeyboardButton;
+import org.apache.camel.component.telegram.model.InlineKeyboardMarkup;
+import org.apache.camel.component.telegram.model.InputMediaAnimation;
+import org.apache.camel.component.telegram.model.InputMediaAudio;
+import org.apache.camel.component.telegram.model.InputMediaPhoto;
+import org.apache.camel.component.telegram.model.InputMediaVideo;
+import org.apache.camel.component.telegram.model.MessageResult;
import org.apache.camel.component.telegram.model.OutgoingAudioMessage;
import org.apache.camel.component.telegram.model.OutgoingDocumentMessage;
+import org.apache.camel.component.telegram.model.OutgoingMessage;
import org.apache.camel.component.telegram.model.OutgoingPhotoMessage;
import org.apache.camel.component.telegram.model.OutgoingStickerMessage;
import org.apache.camel.component.telegram.model.OutgoingTextMessage;
@@ -32,6 +45,7 @@ import org.apache.camel.component.telegram.model.ReplyKeyboardMarkup;
import org.apache.camel.component.telegram.util.TelegramApiConfig;
import org.apache.camel.component.telegram.util.TelegramTestSupport;
import org.apache.camel.component.telegram.util.TelegramTestUtil;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -87,28 +101,28 @@ public class TelegramServiceTest extends TelegramTestSupport {
msg.setText("Choose one option!");
InlineKeyboardButton buttonOptionOneI = InlineKeyboardButton.builder()
- .text("Option One - I").build();
+ .text("Option One - I").build();
InlineKeyboardButton buttonOptionOneII = InlineKeyboardButton.builder()
- .text("Option One - II").build();
+ .text("Option One - II").build();
InlineKeyboardButton buttonOptionTwoI = InlineKeyboardButton.builder()
- .text("Option Two - I").build();
+ .text("Option Two - I").build();
InlineKeyboardButton buttonOptionThreeI = InlineKeyboardButton.builder()
- .text("Option Three - I").build();
+ .text("Option Three - I").build();
InlineKeyboardButton buttonOptionThreeII = InlineKeyboardButton.builder()
- .text("Option Three - II").build();
+ .text("Option Three - II").build();
ReplyKeyboardMarkup replyMarkup = ReplyKeyboardMarkup.builder()
- .keyboard()
- .addRow(Arrays.asList(buttonOptionOneI, buttonOptionOneII))
- .addRow(Arrays.asList(buttonOptionTwoI))
- .addRow(Arrays.asList(buttonOptionThreeI, buttonOptionThreeII))
- .close()
- .oneTimeKeyboard(true)
- .build();
+ .keyboard()
+ .addRow(Arrays.asList(buttonOptionOneI, buttonOptionOneII))
+ .addRow(Arrays.asList(buttonOptionTwoI))
+ .addRow(Arrays.asList(buttonOptionThreeI, buttonOptionThreeII))
+ .close()
+ .oneTimeKeyboard(true)
+ .build();
msg.setReplyKeyboardMarkup(replyMarkup);
@@ -122,8 +136,8 @@ public class TelegramServiceTest extends TelegramTestSupport {
msg.setText("Your answer was accepted!");
ReplyKeyboardMarkup replyMarkup = ReplyKeyboardMarkup.builder()
- .removeKeyboard(true)
- .build();
+ .removeKeyboard(true)
+ .build();
msg.setReplyKeyboardMarkup(replyMarkup);
@@ -275,4 +289,274 @@ public class TelegramServiceTest extends TelegramTestSupport {
template.requestBody(String.format("telegram://bots?chatId=%s", chatId), msg);
}
+ @Test
+ public void testEditTextMessage() {
+
+ // Given
+ final String originalText = "ORIGINAL";
+ final String newText = "NEW";
+
+ // Send message
+ Integer messageId = sendSampleTextMessageAndGetMessageId(originalText);
+
+ // Edit message
+ EditMessageTextMessage msg = EditMessageTextMessage.builder()
+ .chatId(chatId)
+ .text(newText)
+ .messageId(messageId)
+ .build();
+
+ MessageResult response = sendMessage(msg);
+
+ Assertions.assertEquals(newText, response.getMessage().getText());
+ }
+
+ @Test
+ public void testEditTextMessageWithUrl() {
+
+ //Given
+ final String originalText = "ORIGINAL";
+ final String urlDescription = "Inline URL";
+ final String url = "http://www.example.com/";
+ final String newTextWithUrl = String.format("<a href=\"%s\">%s</a>", url, urlDescription);
+
+ // Send message
+ Integer messageId = sendSampleTextMessageAndGetMessageId(originalText);
+
+ // Edit message
+ EditMessageTextMessage msg = EditMessageTextMessage.builder()
+ .chatId(chatId)
+ .text(newTextWithUrl)
+ .parseMode("HTML")
+ .messageId(messageId)
+ .build();
+
+ MessageResult response = sendMessage(msg);
+
+ Assertions.assertEquals(urlDescription, response.getMessage().getText());
+ Assertions.assertEquals(url, response.getMessage().getEntities().get(0).getUrl());
+ Assertions.assertEquals("text_link", response.getMessage().getEntities().get(0).getType());
+ }
+
+ @Test
+ void testEditCaptionMessage() throws IOException {
+
+ String originalCaption = "original caption";
+ String newCaption = "edited caption";
+
+ //Send message with caption
+ Integer messageId = sendSamplePhotoMessageAndGetMessageId(originalCaption);
+
+ //edit message
+ EditMessageCaptionMessage editMessageCaptionMessage = EditMessageCaptionMessage.builder()
+ .caption(newCaption)
+ .messageId(messageId)
+ .build();
+
+ IncomingMessage incomingMessage = sendMessage(editMessageCaptionMessage).getMessage();
+ Assertions.assertEquals(newCaption, incomingMessage.getCaption());
+ }
+
+ @Test
+ void testEditCaptionMessageWithUrl() throws IOException {
+
+ //Given
+ String originalCaption = "original caption";
+ final String urlDescription = "Inline URL";
+ final String url = "http://www.example.com/";
+ final String newCaptionWithUrl = String.format("<a href=\"%s\">%s</a>", url, urlDescription);
+
+ //Send message
+ Integer messageId = sendSamplePhotoMessageAndGetMessageId(originalCaption);
+
+ //edit message
+ EditMessageCaptionMessage editMessageCaptionMessage = EditMessageCaptionMessage.builder()
+ .caption(newCaptionWithUrl)
+ .messageId(messageId)
+ .parseMode("HTML")
+ .build();
+
+ IncomingMessage incomingMessage = sendMessage(editMessageCaptionMessage).getMessage();
+ Assertions.assertEquals(urlDescription, incomingMessage.getCaption());
+ Assertions.assertEquals(url, incomingMessage.getCaptionEntities().get(0).getUrl());
+ Assertions.assertEquals("text_link", incomingMessage.getCaptionEntities().get(0).getType());
+ }
+
+ @Test
+ void testEditMediaToAudio() throws IOException {
+
+ //given
+ String mediaUrl = "https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3";
+ String caption = "caption";
+
+ //send photo message
+ Integer messageId = sendSamplePhotoMessageAndGetMessageId();
+
+ //update to audio message
+ InputMediaAudio inputMediaAudio = new InputMediaAudio();
+ inputMediaAudio.setCaption(caption);
+ inputMediaAudio.setMedia(mediaUrl);
+
+ EditMessageMediaMessage editMessageMediaMessage = EditMessageMediaMessage.builder()
+ .messageId(messageId)
+ .media(inputMediaAudio)
+ .build();
+
+ IncomingMessage incomingMessage = sendMessage(editMessageMediaMessage).getMessage();
+ Assertions.assertNull(incomingMessage.getPhoto());
+ Assertions.assertNotNull(incomingMessage.getAudio());
+ Assertions.assertEquals(caption, incomingMessage.getCaption());
+ }
+
+ @Test
+ void testEditMediaToAnimation() throws IOException {
+
+ //given
+ String mediaUrl = "CgADBAADlZ8AAtMdZAd-ZylyB-kkGRYE";
+ String caption = "caption";
+
+ //send photo message
+ Integer messageId = sendSamplePhotoMessageAndGetMessageId();
+
+ //update to animation
+ InputMediaAnimation inputMediaAnimation = new InputMediaAnimation();
+ inputMediaAnimation.setCaption(caption);
+ inputMediaAnimation.setMedia(mediaUrl);
+
+ EditMessageMediaMessage editMessageMediaMessage = EditMessageMediaMessage.builder()
+ .messageId(messageId)
+ .media(inputMediaAnimation)
+ .build();
+
+ IncomingMessage incomingMessage = sendMessage(editMessageMediaMessage).getMessage();
+ Assertions.assertNull(incomingMessage.getPhoto());
+ Assertions.assertNotNull(incomingMessage.getDocument());
+ Assertions.assertEquals(caption, incomingMessage.getCaption());
+ }
+
+ @Test
+ void testEditMediaToVideo() throws IOException {
+
+ //given
+ String mediaUrl = "http://mirrors.standaloneinstaller.com/video-sample/small.mp4";
+ String caption = "caption";
+
+ //send photo message
+ Integer messageId = sendSamplePhotoMessageAndGetMessageId();
+
+ //update to video message
+ InputMediaVideo inputMediaVideo = new InputMediaVideo();
+ inputMediaVideo.setCaption(caption);
+ inputMediaVideo.setMedia(mediaUrl);
+
+ EditMessageMediaMessage editMessageMediaMessage = EditMessageMediaMessage.builder()
+ .messageId(messageId)
+ .media(inputMediaVideo)
+ .build();
+
+ IncomingMessage incomingMessage = sendMessage(editMessageMediaMessage).getMessage();
+ Assertions.assertNull(incomingMessage.getPhoto());
+ Assertions.assertNotNull(incomingMessage.getVideo());
+ Assertions.assertEquals(caption, incomingMessage.getCaption());
+ }
+
+ @Test
+ void testEditMediaToPhoto() throws IOException {
+
+ //given
+ String mediaUrl = "https://sample-videos.com/img/Sample-jpg-image-50kb.jpg";
+ String caption = "caption";
+
+ //send photo message
+ Integer messageId = sendSamplePhotoMessageAndGetMessageId();
+
+ //update to another photo message
+ InputMediaPhoto inputMediaPhoto = new InputMediaPhoto();
+ inputMediaPhoto.setCaption(String.format("<b>%s</b>", caption));
+ inputMediaPhoto.setParseMode("HTML");
+ inputMediaPhoto.setMedia(mediaUrl);
+
+ EditMessageMediaMessage editMessageMediaMessage = EditMessageMediaMessage.builder()
+ .messageId(messageId)
+ .media(inputMediaPhoto)
+ .build();
+
+ IncomingMessage incomingMessage = sendMessage(editMessageMediaMessage).getMessage();
+ Assertions.assertNotNull(incomingMessage.getPhoto());
+ Assertions.assertEquals(caption, incomingMessage.getCaption());
+ Assertions.assertEquals("bold", incomingMessage.getCaptionEntities().get(0).getType());
+ }
+
+ @Test
+ void testEditMarkupMessage() throws IOException {
+
+ //send message
+ Integer messageId = sendSamplePhotoMessageAndGetMessageId();
+
+ //edit markup
+ InlineKeyboardButton buttonOptionOneI = InlineKeyboardButton.builder()
+ .text("camel")
+ .url("https://camel.apache.org/")
+ .build();
+
+ InlineKeyboardMarkup replyMarkup = InlineKeyboardMarkup.builder()
+ .addRow(Collections.singletonList(buttonOptionOneI))
+ .build();
+
+ EditMessageReplyMarkupMessage editMessageReplyMarkupMessage = new EditMessageReplyMarkupMessage.Builder()
+ .messageId(messageId)
+ .replyMarkup(replyMarkup)
+ .build();
+
+ MessageResult incomingMessage = sendMessage(editMessageReplyMarkupMessage);
+ Assertions.assertTrue(incomingMessage.isOk());
+
+ Assertions.assertEquals(buttonOptionOneI, incomingMessage.getMessage().getReplyMarkup().getInlineKeyboard()
+ .get(0).get(0));
+ }
+
+ @Test
+ void testDeleteMessage() {
+
+ //send message
+ Integer messageId = sendSampleTextMessageAndGetMessageId("text");
+
+ //delete message
+ EditMessageDelete messageDelete = new EditMessageDelete(chatId, messageId);
+
+ MessageResult incomingMessage = sendMessage(messageDelete);
+ Assertions.assertTrue(incomingMessage.isOk());
+ Assertions.assertTrue(incomingMessage.isResult());
+ }
+
+ private Integer sendSamplePhotoMessageAndGetMessageId(String caption) throws IOException {
+ byte[] image = TelegramTestUtil.createSampleImage("PNG");
+
+ OutgoingPhotoMessage msg = new OutgoingPhotoMessage();
+ msg.setPhoto(image);
+ msg.setFilenameWithExtension("file.png");
+ msg.setCaption(caption);
+
+ return sendMessage(msg).getMessage().getMessageId().intValue();
+ }
+
+ private Integer sendSampleTextMessageAndGetMessageId(String text) {
+ OutgoingTextMessage msg = new OutgoingTextMessage();
+ msg.setText(text);
+ return sendMessage(msg).getMessage().getMessageId().intValue();
+ }
+
+ private Integer sendSamplePhotoMessageAndGetMessageId() throws IOException {
+ byte[] image = TelegramTestUtil.createSampleImage("PNG");
+
+ OutgoingPhotoMessage msg = new OutgoingPhotoMessage();
+ msg.setPhoto(image);
+ msg.setFilenameWithExtension("file.png");
+
+ return sendMessage(msg).getMessage().getMessageId().intValue();
+ }
+
+ private MessageResult sendMessage(OutgoingMessage outgoingMessage) {
+ return (MessageResult) template.requestBody(String.format("telegram://bots?chatId=%s", chatId), outgoingMessage);
+ }
}