[camel] branch master updated: CAMEL-11541 Add sendVenue and stopMessageLiveLocation support

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[camel] branch master updated: CAMEL-11541 Add sendVenue and stopMessageLiveLocation support

acosentino
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 fb47ebd  CAMEL-11541 Add sendVenue and stopMessageLiveLocation support
fb47ebd is described below

commit fb47ebd3e2b67f2d7fabf1aa0325ebdec11d049c
Author: Denis Istomin <[hidden email]>
AuthorDate: Tue Feb 12 01:01:44 2019 +0500

    CAMEL-11541 Add sendVenue and stopMessageLiveLocation support
---
 .../src/main/docs/telegram-component.adoc          |  2 +
 .../telegram/model/SendLocationMessage.java        | 11 ----
 ...dLocationMessage.java => SendVenueMessage.java} | 65 +++++++++++++++++-----
 ...ge.java => StopMessageLiveLocationMessage.java} | 50 ++++++-----------
 .../component/telegram/service/RestBotAPI.java     | 18 +++++-
 .../service/TelegramServiceRestBotAPIAdapter.java  |  6 ++
 .../telegram/TelegramProducerLocationTest.java     | 26 +++++++++
 7 files changed, 119 insertions(+), 59 deletions(-)

diff --git a/components/camel-telegram/src/main/docs/telegram-component.adoc b/components/camel-telegram/src/main/docs/telegram-component.adoc
index bc928b0..1d9f3ba 100644
--- a/components/camel-telegram/src/main/docs/telegram-component.adoc
+++ b/components/camel-telegram/src/main/docs/telegram-component.adoc
@@ -194,6 +194,8 @@ The following message bodies are allowed for a producer endpoint (messages of ty
 | `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)
+| `StopMessageLiveLocationMessage` | To stop updating a live location message sent by the bot or via the bot (for inline bots) before live_period expires (stopMessageLiveLocation)
+| `SendVenueMessage` | To send information about a venue (sendVenue)
 | `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/model/SendLocationMessage.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/SendLocationMessage.java
index 67391a8..8556a50 100644
--- 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
@@ -28,9 +28,6 @@ public class SendLocationMessage extends OutgoingMessage {
     @JsonProperty("live_period")
     private Integer livePeriod;
 
-    @JsonProperty("disable_notification")
-    private boolean disableNotification;
-
     @JsonProperty("reply_markup")
     private ReplyKeyboardMarkup replyKeyboardMarkup;
 
@@ -51,14 +48,6 @@ public class SendLocationMessage extends OutgoingMessage {
         this.livePeriod = livePeriod;
     }
 
-    public boolean isDisableNotification() {
-        return disableNotification;
-    }
-
-    public void setDisableNotification(boolean disableNotification) {
-        this.disableNotification = disableNotification;
-    }
-
     public ReplyKeyboardMarkup getReplyKeyboardMarkup() {
         return replyKeyboardMarkup;
     }
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/SendVenueMessage.java
similarity index 59%
copy from components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/SendLocationMessage.java
copy to components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/SendVenueMessage.java
index 67391a8..6ff2d71 100644
--- 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/SendVenueMessage.java
@@ -18,25 +18,33 @@ package org.apache.camel.component.telegram.model;
 
 import com.fasterxml.jackson.annotation.JsonProperty;
 
-public class SendLocationMessage extends OutgoingMessage {
+public class SendVenueMessage extends OutgoingMessage {
     @JsonProperty("longitude")
     private double longitude;
 
     @JsonProperty("latitude")
     private double latitude;
 
-    @JsonProperty("live_period")
-    private Integer livePeriod;
+    @JsonProperty("title")
+    private String title;
 
-    @JsonProperty("disable_notification")
-    private boolean disableNotification;
+    @JsonProperty("address")
+    private String address;
+
+    @JsonProperty("foursquare_id")
+    private String foursquareId;
+
+    @JsonProperty("foursquare_type")
+    private String foursquareType;
 
     @JsonProperty("reply_markup")
     private ReplyKeyboardMarkup replyKeyboardMarkup;
 
-    public SendLocationMessage(double latitude, double longitude) {
+    public SendVenueMessage(double latitude, double longitude, String title, String address) {
         this.setLatitude(latitude);
         this.setLongitude(longitude);
+        this.setTitle(title);
+        this.setAddress(address);
     }
 
     public void setLatitude(double latitude) {
@@ -47,16 +55,44 @@ public class SendLocationMessage extends OutgoingMessage {
         this.longitude = longitude;
     }
 
-    public void setLivePeriod(Integer livePeriod) {
-        this.livePeriod = livePeriod;
+    public double getLongitude() {
+        return longitude;
+    }
+
+    public double getLatitude() {
+        return latitude;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getAddress() {
+        return address;
+    }
+
+    public void setAddress(String address) {
+        this.address = address;
+    }
+
+    public String getFoursquareId() {
+        return foursquareId;
+    }
+
+    public void setFoursquareId(String foursquareId) {
+        this.foursquareId = foursquareId;
     }
 
-    public boolean isDisableNotification() {
-        return disableNotification;
+    public String getFoursquareType() {
+        return foursquareType;
     }
 
-    public void setDisableNotification(boolean disableNotification) {
-        this.disableNotification = disableNotification;
+    public void setFoursquareType(String foursquareType) {
+        this.foursquareType = foursquareType;
     }
 
     public ReplyKeyboardMarkup getReplyKeyboardMarkup() {
@@ -72,7 +108,10 @@ public class SendLocationMessage extends OutgoingMessage {
         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(", title=").append(title).append('\'');
+        sb.append(", address=").append(address).append('\'');
+        sb.append(", foursquareId=").append(foursquareId).append('\'');
+        sb.append(", foursquareType=").append(foursquareType).append('\'');
         sb.append(", disableNotification=").append(disableNotification).append('\'');
         sb.append(", replyToMessageId=").append(replyToMessageId).append('\'');
         sb.append(", replyKeyboardMarkup=").append(replyKeyboardMarkup);
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/StopMessageLiveLocationMessage.java
similarity index 51%
copy from components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/SendLocationMessage.java
copy to components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/StopMessageLiveLocationMessage.java
index 67391a8..cc536e5 100644
--- 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/StopMessageLiveLocationMessage.java
@@ -18,45 +18,31 @@ package org.apache.camel.component.telegram.model;
 
 import com.fasterxml.jackson.annotation.JsonProperty;
 
-public class SendLocationMessage extends OutgoingMessage {
-    @JsonProperty("longitude")
-    private double longitude;
+public class StopMessageLiveLocationMessage extends OutgoingMessage {
 
-    @JsonProperty("latitude")
-    private double latitude;
+    @JsonProperty("message_id")
+    private Long messageId;
 
-    @JsonProperty("live_period")
-    private Integer livePeriod;
-
-    @JsonProperty("disable_notification")
-    private boolean disableNotification;
+    @JsonProperty("inline_message_id")
+    private String inlineMessageId;
 
     @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 Long getMessageId() {
+        return messageId;
     }
 
-    public void setLongitude(double longitude) {
-        this.longitude = longitude;
+    public void setMessageId(Long messageId) {
+        this.messageId = messageId;
     }
 
-    public void setLivePeriod(Integer livePeriod) {
-        this.livePeriod = livePeriod;
+    public String getInlineMessageId() {
+        return inlineMessageId;
     }
 
-    public boolean isDisableNotification() {
-        return disableNotification;
-    }
-
-    public void setDisableNotification(boolean disableNotification) {
-        this.disableNotification = disableNotification;
+    public void setInlineMessageId(String inlineMessageId) {
+        this.inlineMessageId = inlineMessageId;
     }
 
     public ReplyKeyboardMarkup getReplyKeyboardMarkup() {
@@ -69,14 +55,12 @@ public class SendLocationMessage extends OutgoingMessage {
 
     @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('\'');
+        final StringBuilder sb = new StringBuilder("StopMessageLiveLocationMessage{");
+        sb.append("message_id='").append(messageId).append('\'');
+        sb.append(", inlineMessageId=").append(inlineMessageId).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/service/RestBotAPI.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/RestBotAPI.java
index 422c3ff..26fcc72 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
@@ -31,6 +31,8 @@ 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.SendVenueMessage;
+import org.apache.camel.component.telegram.model.StopMessageLiveLocationMessage;
 import org.apache.camel.component.telegram.model.UpdateResult;
 import org.apache.cxf.jaxrs.ext.multipart.Attachment;
 
@@ -93,5 +95,17 @@ public interface RestBotAPI {
     @Path("/bot{authorizationToken}/editMessageLiveLocation")
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces(MediaType.APPLICATION_JSON)
-    MessageResult editMessageLiveLocation(@PathParam("authorizationToken") String authorizationToken, EditMessageLiveLocationMessage location);
-}
+    MessageResult editMessageLiveLocation(@PathParam("authorizationToken") String authorizationToken, EditMessageLiveLocationMessage message);
+
+    @POST
+    @Path("/bot{authorizationToken}/stopMessageLiveLocation")
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.APPLICATION_JSON)
+    MessageResult stopMessageLiveLocation(@PathParam("authorizationToken") String authorizationToken, StopMessageLiveLocationMessage message);
+
+    @POST
+    @Path("/bot{authorizationToken}/sendVenue")
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.APPLICATION_JSON)
+    MessageResult sendVenue(@PathParam("authorizationToken") String authorizationToken, SendVenueMessage location);
+}
\ No newline at end of file
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 d337ffc..639a8ad 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
@@ -37,6 +37,8 @@ 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.SendVenueMessage;
+import org.apache.camel.component.telegram.model.StopMessageLiveLocationMessage;
 import org.apache.camel.component.telegram.model.UpdateResult;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
 import org.apache.cxf.jaxrs.client.WebClient;
@@ -82,6 +84,10 @@ public class TelegramServiceRestBotAPIAdapter implements TelegramService {
             resultMessage = api.sendLocation(authorizationToken, (SendLocationMessage) message);
         } else if (message instanceof EditMessageLiveLocationMessage) {
             resultMessage = api.editMessageLiveLocation(authorizationToken, (EditMessageLiveLocationMessage) message);
+        } else if (message instanceof StopMessageLiveLocationMessage) {
+            resultMessage = api.stopMessageLiveLocation(authorizationToken, (StopMessageLiveLocationMessage) message);
+        } else if (message instanceof SendVenueMessage) {
+            resultMessage = api.sendVenue(authorizationToken, (SendVenueMessage) message);
         } else {
             throw new IllegalArgumentException("Unsupported message type " + (message != null ? message.getClass().getName() : null));
         }
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
index 75dba91..093c943 100644
--- 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
@@ -21,6 +21,8 @@ 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.model.SendVenueMessage;
+import org.apache.camel.component.telegram.model.StopMessageLiveLocationMessage;
 import org.apache.camel.component.telegram.service.RestBotAPI;
 import org.apache.camel.component.telegram.service.TelegramServiceRestBotAPIAdapter;
 import org.apache.camel.component.telegram.util.TelegramTestSupport;
@@ -67,6 +69,18 @@ public class TelegramProducerLocationTest extends TelegramTestSupport {
     }
 
     @Test
+    public void testSendVenue() {
+        MessageResult expected = new MessageResult();
+        expected.setOk(true);
+        when(restBotAPI.sendVenue(anyString(), any(SendVenueMessage.class))).thenReturn(expected);
+
+        SendVenueMessage msg = new SendVenueMessage(latitude, longitude, "title", "address");
+        MessageResult actual = (MessageResult) service.sendMessage("mock-token", msg);
+
+        assertEquals(expected, actual);
+    }
+
+    @Test
     public void testEditMessageLiveLocation() {
         MessageResult expected = new MessageResult();
         expected.setOk(true);
@@ -78,6 +92,18 @@ public class TelegramProducerLocationTest extends TelegramTestSupport {
         assertEquals(expected, actual);
     }
 
+    @Test
+    public void testStopMessageLiveLocation() {
+        MessageResult expected = new MessageResult();
+        expected.setOk(true);
+        when(restBotAPI.stopMessageLiveLocation(anyString(), any(StopMessageLiveLocationMessage.class))).thenReturn(expected);
+
+        StopMessageLiveLocationMessage msg = new StopMessageLiveLocationMessage();
+        MessageResult actual = (MessageResult) service.sendMessage("mock-token", msg);
+
+        assertEquals(expected, actual);
+    }
+
     @Override
     protected RoutesBuilder createRouteBuilder() {
         return new RouteBuilder() {