You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/01/28 07:16:56 UTC
[camel] branch master updated: CAMEL-11541: Add "sendLocation",
"editMessageLiveLocation" methods support
This is an automated email from the ASF dual-hosted git repository.
acosentino 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 8f912fc CAMEL-11541: Add "sendLocation", "editMessageLiveLocation" methods support
8f912fc is described below
commit 8f912fc9a3f1d2793c2c2841570183a99881f6a0
Author: Denis Istomin <is...@gmail.com>
AuthorDate: Tue Jan 22 19:04:29 2019 +0500
CAMEL-11541: Add "sendLocation", "editMessageLiveLocation" methods support
---
.../src/main/docs/telegram-component.adoc | 2 +
.../component/telegram/TelegramComponent.java | 3 +-
.../camel/component/telegram/TelegramProducer.java | 5 +-
.../camel/component/telegram/TelegramService.java | 4 +-
.../camel/component/telegram/model/Chat.java | 13 ++++
.../model/EditMessageLiveLocationMessage.java | 71 +++++++++++++++++
.../component/telegram/model/IncomingAudio.java | 2 +-
.../component/telegram/model/IncomingMessage.java | 11 +++
.../telegram/model/{Chat.java => Location.java} | 52 ++++---------
.../model/{Chat.java => MessageResult.java} | 48 +++++-------
.../telegram/model/SendLocationMessage.java | 82 ++++++++++++++++++++
.../telegram/model/UnixTimestampDeserializer.java | 1 -
.../camel/component/telegram/model/User.java | 12 +++
.../component/telegram/service/RestBotAPI.java | 28 +++++--
.../service/TelegramServiceRestBotAPIAdapter.java | 50 +++++++-----
.../telegram/TelegramConsumerMappingTest.java | 26 ++++++-
.../telegram/TelegramProducerLocationTest.java | 90 ++++++++++++++++++++++
.../resources/messages/updates-sendLocation.json | 23 ++++++
18 files changed, 422 insertions(+), 101 deletions(-)
diff --git a/components/camel-telegram/src/main/docs/telegram-component.adoc b/components/camel-telegram/src/main/docs/telegram-component.adoc
index 83a4461..bc928b0 100644
--- a/components/camel-telegram/src/main/docs/telegram-component.adoc
+++ b/components/camel-telegram/src/main/docs/telegram-component.adoc
@@ -192,6 +192,8 @@ The following message bodies are allowed for a producer endpoint (messages of ty
| `OutgoingAudioMessage` | To send a mp3 audio to a chat
| `OutgoingVideoMessage` | To send a mp4 video to a chat
| `OutgoingDocumentMessage` | To send a file to a chat (any media type)
+| `SendLocationMessage` | To send a location (setSendLocation)
+| `EditMessageLiveLocationMessage` | To send changes to a live location (editMessageLiveLocation)
| `byte[]` | To send any media type supported. It requires the `CamelTelegramMediaType` header to be set to the appropriate media type
| `String` | To send a text message to a chat. It gets converted automatically into a `OutgoingTextMessage`
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramComponent.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramComponent.java
index 0fd35f8..7c616a9 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramComponent.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramComponent.java
@@ -19,9 +19,8 @@ package org.apache.camel.component.telegram;
import java.util.Map;
import org.apache.camel.Endpoint;
-
-import org.apache.camel.spi.annotations.Component;
import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.annotations.Component;
import org.apache.camel.support.DefaultComponent;
import org.apache.camel.util.ObjectHelper;
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramProducer.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramProducer.java
index 7d63312..4a68550 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramProducer.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramProducer.java
@@ -62,7 +62,10 @@ public class TelegramProducer extends DefaultProducer {
log.debug("Message being sent is: {}", message);
log.debug("Headers of message being sent are: {}", exchange.getIn().getHeaders());
- service.sendMessage(config.getAuthorizationToken(), message);
+ Object receivedMessage = service.sendMessage(config.getAuthorizationToken(), message);
+ log.debug("Message being received is: {}", receivedMessage);
+
+ exchange.getOut().setBody(receivedMessage);
}
private String resolveChatId(TelegramConfiguration config, OutgoingMessage message, Exchange exchange) {
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramService.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramService.java
index b38f4ad..c3641ce 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramService.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramService.java
@@ -24,9 +24,7 @@ import org.apache.camel.component.telegram.model.UpdateResult;
*/
public interface TelegramService {
-
UpdateResult getUpdates(String authorizationToken, Long offset, Integer limit, Integer timeoutSeconds);
- void sendMessage(String authorizationToken, OutgoingMessage message);
-
+ Object sendMessage(String authorizationToken, OutgoingMessage message);
}
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Chat.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Chat.java
index 75de354..988d418 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Chat.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Chat.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.telegram.model;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Contains information about a telegram chat.
@@ -34,6 +35,9 @@ public class Chat implements Serializable {
private String type;
+ @JsonProperty("all_members_are_administrators")
+ private boolean allMembersAreAdministrators;
+
public Chat() {
}
@@ -61,12 +65,21 @@ public class Chat implements Serializable {
this.type = type;
}
+ public boolean isAllMembersAreAdministrators() {
+ return allMembersAreAdministrators;
+ }
+
+ public void setAllMembersAreAdministrators(boolean allMembersAreAdministrators) {
+ this.allMembersAreAdministrators = allMembersAreAdministrators;
+ }
+
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("Chat{");
sb.append("id='").append(id).append('\'');
sb.append(", title='").append(title).append('\'');
sb.append(", type='").append(type).append('\'');
+ sb.append(", all_members_are_administrators='").append(allMembersAreAdministrators).append('\'');
sb.append('}');
return sb.toString();
}
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/EditMessageLiveLocationMessage.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/EditMessageLiveLocationMessage.java
new file mode 100644
index 0000000..42ecc3a
--- /dev/null
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/EditMessageLiveLocationMessage.java
@@ -0,0 +1,71 @@
+/**
+ * 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.JsonProperty;
+
+public class EditMessageLiveLocationMessage extends OutgoingMessage {
+
+ @JsonProperty("latitude")
+ private double latitude;
+
+ @JsonProperty("longitude")
+ private double longitude;
+
+ @JsonProperty("message_id")
+ private Long messageId;
+
+ @JsonProperty("inline_message_id")
+ private String inlineMessageId;
+
+ @JsonProperty("reply_markup")
+ private ReplyKeyboardMarkup replyKeyboardMarkup;
+
+ public EditMessageLiveLocationMessage(double latitude, double longitude) {
+ this.setLatitude(latitude);
+ this.setLongitude(longitude);
+ }
+
+ public void setLatitude(double latitude) {
+ this.latitude = latitude;
+ }
+
+ public void setLongitude(double longitude) {
+ this.longitude = longitude;
+ }
+
+ public void setReplyKeyboardMarkup(ReplyKeyboardMarkup replyKeyboardMarkup) {
+ this.replyKeyboardMarkup = replyKeyboardMarkup;
+ }
+
+ public void setMessageId(Long messageId) {
+ this.messageId = messageId;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder("{");
+ sb.append("message_id='").append(messageId).append('\'');
+ sb.append(", inlineMessageId=").append(inlineMessageId).append('\'');
+ sb.append(", latitude=").append(latitude).append('\'');
+ sb.append(", longitude=").append(longitude).append('\'');
+ sb.append(", replyKeyboardMarkup=").append(replyKeyboardMarkup);
+ sb.append('}');
+ return sb.toString();
+ }
+}
+
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingAudio.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingAudio.java
index c4a649a..278a272 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingAudio.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingAudio.java
@@ -20,7 +20,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
- * ontains information about an audio file.
+ * Contains information about an audio file.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class IncomingAudio {
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 44d1fde..f28e8d4 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
@@ -52,6 +52,9 @@ public class IncomingMessage implements Serializable {
private IncomingDocument document;
+ @JsonProperty("location")
+ private Location location;
+
public IncomingMessage() {
}
@@ -127,6 +130,13 @@ public class IncomingMessage implements Serializable {
this.document = document;
}
+ public Location getLocation() {
+ return location;
+ }
+
+ public void setLocation(Location location) {
+ this.location = location;
+ }
@Override
public String toString() {
@@ -140,6 +150,7 @@ public class IncomingMessage implements Serializable {
sb.append(", video=").append(video);
sb.append(", audio=").append(audio);
sb.append(", document=").append(document);
+ sb.append(", location=").append(location);
sb.append('}');
return sb.toString();
}
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Chat.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Location.java
similarity index 55%
copy from components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Chat.java
copy to components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Location.java
index 75de354..558267c 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Chat.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Location.java
@@ -16,57 +16,39 @@
*/
package org.apache.camel.component.telegram.model;
-import java.io.Serializable;
-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
-/**
- * Contains information about a telegram chat.
- */
@JsonIgnoreProperties(ignoreUnknown = true)
-public class Chat implements Serializable {
-
- private static final long serialVersionUID = 4706232811327318379L;
-
- private String id;
-
- private String title;
+public class Location {
- private String type;
+ @JsonProperty("latitude")
+ private double latitude;
- public Chat() {
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
+ @JsonProperty("longitude")
+ private double longitude;
- public String getTitle() {
- return title;
+ public double getLatitude() {
+ return latitude;
}
- public void setTitle(String title) {
- this.title = title;
+ public void setLatitude(float latitude) {
+ this.latitude = latitude;
}
- public String getType() {
- return type;
+ public double getLongitude() {
+ return longitude;
}
- public void setType(String type) {
- this.type = type;
+ public void setLongitude(float longitude) {
+ this.longitude = longitude;
}
@Override
public String toString() {
- final StringBuilder sb = new StringBuilder("Chat{");
- sb.append("id='").append(id).append('\'');
- sb.append(", title='").append(title).append('\'');
- sb.append(", type='").append(type).append('\'');
+ final StringBuilder sb = new StringBuilder("Location{");
+ sb.append("longitude='").append(longitude).append('\'');
+ sb.append(", latitude=").append(latitude);
sb.append('}');
return sb.toString();
}
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Chat.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/MessageResult.java
similarity index 57%
copy from components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Chat.java
copy to components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/MessageResult.java
index 75de354..2086e49 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/Chat.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/MessageResult.java
@@ -19,54 +19,42 @@ package org.apache.camel.component.telegram.model;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
-/**
- * Contains information about a telegram chat.
- */
@JsonIgnoreProperties(ignoreUnknown = true)
-public class Chat implements Serializable {
-
- private static final long serialVersionUID = 4706232811327318379L;
-
- private String id;
+public class MessageResult implements Serializable {
- private String title;
+ private static final long serialVersionUID = -4560342931918215225L;
- private String type;
+ private boolean ok;
- public Chat() {
- }
-
- public String getId() {
- return id;
- }
+ @JsonProperty("result")
+ private IncomingMessage message;
- public void setId(String id) {
- this.id = id;
+ public MessageResult() {
}
- public String getTitle() {
- return title;
+ public boolean isOk() {
+ return ok;
}
- public void setTitle(String title) {
- this.title = title;
+ public void setOk(boolean ok) {
+ this.ok = ok;
}
- public String getType() {
- return type;
+ public IncomingMessage getMessage() {
+ return message;
}
- public void setType(String type) {
- this.type = type;
+ public void setMessage(IncomingMessage message) {
+ this.message = message;
}
@Override
public String toString() {
- final StringBuilder sb = new StringBuilder("Chat{");
- sb.append("id='").append(id).append('\'');
- sb.append(", title='").append(title).append('\'');
- sb.append(", type='").append(type).append('\'');
+ final StringBuilder sb = new StringBuilder("MessageResult{");
+ sb.append("ok=").append(ok);
+ sb.append(", message=").append(message);
sb.append('}');
return sb.toString();
}
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/SendLocationMessage.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/SendLocationMessage.java
new file mode 100644
index 0000000..67391a8
--- /dev/null
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/SendLocationMessage.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.JsonProperty;
+
+public class SendLocationMessage extends OutgoingMessage {
+ @JsonProperty("longitude")
+ private double longitude;
+
+ @JsonProperty("latitude")
+ private double latitude;
+
+ @JsonProperty("live_period")
+ private Integer livePeriod;
+
+ @JsonProperty("disable_notification")
+ private boolean disableNotification;
+
+ @JsonProperty("reply_markup")
+ private ReplyKeyboardMarkup replyKeyboardMarkup;
+
+ public SendLocationMessage(double latitude, double longitude) {
+ this.setLatitude(latitude);
+ this.setLongitude(longitude);
+ }
+
+ public void setLatitude(double latitude) {
+ this.latitude = latitude;
+ }
+
+ public void setLongitude(double longitude) {
+ this.longitude = longitude;
+ }
+
+ public void setLivePeriod(Integer livePeriod) {
+ this.livePeriod = livePeriod;
+ }
+
+ public boolean isDisableNotification() {
+ return disableNotification;
+ }
+
+ public void setDisableNotification(boolean disableNotification) {
+ this.disableNotification = disableNotification;
+ }
+
+ public ReplyKeyboardMarkup getReplyKeyboardMarkup() {
+ return replyKeyboardMarkup;
+ }
+
+ public void setReplyKeyboardMarkup(ReplyKeyboardMarkup replyKeyboardMarkup) {
+ this.replyKeyboardMarkup = replyKeyboardMarkup;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder("SendLocationMessage{");
+ sb.append("latitude=").append(latitude).append('\'');
+ sb.append(", longitude=").append(longitude).append('\'');
+ sb.append(", livePeriod=").append(livePeriod).append('\'');
+ sb.append(", disableNotification=").append(disableNotification).append('\'');
+ sb.append(", replyToMessageId=").append(replyToMessageId).append('\'');
+ sb.append(", replyKeyboardMarkup=").append(replyKeyboardMarkup);
+ sb.append('}');
+ return sb.toString();
+ }
+}
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/UnixTimestampDeserializer.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/UnixTimestampDeserializer.java
index 844dfa3..c18c5fd 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/UnixTimestampDeserializer.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/UnixTimestampDeserializer.java
@@ -23,7 +23,6 @@ import java.time.Instant;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/User.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/User.java
index cdd3552..4fc7ef1 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/User.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/User.java
@@ -39,6 +39,9 @@ public class User implements Serializable {
private String username;
+ @JsonProperty("is_bot")
+ private boolean isBot;
+
public User() {
}
@@ -74,10 +77,19 @@ public class User implements Serializable {
this.username = username;
}
+ public boolean isBot() {
+ return isBot;
+ }
+
+ public void setBot(boolean bot) {
+ isBot = bot;
+ }
+
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("User{");
sb.append("id=").append(id);
+ sb.append(", is_bot='").append(isBot).append('\'');
sb.append(", firstName='").append(firstName).append('\'');
sb.append(", lastName='").append(lastName).append('\'');
sb.append(", username='").append(username).append('\'');
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/RestBotAPI.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/RestBotAPI.java
index 93642cf..422c3ff 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/RestBotAPI.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/RestBotAPI.java
@@ -27,7 +27,10 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
+import org.apache.camel.component.telegram.model.EditMessageLiveLocationMessage;
+import org.apache.camel.component.telegram.model.MessageResult;
import org.apache.camel.component.telegram.model.OutgoingTextMessage;
+import org.apache.camel.component.telegram.model.SendLocationMessage;
import org.apache.camel.component.telegram.model.UpdateResult;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
@@ -48,38 +51,47 @@ public interface RestBotAPI {
@QueryParam("limit") Integer limit,
@QueryParam("timeout") Integer timeoutSeconds);
-
@POST
@Path("/bot{authorizationToken}/sendMessage")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- void sendMessage(
+ MessageResult sendMessage(
@PathParam("authorizationToken") String authorizationToken,
OutgoingTextMessage message);
-
@POST
@Path("/bot{authorizationToken}/sendPhoto")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
- void sendPhoto(@PathParam("authorizationToken") String authorizationToken, List<Attachment> attachments);
-
+ MessageResult sendPhoto(@PathParam("authorizationToken") String authorizationToken, List<Attachment> attachments);
@POST
@Path("/bot{authorizationToken}/sendAudio")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
- void sendAudio(@PathParam("authorizationToken") String authorizationToken, List<Attachment> attachments);
+ MessageResult sendAudio(@PathParam("authorizationToken") String authorizationToken, List<Attachment> attachments);
@POST
@Path("/bot{authorizationToken}/sendVideo")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
- void sendVideo(@PathParam("authorizationToken") String authorizationToken, List<Attachment> attachments);
+ MessageResult sendVideo(@PathParam("authorizationToken") String authorizationToken, List<Attachment> attachments);
@POST
@Path("/bot{authorizationToken}/sendDocument")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
- void sendDocument(@PathParam("authorizationToken") String authorizationToken, List<Attachment> attachments);
+ MessageResult sendDocument(@PathParam("authorizationToken") String authorizationToken, List<Attachment> attachments);
+
+ @POST
+ @Path("/bot{authorizationToken}/sendLocation")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ MessageResult sendLocation(@PathParam("authorizationToken") String authorizationToken, SendLocationMessage location);
+
+ @POST
+ @Path("/bot{authorizationToken}/editMessageLiveLocation")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ MessageResult editMessageLiveLocation(@PathParam("authorizationToken") String authorizationToken, EditMessageLiveLocationMessage location);
}
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 465b253..d337ffc 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
@@ -27,14 +27,16 @@ import javax.ws.rs.core.MultivaluedMap;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
-
import org.apache.camel.component.telegram.TelegramService;
+import org.apache.camel.component.telegram.model.EditMessageLiveLocationMessage;
+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.OutgoingTextMessage;
import org.apache.camel.component.telegram.model.OutgoingVideoMessage;
+import org.apache.camel.component.telegram.model.SendLocationMessage;
import org.apache.camel.component.telegram.model.UpdateResult;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.apache.cxf.jaxrs.client.WebClient;
@@ -53,35 +55,45 @@ public class TelegramServiceRestBotAPIAdapter implements TelegramService {
WebClient.getConfig(this.api).getHttpConduit().getClient().setAllowChunking(false);
}
+ public TelegramServiceRestBotAPIAdapter(RestBotAPI api) {
+ this.api = api;
+ }
+
@Override
public UpdateResult getUpdates(String authorizationToken, Long offset, Integer limit, Integer timeoutSeconds) {
return api.getUpdates(authorizationToken, offset, limit, timeoutSeconds);
}
@Override
- public void sendMessage(String authorizationToken, OutgoingMessage message) {
+ public Object sendMessage(String authorizationToken, OutgoingMessage message) {
+ Object resultMessage;
+
if (message instanceof OutgoingTextMessage) {
- this.sendMessage(authorizationToken, (OutgoingTextMessage) message);
+ resultMessage = this.sendMessage(authorizationToken, (OutgoingTextMessage) message);
} else if (message instanceof OutgoingPhotoMessage) {
- this.sendMessage(authorizationToken, (OutgoingPhotoMessage) message);
+ resultMessage = this.sendMessage(authorizationToken, (OutgoingPhotoMessage) message);
} else if (message instanceof OutgoingAudioMessage) {
- this.sendMessage(authorizationToken, (OutgoingAudioMessage) message);
+ resultMessage = this.sendMessage(authorizationToken, (OutgoingAudioMessage) message);
} else if (message instanceof OutgoingVideoMessage) {
- this.sendMessage(authorizationToken, (OutgoingVideoMessage) message);
+ resultMessage = this.sendMessage(authorizationToken, (OutgoingVideoMessage) message);
} else if (message instanceof OutgoingDocumentMessage) {
- this.sendMessage(authorizationToken, (OutgoingDocumentMessage) message);
+ resultMessage = this.sendMessage(authorizationToken, (OutgoingDocumentMessage) message);
+ } else if (message instanceof SendLocationMessage) {
+ resultMessage = api.sendLocation(authorizationToken, (SendLocationMessage) message);
+ } else if (message instanceof EditMessageLiveLocationMessage) {
+ resultMessage = api.editMessageLiveLocation(authorizationToken, (EditMessageLiveLocationMessage) message);
} else {
throw new IllegalArgumentException("Unsupported message type " + (message != null ? message.getClass().getName() : null));
}
- }
-
- private void sendMessage(String authorizationToken, OutgoingTextMessage message) {
- api.sendMessage(authorizationToken, message);
+ return resultMessage;
}
+ private MessageResult sendMessage(String authorizationToken, OutgoingTextMessage message) {
+ return api.sendMessage(authorizationToken, message);
+ }
- private void sendMessage(String authorizationToken, OutgoingPhotoMessage message) {
+ private MessageResult sendMessage(String authorizationToken, OutgoingPhotoMessage message) {
List<Attachment> parts = new LinkedList<>();
fillCommonMediaParts(parts, message);
@@ -91,10 +103,10 @@ public class TelegramServiceRestBotAPIAdapter implements TelegramService {
parts.add(buildTextPart("caption", message.getCaption()));
}
- api.sendPhoto(authorizationToken, parts);
+ return api.sendPhoto(authorizationToken, parts);
}
- private void sendMessage(String authorizationToken, OutgoingAudioMessage message) {
+ private MessageResult sendMessage(String authorizationToken, OutgoingAudioMessage message) {
List<Attachment> parts = new LinkedList<>();
fillCommonMediaParts(parts, message);
@@ -110,10 +122,10 @@ public class TelegramServiceRestBotAPIAdapter implements TelegramService {
parts.add(buildTextPart("performer", message.getPerformer()));
}
- api.sendAudio(authorizationToken, parts);
+ return api.sendAudio(authorizationToken, parts);
}
- private void sendMessage(String authorizationToken, OutgoingVideoMessage message) {
+ private MessageResult sendMessage(String authorizationToken, OutgoingVideoMessage message) {
List<Attachment> parts = new LinkedList<>();
fillCommonMediaParts(parts, message);
@@ -132,10 +144,10 @@ public class TelegramServiceRestBotAPIAdapter implements TelegramService {
parts.add(buildTextPart("height", String.valueOf(message.getHeight())));
}
- api.sendVideo(authorizationToken, parts);
+ return api.sendVideo(authorizationToken, parts);
}
- private void sendMessage(String authorizationToken, OutgoingDocumentMessage message) {
+ private MessageResult sendMessage(String authorizationToken, OutgoingDocumentMessage message) {
List<Attachment> parts = new LinkedList<>();
fillCommonMediaParts(parts, message);
@@ -145,7 +157,7 @@ public class TelegramServiceRestBotAPIAdapter implements TelegramService {
parts.add(buildTextPart("caption", message.getCaption()));
}
- api.sendDocument(authorizationToken, parts);
+ return api.sendDocument(authorizationToken, parts);
}
private void fillCommonMediaParts(List<Attachment> parts, OutgoingMessage message) {
diff --git a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramConsumerMappingTest.java b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramConsumerMappingTest.java
index 005de59..dca3b99 100644
--- a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramConsumerMappingTest.java
+++ b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramConsumerMappingTest.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.telegram;
import java.time.Instant;
+import java.util.Date;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
@@ -26,6 +27,7 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.component.telegram.model.Chat;
import org.apache.camel.component.telegram.model.IncomingMessage;
+import org.apache.camel.component.telegram.model.MessageResult;
import org.apache.camel.component.telegram.model.UpdateResult;
import org.apache.camel.component.telegram.model.User;
import org.apache.camel.component.telegram.util.TelegramTestSupport;
@@ -93,8 +95,30 @@ public class TelegramConsumerMappingTest extends TelegramTestSupport {
}
+ @Test
+ public void testMessageResultMapping() {
+ MessageResult messageResult = getJSONResource("messages/updates-sendLocation.json", MessageResult.class);
+
+ assertEquals(true, messageResult.isOk());
+ assertEquals(true, messageResult.isOk());
+ assertEquals((Long) 33L, messageResult.getMessage().getMessageId());
+ assertEquals(Instant.ofEpochSecond(1548091564).getEpochSecond(), messageResult.getMessage().getDate().getEpochSecond());
+ assertEquals((Long) 665977497L, messageResult.getMessage().getFrom().getId());
+ assertEquals(true, messageResult.getMessage().getFrom().isBot());
+ assertEquals("camelbot", messageResult.getMessage().getFrom().getFirstName());
+ assertEquals("camel_component_bot", messageResult.getMessage().getFrom().getUsername());
+
+ assertEquals("-182520913", messageResult.getMessage().getChat().getId());
+ assertEquals("testgroup", messageResult.getMessage().getChat().getTitle());
+ assertEquals("group", messageResult.getMessage().getChat().getType());
+ assertEquals(true, messageResult.getMessage().getChat().isAllMembersAreAdministrators());
+
+ assertEquals(59.9386292, messageResult.getMessage().getLocation().getLatitude(), 1.0E-07);
+ assertEquals(30.3141308, messageResult.getMessage().getLocation().getLongitude(), 1.0E-07);
+ }
+
@Override
- protected RoutesBuilder createRouteBuilder() throws Exception {
+ protected RoutesBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
diff --git a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramProducerLocationTest.java b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramProducerLocationTest.java
new file mode 100644
index 0000000..75dba91
--- /dev/null
+++ b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramProducerLocationTest.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;
+
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.telegram.model.EditMessageLiveLocationMessage;
+import org.apache.camel.component.telegram.model.MessageResult;
+import org.apache.camel.component.telegram.model.SendLocationMessage;
+import org.apache.camel.component.telegram.service.RestBotAPI;
+import org.apache.camel.component.telegram.service.TelegramServiceRestBotAPIAdapter;
+import org.apache.camel.component.telegram.util.TelegramTestSupport;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests a producer that sends location information.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class TelegramProducerLocationTest extends TelegramTestSupport {
+
+ private final double latitude = 59.9386292;
+ private final double longitude = 30.3141308;
+
+ private TelegramService service;
+
+ @Mock
+ private RestBotAPI restBotAPI;
+
+ @Before
+ public void setUp() {
+ service = new TelegramServiceRestBotAPIAdapter(restBotAPI);
+ TelegramServiceProvider.get().setAlternativeService(service);
+ }
+
+ @Test
+ public void testSendLocation() {
+ MessageResult expected = new MessageResult();
+ expected.setOk(true);
+ when(restBotAPI.sendLocation(anyString(), any(SendLocationMessage.class))).thenReturn(expected);
+
+ SendLocationMessage msg = new SendLocationMessage(latitude, longitude);
+ MessageResult actual = (MessageResult) service.sendMessage("mock-token", msg);
+
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void testEditMessageLiveLocation() {
+ MessageResult expected = new MessageResult();
+ expected.setOk(true);
+ when(restBotAPI.editMessageLiveLocation(anyString(), any(EditMessageLiveLocationMessage.class))).thenReturn(expected);
+
+ EditMessageLiveLocationMessage msg = new EditMessageLiveLocationMessage(latitude, longitude);
+ MessageResult actual = (MessageResult) service.sendMessage("mock-token", msg);
+
+ assertEquals(expected, actual);
+ }
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:telegram").to("telegram:bots/mock-token?chatId=my-id");
+ }
+ };
+ }
+}
diff --git a/components/camel-telegram/src/test/resources/messages/updates-sendLocation.json b/components/camel-telegram/src/test/resources/messages/updates-sendLocation.json
new file mode 100644
index 0000000..ae4c091
--- /dev/null
+++ b/components/camel-telegram/src/test/resources/messages/updates-sendLocation.json
@@ -0,0 +1,23 @@
+{
+ "ok": true,
+ "result": {
+ "message_id": 33,
+ "from": {
+ "id": 665977497,
+ "is_bot": true,
+ "first_name": "camelbot",
+ "username": "camel_component_bot"
+ },
+ "chat": {
+ "id": -182520913,
+ "title": "testgroup",
+ "type": "group",
+ "all_members_are_administrators": true
+ },
+ "date": 1548091564,
+ "location": {
+ "latitude": 59.9386292,
+ "longitude": 30.3141308
+ }
+ }
+}
\ No newline at end of file