This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch camel-master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 264b2d3db62a2fdcd7824d2ede12c1e2c46652d2 Author: Peter Palaga <ppal...@redhat.com> AuthorDate: Mon Dec 23 16:46:52 2019 +0100 Fix #74 Telegram extension --- .../pages/list-of-camel-quarkus-extensions.adoc | 5 +- extensions/pom.xml | 1 + extensions/readme.adoc | 5 +- extensions/telegram/deployment/pom.xml | 83 +++++++++ .../telegram/deployment/TelegramProcessor.java | 82 +++++++++ extensions/telegram/pom.xml | 39 +++++ extensions/telegram/runtime/pom.xml | 106 ++++++++++++ .../component/telegram/TelegramRecorder.java | 31 ++++ .../main/resources/META-INF/quarkus-extension.yaml | 28 +++ integration-tests/pom.xml | 1 + integration-tests/telegram/README.adoc | 13 ++ integration-tests/telegram/pom.xml | 165 ++++++++++++++++++ .../component/telegram/it/TelegramResource.java | 157 +++++++++++++++++ .../component/telegram/it/TelegramRoutes.java | 77 +++++++++ .../src/main/resources/application.properties | 34 ++++ .../mock-messages/editMessageLiveLocation.json | 24 +++ .../main/resources/mock-messages/getUpdates.json | 41 +++++ .../main/resources/mock-messages/sendAudio.json | 25 +++ .../main/resources/mock-messages/sendDocument.json | 24 +++ .../main/resources/mock-messages/sendLocation.json | 23 +++ .../main/resources/mock-messages/sendMessage.json | 20 +++ .../main/resources/mock-messages/sendPhoto.json | 27 +++ .../main/resources/mock-messages/sendVenue.json | 31 ++++ .../main/resources/mock-messages/sendVideo.json | 33 ++++ .../mock-messages/stopMessageLiveLocation.json | 24 +++ .../quarkus/component/telegram/it/TelegramIT.java | 24 +++ .../component/telegram/it/TelegramTest.java | 187 +++++++++++++++++++++ .../src/test/resources/camel-quarkus-rocks.mp3 | Bin 0 -> 9657 bytes .../src/test/resources/camel-quarkus-rocks.mp4 | Bin 0 -> 27845 bytes .../src/test/resources/camel-quarkus-rocks.pdf | Bin 0 -> 7638 bytes .../src/test/resources/camel-quarkus-rocks.png | Bin 0 -> 264 bytes poms/bom/pom.xml | 15 ++ 32 files changed, 1323 insertions(+), 2 deletions(-) diff --git a/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc b/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc index 3c4999e..a0128cd 100644 --- a/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc +++ b/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc @@ -18,7 +18,7 @@ In case you are missing some Camel feature in the list: == Camel Components // components: START -Number of Camel components: 64 in 55 JAR artifacts (0 deprecated) +Number of Camel components: 65 in 56 JAR artifacts (0 deprecated) [width="100%",cols="4,1,5",options="header"] |=== @@ -195,6 +195,9 @@ Number of Camel components: 64 in 55 JAR artifacts (0 deprecated) | xref:extensions/stream.adoc[Stream] (camel-quarkus-stream) + `stream:kind` | 1.2.0 | The stream: component provides access to the system-in, system-out and system-err streams as well as allowing streaming of file. +| link:https://camel.apache.org/components/latest/telegram-component.html[Telegram] (camel-quarkus-telegram) + +`telegram:type` | 1.0.0 | The telegram component provides access to the Telegram Bot API. + | link:https://camel.apache.org/components/latest/timer-component.html[Timer] (camel-quarkus-timer) + `timer:timerName` | 0.2.0 | The timer component is used for generating message exchanges when a timer fires. diff --git a/extensions/pom.xml b/extensions/pom.xml index 2ece525..1106c36 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -107,6 +107,7 @@ <module>stream</module> <module>tagsoup</module> <module>tarfile</module> + <module>telegram</module> <module>timer</module> <module>twitter</module> <module>validator</module> diff --git a/extensions/readme.adoc b/extensions/readme.adoc index 49f41c3..22569de 100644 --- a/extensions/readme.adoc +++ b/extensions/readme.adoc @@ -5,7 +5,7 @@ Apache Camel Quarkus supports the following Camel artifacts as Quarkus Extension == Camel Components // components: START -Number of Camel components: 64 in 55 JAR artifacts (0 deprecated) +Number of Camel components: 65 in 56 JAR artifacts (0 deprecated) [width="100%",cols="4,1,5",options="header"] |=== @@ -182,6 +182,9 @@ Number of Camel components: 64 in 55 JAR artifacts (0 deprecated) | xref:extensions/stream.adoc[Stream] (camel-quarkus-stream) + `stream:kind` | 1.2.0 | The stream: component provides access to the system-in, system-out and system-err streams as well as allowing streaming of file. +| link:https://camel.apache.org/components/latest/telegram-component.html[Telegram] (camel-quarkus-telegram) + +`telegram:type` | 1.0.0 | The telegram component provides access to the Telegram Bot API. + | link:https://camel.apache.org/components/latest/timer-component.html[Timer] (camel-quarkus-timer) + `timer:timerName` | 0.2.0 | The timer component is used for generating message exchanges when a timer fires. diff --git a/extensions/telegram/deployment/pom.xml b/extensions/telegram/deployment/pom.xml new file mode 100644 index 0000000..231703c --- /dev/null +++ b/extensions/telegram/deployment/pom.xml @@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-telegram-parent</artifactId> + <version>1.1.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-telegram-deployment</artifactId> + <name>Camel Quarkus :: Telegram :: Deployment</name> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-bom-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-core-deployment</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-ahc-deployment</artifactId> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-jackson-deployment</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-telegram</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <annotationProcessorPaths> + <path> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-extension-processor</artifactId> + <version>${quarkus.version}</version> + </path> + </annotationProcessorPaths> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/extensions/telegram/deployment/src/main/java/org/apache/camel/quarkus/component/telegram/deployment/TelegramProcessor.java b/extensions/telegram/deployment/src/main/java/org/apache/camel/quarkus/component/telegram/deployment/TelegramProcessor.java new file mode 100644 index 0000000..2535a74 --- /dev/null +++ b/extensions/telegram/deployment/src/main/java/org/apache/camel/quarkus/component/telegram/deployment/TelegramProcessor.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.quarkus.component.telegram.deployment; + +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.annotations.ExecutionTime; +import io.quarkus.deployment.annotations.Record; +import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem; +import io.quarkus.deployment.builditem.FeatureBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; +import org.apache.camel.quarkus.component.telegram.TelegramRecorder; +import org.apache.camel.quarkus.core.deployment.CamelBeanBuildItem; + +class TelegramProcessor { + + private static final String FEATURE = "camel-telegram"; + + @BuildStep + FeatureBuildItem feature() { + return new FeatureBuildItem(FEATURE); + } + + @Record(ExecutionTime.STATIC_INIT) + @BuildStep + CamelBeanBuildItem telegramComponent(TelegramRecorder recorder) { + return new CamelBeanBuildItem( + "telegram", + "org.apache.camel.component.telegram.TelegramComponent", + recorder.createTelegramComponent()); + } + + @BuildStep + ExtensionSslNativeSupportBuildItem activateSslNativeSupport() { + return new ExtensionSslNativeSupportBuildItem(FEATURE); + } + + @BuildStep + ReflectiveClassBuildItem reflectiveMethodsAndFields() { + return new ReflectiveClassBuildItem(true, true, + "org.apache.camel.component.telegram.model.Chat", + "org.apache.camel.component.telegram.model.EditMessageLiveLocationMessage", + "org.apache.camel.component.telegram.model.IncomingAudio", + "org.apache.camel.component.telegram.model.IncomingDocument", + "org.apache.camel.component.telegram.model.IncomingMessage", + "org.apache.camel.component.telegram.model.IncomingPhotoSize", + "org.apache.camel.component.telegram.model.IncomingVideo", + "org.apache.camel.component.telegram.model.InlineKeyboardButton", + "org.apache.camel.component.telegram.model.Location", + "org.apache.camel.component.telegram.model.MessageResult", + "org.apache.camel.component.telegram.model.OutgoingAudioMessage", + "org.apache.camel.component.telegram.model.OutgoingDocumentMessage", + "org.apache.camel.component.telegram.model.OutgoingMessage", + "org.apache.camel.component.telegram.model.OutgoingPhotoMessage", + "org.apache.camel.component.telegram.model.OutgoingTextMessage", + "org.apache.camel.component.telegram.model.OutgoingVideoMessage", + "org.apache.camel.component.telegram.model.ReplyKeyboardMarkup", + "org.apache.camel.component.telegram.model.SendLocationMessage", + "org.apache.camel.component.telegram.model.SendVenueMessage", + "org.apache.camel.component.telegram.model.StopMessageLiveLocationMessage", + "org.apache.camel.component.telegram.model.UnixTimestampDeserializer", + "org.apache.camel.component.telegram.model.Update", + "org.apache.camel.component.telegram.model.UpdateResult", + "org.apache.camel.component.telegram.model.User", + "org.apache.camel.component.telegram.model.WebhookInfo", + "org.apache.camel.component.telegram.model.WebhookResult"); + } + +} diff --git a/extensions/telegram/pom.xml b/extensions/telegram/pom.xml new file mode 100644 index 0000000..70603ba --- /dev/null +++ b/extensions/telegram/pom.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-build-parent</artifactId> + <version>1.1.0-SNAPSHOT</version> + <relativePath>../../poms/build-parent/pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-telegram-parent</artifactId> + <name>Camel Quarkus :: Telegram</name> + <packaging>pom</packaging> + + <modules> + <module>deployment</module> + <module>runtime</module> + </modules> +</project> diff --git a/extensions/telegram/runtime/pom.xml b/extensions/telegram/runtime/pom.xml new file mode 100644 index 0000000..0679852 --- /dev/null +++ b/extensions/telegram/runtime/pom.xml @@ -0,0 +1,106 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-telegram-parent</artifactId> + <version>1.1.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-telegram</artifactId> + <name>Camel Quarkus :: Telegram :: Runtime</name> + <description>Telegram Chat Support</description> + + <properties> + <firstVersion>1.0.0</firstVersion> + </properties> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-bom</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-support-ahc</artifactId> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-jackson</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-telegram</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpasyncclient</artifactId> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.jboss.logging</groupId> + <artifactId>commons-logging-jboss-logging</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-bootstrap-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <annotationProcessorPaths> + <path> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-extension-processor</artifactId> + <version>${quarkus.version}</version> + </path> + </annotationProcessorPaths> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/extensions/telegram/runtime/src/main/java/org/apache/camel/quarkus/component/telegram/TelegramRecorder.java b/extensions/telegram/runtime/src/main/java/org/apache/camel/quarkus/component/telegram/TelegramRecorder.java new file mode 100644 index 0000000..5a5e55a --- /dev/null +++ b/extensions/telegram/runtime/src/main/java/org/apache/camel/quarkus/component/telegram/TelegramRecorder.java @@ -0,0 +1,31 @@ +/* + * 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.quarkus.component.telegram; + +import io.quarkus.runtime.RuntimeValue; +import io.quarkus.runtime.annotations.Recorder; +import org.apache.camel.component.telegram.TelegramComponent; + +@Recorder +public class TelegramRecorder { + + public RuntimeValue<TelegramComponent> createTelegramComponent() { + final TelegramComponent telegramComponent = new TelegramComponent(); + return new RuntimeValue<>(telegramComponent); + } + +} diff --git a/extensions/telegram/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/telegram/runtime/src/main/resources/META-INF/quarkus-extension.yaml new file mode 100644 index 0000000..a799cd2 --- /dev/null +++ b/extensions/telegram/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -0,0 +1,28 @@ +# +# 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. +# + +--- +name: "Camel Quarkus Telegram" +description: "Camel Telegram support" +metadata: + keywords: + - "camel" + - "chat" + - "telegram" + guide: "https://quarkus.io/guides/camel" + categories: + - "integration" \ No newline at end of file diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 0fba9c4..3d050ea 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -213,6 +213,7 @@ <module>stream</module> <module>tagsoup</module> <module>tarfile</module> + <module>telegram</module> <module>twitter</module> <module>validator</module> <module>xslt</module> diff --git a/integration-tests/telegram/README.adoc b/integration-tests/telegram/README.adoc new file mode 100644 index 0000000..259e493 --- /dev/null +++ b/integration-tests/telegram/README.adoc @@ -0,0 +1,13 @@ +== Camel Quarkus Telegram Integration Tests + +A work in progress, see https://github.com/apache/camel-quarkus/issues/74 + +To run `camel-quarkus-telegram` integration tests, you must first create a Telegram bot following this guide: https://www.nicolaferraro.me/2016/05/27/creating-a-telegram-bot-in-5-minutes-with-apache-camel/ . + +Then set the following environment variables: + +[source,shell] +---- +$ export TELEGRAM_AUTHORIZATION_TOKEN=my-autorization-token +$ export TELEGRAM_CHAT_ID=my-chatId +---- diff --git a/integration-tests/telegram/pom.xml b/integration-tests/telegram/pom.xml new file mode 100644 index 0000000..393524b --- /dev/null +++ b/integration-tests/telegram/pom.xml @@ -0,0 +1,165 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-tests</artifactId> + <version>1.1.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-quarkus-integration-test-telegram</artifactId> + <name>Camel Quarkus :: Integration Tests :: Telegram</name> + <description>Integration tests for Camel Quarkus Telegram extension</description> + + <properties> + <!-- mvnd, a.k.a. Maven Daemon: https://github.com/gnodet/mvnd --> + <!-- The following rule tells mvnd to build the listed deployment modules before this module. --> + <!-- This is important because mvnd builds modules in parallel by default. The deployment modules are not --> + <!-- explicit dependencies of this module in the Maven sense, although they are required by the Quarkus Maven plugin. --> + <!-- Please update rule whenever you change the dependencies of this module by running --> + <!-- mvn process-resources -Pformat from the root directory --> + <mvnd.builder.rule>camel-quarkus-attachments-deployment,camel-quarkus-platform-http-deployment,camel-quarkus-support-policy-deployment,camel-quarkus-telegram-deployment</mvnd.builder.rule> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-telegram</artifactId> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-resteasy</artifactId> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-resteasy-jackson</artifactId> + </dependency> + + <!-- To serve the mock Telegram API --> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-platform-http</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-attachments</artifactId> + </dependency> + + <!-- test dependencies --> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-test-support</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit5</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.rest-assured</groupId> + <artifactId>rest-assured</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.awaitility</groupId> + <artifactId>awaitility</artifactId> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-core</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-maven-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>build</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <id>native</id> + <activation> + <property> + <name>native</name> + </property> + </activation> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + <configuration> + <systemProperties> + <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path> + </systemProperties> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-maven-plugin</artifactId> + <executions> + <execution> + <id>native-image</id> + <goals> + <goal>native-image</goal> + </goals> + <configuration> + <reportErrorsAtRuntime>false</reportErrorsAtRuntime> + <cleanupServer>true</cleanupServer> + <enableServer>false</enableServer> + <dumpProxies>false</dumpProxies> + <graalvmHome>${graalvmHome}</graalvmHome> + <disableReports>true</disableReports> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> + +</project> diff --git a/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/TelegramResource.java b/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/TelegramResource.java new file mode 100644 index 0000000..52b929c --- /dev/null +++ b/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/TelegramResource.java @@ -0,0 +1,157 @@ +/* + * 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.quarkus.component.telegram.it; + +import java.net.URI; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.camel.ConsumerTemplate; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.component.telegram.TelegramConstants; +import org.apache.camel.component.telegram.TelegramMediaType; +import org.apache.camel.component.telegram.model.EditMessageLiveLocationMessage; +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.eclipse.microprofile.config.inject.ConfigProperty; +import org.jboss.logging.Logger; + +@Path("/telegram") +@ApplicationScoped +public class TelegramResource { + + private static final Logger log = Logger.getLogger(TelegramResource.class); + + @Inject + ProducerTemplate producerTemplate; + + @Inject + ConsumerTemplate consumerTemplate; + + @ConfigProperty(name = "telegram.chatId") + String chatId; + + @Path("/messages") + @GET + @Produces(MediaType.TEXT_PLAIN) + public String getMessages() { + final String messages = consumerTemplate.receiveBodyNoWait("telegram://bots", String.class); + log.infof("Received telegram messages: %s", messages); + return messages; + } + + @Path("/messages") + @POST + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public Response postMessage(String message) throws Exception { + producerTemplate.requestBody(String.format("telegram://bots?chatId=%s", chatId), message); + log.infof("Sent a message to telegram %s", message); + return Response + .created(new URI(String.format("https://telegram.org/"))) + .build(); + } + + @Path("/media") + @POST + @Produces(MediaType.TEXT_PLAIN) + public Response postMedia(@HeaderParam("Content-type") String type, byte[] message) throws Exception { + final TelegramMediaType telegramMediaType; + if (type != null && type.startsWith("image/")) { + telegramMediaType = TelegramMediaType.PHOTO_PNG; + } else if (type != null && type.startsWith("audio/")) { + telegramMediaType = TelegramMediaType.AUDIO; + } else if (type != null && type.startsWith("video/")) { + telegramMediaType = TelegramMediaType.VIDEO; + } else if (type != null && type.startsWith("application/pdf")) { + telegramMediaType = TelegramMediaType.DOCUMENT; + } else { + return Response.status(415, "Unsupported content type " + type).build(); + } + + producerTemplate.requestBodyAndHeader( + String.format("telegram://bots?chatId=%s", chatId), + message, + TelegramConstants.TELEGRAM_MEDIA_TYPE, + telegramMediaType); + log.infof("Sent a message to telegram %s", message); + return Response + .created(new URI(String.format("https://telegram.org/"))) + .build(); + } + + @Path("/send-location") + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response sendLocation(SendLocationMessage message) throws Exception { + final Object result = producerTemplate.requestBody(String.format("telegram://bots?chatId=%s", chatId), message); + log.infof("Sent a message to telegram %s", message); + return Response + .created(new URI(String.format("https://telegram.org/"))) + .entity(result) + .build(); + } + + @Path("/edit-location") + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response editLocation(EditMessageLiveLocationMessage message) throws Exception { + producerTemplate.requestBody(String.format("telegram://bots?chatId=%s", chatId), message); + log.infof("Sent a message to telegram %s", message); + return Response + .created(new URI(String.format("https://telegram.org/"))) + .build(); + } + + @Path("/stop-location") + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response stopLocation(StopMessageLiveLocationMessage message) throws Exception { + producerTemplate.requestBody(String.format("telegram://bots?chatId=%s", chatId), message); + log.infof("Sent a message to telegram %s", message); + return Response + .created(new URI(String.format("https://telegram.org/"))) + .build(); + } + + @Path("/venue") + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response venue(SendVenueMessage message) throws Exception { + final Object result = producerTemplate.requestBody(String.format("telegram://bots?chatId=%s", chatId), message); + log.infof("Sent a message to telegram %s", message); + return Response + .created(new URI(String.format("https://telegram.org/"))) + .entity(result) + .build(); + } + +} diff --git a/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/TelegramRoutes.java b/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/TelegramRoutes.java new file mode 100644 index 0000000..f11b2cf --- /dev/null +++ b/integration-tests/telegram/src/main/java/org/apache/camel/quarkus/component/telegram/it/TelegramRoutes.java @@ -0,0 +1,77 @@ +/* + * 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.quarkus.component.telegram.it; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.util.IOHelper; + +public class TelegramRoutes extends RouteBuilder { + + @Override + public void configure() throws Exception { + + /* Mock Telegram API */ + from("platform-http:/bot{authToken}/getUpdates?httpMethodRestrict=GET") + .process(new ResourceSupplier("mock-messages/getUpdates.json")); + Arrays.asList( + "sendMessage", + "sendAudio", + "sendVideo", + "sendDocument", + "sendPhoto", + "sendVenue", + "sendLocation", + "stopMessageLiveLocation").stream() + .forEach(endpoint -> { + from("platform-http:/{authToken}/" + endpoint + "?httpMethodRestrict=POST") + .process(new ResourceSupplier("mock-messages/" + endpoint + ".json")); + }); + + } + + static class ResourceSupplier implements Processor { + private final byte[] bytes; + + public ResourceSupplier(String path) { + try (ByteArrayOutputStream out = new ByteArrayOutputStream(IOHelper.DEFAULT_BUFFER_SIZE); + InputStream in = getClass().getClassLoader().getResourceAsStream(path)) { + IOHelper.copy(in, out, IOHelper.DEFAULT_BUFFER_SIZE); + this.bytes = out.toByteArray(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public void process(Exchange exchange) throws Exception { + final Message m = exchange.getMessage(); + m.setBody(bytes); + m.setHeader("Content-Length", bytes.length); + m.setHeader("Content-Type", "application/json; charset=UTF-8"); + } + + } + +} diff --git a/integration-tests/telegram/src/main/resources/application.properties b/integration-tests/telegram/src/main/resources/application.properties new file mode 100644 index 0000000..08f9610 --- /dev/null +++ b/integration-tests/telegram/src/main/resources/application.properties @@ -0,0 +1,34 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- +# +# Quarkus +# +quarkus.log.file.enable = false + +quarkus.log.category."org.apache.camel.support.DefaultComponent".level = TRACE +#quarkus.log.category."org.asynchttpclient".level = TRACE +#quarkus.log.category."org.apache.camel.component.telegram.TelegramComponent".level = TRACE +# You can check in this directory what requests the client is sending when you run against the mock Telegram API +quarkus.http.body.uploads-directory=target/uploads + +quarkus.native.additional-build-args = -H:IncludeResources=.*mock-messages/.* +# +# Camel :: Telegram +# +camel.component.telegram.authorizationToken={{env:TELEGRAM_AUTHORIZATION_TOKEN:default-dummy-token}} +camel.component.telegram.baseUri={{env:TELEGRAM_BASE_URI:https://api.telegram.org}} +telegram.chatId={{env:TELEGRAM_CHAT_ID:-1}} diff --git a/integration-tests/telegram/src/main/resources/mock-messages/editMessageLiveLocation.json b/integration-tests/telegram/src/main/resources/mock-messages/editMessageLiveLocation.json new file mode 100644 index 0000000..a6a060d --- /dev/null +++ b/integration-tests/telegram/src/main/resources/mock-messages/editMessageLiveLocation.json @@ -0,0 +1,24 @@ +{ + "ok": true, + "result": { + "message_id": 938, + "from": { + "id": 770882310, + "is_bot": true, + "first_name": "camelDemoBot", + "username": "camelDemoBot" + }, + "chat": { + "id": 434822960, + "first_name": "Peter", + "last_name": "Palaga", + "type": "private" + }, + "date": 1576249600, + "edit_date": 1576249601, + "location": { + "latitude": 29.974934, + "longitude": 31.131109 + } + } +} \ No newline at end of file diff --git a/integration-tests/telegram/src/main/resources/mock-messages/getUpdates.json b/integration-tests/telegram/src/main/resources/mock-messages/getUpdates.json new file mode 100644 index 0000000..85fbd55 --- /dev/null +++ b/integration-tests/telegram/src/main/resources/mock-messages/getUpdates.json @@ -0,0 +1,41 @@ +{ + "ok": true, + "result": [ + { + "update_id": 525704898, + "message": { + "message_id": 179, + "from": { + "id": 1585844777, + "first_name": "John", + "last_name": "Doe" + }, + "chat": { + "id": -45658, + "title": "A chat group", + "type": "group" + }, + "date": 1463436626, + "text": "a message" + } + }, + { + "update_id": 525704899, + "message": { + "message_id": 180, + "from": { + "id": 1585844777, + "first_name": "John", + "last_name": "Doe" + }, + "chat": { + "id": -45658, + "title": "A chat group", + "type": "group" + }, + "date": 1463466626, + "text": "another message" + } + } + ] +} \ No newline at end of file diff --git a/integration-tests/telegram/src/main/resources/mock-messages/sendAudio.json b/integration-tests/telegram/src/main/resources/mock-messages/sendAudio.json new file mode 100644 index 0000000..ed4ac2d --- /dev/null +++ b/integration-tests/telegram/src/main/resources/mock-messages/sendAudio.json @@ -0,0 +1,25 @@ +{ + "ok": true, + "result": { + "message_id": 932, + "from": { + "id": 770882310, + "is_bot": true, + "first_name": "camelDemoBot", + "username": "camelDemoBot" + }, + "chat": { + "id": 434822960, + "first_name": "Peter", + "last_name": "Palaga", + "type": "private" + }, + "date": 1576249599, + "audio": { + "duration": 1, + "mime_type": "audio/mpeg", + "file_id": "CQADBAAD5QUAAmcaoVMYrfWhEfLFTBYE", + "file_size": 9657 + } + } +} \ No newline at end of file diff --git a/integration-tests/telegram/src/main/resources/mock-messages/sendDocument.json b/integration-tests/telegram/src/main/resources/mock-messages/sendDocument.json new file mode 100644 index 0000000..f352d13 --- /dev/null +++ b/integration-tests/telegram/src/main/resources/mock-messages/sendDocument.json @@ -0,0 +1,24 @@ +{ + "ok": true, + "result": { + "message_id": 934, + "from": { + "id": 770882310, + "is_bot": true, + "first_name": "camelDemoBot", + "username": "camelDemoBot" + }, + "chat": { + "id": 434822960, + "first_name": "Peter", + "last_name": "Palaga", + "type": "private" + }, + "date": 1576249600, + "document": { + "file_name": "file", + "file_id": "BQADBAAD5wUAAmcaoVNbRjnV8IcCmhYE", + "file_size": 7638 + } + } +} \ No newline at end of file diff --git a/integration-tests/telegram/src/main/resources/mock-messages/sendLocation.json b/integration-tests/telegram/src/main/resources/mock-messages/sendLocation.json new file mode 100644 index 0000000..5b645a1 --- /dev/null +++ b/integration-tests/telegram/src/main/resources/mock-messages/sendLocation.json @@ -0,0 +1,23 @@ +{ + "ok": true, + "result": { + "message_id": 938, + "from": { + "id": 770882310, + "is_bot": true, + "first_name": "camelDemoBot", + "username": "camelDemoBot" + }, + "chat": { + "id": 434822960, + "first_name": "Peter", + "last_name": "Palaga", + "type": "private" + }, + "date": 1576249600, + "location": { + "latitude": 29.974830, + "longitude": 31.138579 + } + } +} \ No newline at end of file diff --git a/integration-tests/telegram/src/main/resources/mock-messages/sendMessage.json b/integration-tests/telegram/src/main/resources/mock-messages/sendMessage.json new file mode 100644 index 0000000..8f37da2 --- /dev/null +++ b/integration-tests/telegram/src/main/resources/mock-messages/sendMessage.json @@ -0,0 +1,20 @@ +{ + "ok": true, + "result": { + "message_id": 937, + "from": { + "id": 770882310, + "is_bot": true, + "first_name": "camelDemoBot", + "username": "camelDemoBot" + }, + "chat": { + "id": 434822960, + "first_name": "Peter", + "last_name": "Palaga", + "type": "private" + }, + "date": 1576249600, + "text": "A message from camel-quarkus-telegram ffdcc8ef72a34053a3e75daec74676a9" + } +} \ No newline at end of file diff --git a/integration-tests/telegram/src/main/resources/mock-messages/sendPhoto.json b/integration-tests/telegram/src/main/resources/mock-messages/sendPhoto.json new file mode 100644 index 0000000..8523d11 --- /dev/null +++ b/integration-tests/telegram/src/main/resources/mock-messages/sendPhoto.json @@ -0,0 +1,27 @@ +{ + "ok": true, + "result": { + "message_id": 935, + "from": { + "id": 770882310, + "is_bot": true, + "first_name": "camelDemoBot", + "username": "camelDemoBot" + }, + "chat": { + "id": 434822960, + "first_name": "Peter", + "last_name": "Palaga", + "type": "private" + }, + "date": 1576249600, + "photo": [ + { + "file_id": "AgADBAADYbExG2caoVPPY5I2XKLPM3lKqBsABAEAAwIAA20AA80nBQABFgQ", + "file_size": 1005, + "width": 108, + "height": 10 + } + ] + } +} \ No newline at end of file diff --git a/integration-tests/telegram/src/main/resources/mock-messages/sendVenue.json b/integration-tests/telegram/src/main/resources/mock-messages/sendVenue.json new file mode 100644 index 0000000..f098ac2 --- /dev/null +++ b/integration-tests/telegram/src/main/resources/mock-messages/sendVenue.json @@ -0,0 +1,31 @@ +{ + "ok": true, + "result": { + "message_id": 936, + "from": { + "id": 770882310, + "is_bot": true, + "first_name": "camelDemoBot", + "username": "camelDemoBot" + }, + "chat": { + "id": 434822960, + "first_name": "Peter", + "last_name": "Palaga", + "type": "private" + }, + "date": 1576249600, + "location": { + "latitude": 29.977826, + "longitude": 31.136330 + }, + "venue": { + "location": { + "latitude": 29.977826, + "longitude": 31.136330 + }, + "title": "Pyramid of Queen Henutsen", + "address": "El-Hussein Ibn Ali Ln, Nazlet El-Semman, Al Haram, Giza Governorate, Egypt" + } + } +} \ No newline at end of file diff --git a/integration-tests/telegram/src/main/resources/mock-messages/sendVideo.json b/integration-tests/telegram/src/main/resources/mock-messages/sendVideo.json new file mode 100644 index 0000000..4f8d0ef --- /dev/null +++ b/integration-tests/telegram/src/main/resources/mock-messages/sendVideo.json @@ -0,0 +1,33 @@ +{ + "ok": true, + "result": { + "message_id": 933, + "from": { + "id": 770882310, + "is_bot": true, + "first_name": "camelDemoBot", + "username": "camelDemoBot" + }, + "chat": { + "id": 434822960, + "first_name": "Peter", + "last_name": "Palaga", + "type": "private" + }, + "date": 1576249600, + "video": { + "duration": 4, + "width": 108, + "height": 10, + "mime_type": "video/mp4", + "thumb": { + "file_id": "AAQEAAPmBQACZxqhU8LAVawXPI5dMWO3GwAEAQAHbQADcxQAAhYE", + "file_size": 991, + "width": 108, + "height": 10 + }, + "file_id": "BAADBAAD5gUAAmcaoVPCwFWsFzyOXRYE", + "file_size": 27845 + } + } +} \ No newline at end of file diff --git a/integration-tests/telegram/src/main/resources/mock-messages/stopMessageLiveLocation.json b/integration-tests/telegram/src/main/resources/mock-messages/stopMessageLiveLocation.json new file mode 100644 index 0000000..a6a060d --- /dev/null +++ b/integration-tests/telegram/src/main/resources/mock-messages/stopMessageLiveLocation.json @@ -0,0 +1,24 @@ +{ + "ok": true, + "result": { + "message_id": 938, + "from": { + "id": 770882310, + "is_bot": true, + "first_name": "camelDemoBot", + "username": "camelDemoBot" + }, + "chat": { + "id": 434822960, + "first_name": "Peter", + "last_name": "Palaga", + "type": "private" + }, + "date": 1576249600, + "edit_date": 1576249601, + "location": { + "latitude": 29.974934, + "longitude": 31.131109 + } + } +} \ No newline at end of file diff --git a/integration-tests/telegram/src/test/java/org/apache/camel/quarkus/component/telegram/it/TelegramIT.java b/integration-tests/telegram/src/test/java/org/apache/camel/quarkus/component/telegram/it/TelegramIT.java new file mode 100644 index 0000000..23a735e --- /dev/null +++ b/integration-tests/telegram/src/test/java/org/apache/camel/quarkus/component/telegram/it/TelegramIT.java @@ -0,0 +1,24 @@ +/* + * 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.quarkus.component.telegram.it; + +import io.quarkus.test.junit.NativeImageTest; + +@NativeImageTest +class TelegramIT extends TelegramTest { + +} diff --git a/integration-tests/telegram/src/test/java/org/apache/camel/quarkus/component/telegram/it/TelegramTest.java b/integration-tests/telegram/src/test/java/org/apache/camel/quarkus/component/telegram/it/TelegramTest.java new file mode 100644 index 0000000..bf3e88e --- /dev/null +++ b/integration-tests/telegram/src/test/java/org/apache/camel/quarkus/component/telegram/it/TelegramTest.java @@ -0,0 +1,187 @@ +/* + * 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.quarkus.component.telegram.it; + +import java.io.IOException; +import java.io.InputStream; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import io.quarkus.test.common.QuarkusTestResource; +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import io.restassured.http.ContentType; +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.quarkus.test.TrustStoreResource; +import org.awaitility.Awaitility; +import org.jboss.logging.Logger; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; + +import static org.hamcrest.Matchers.both; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.lessThan; + +@QuarkusTest +@QuarkusTestResource(TrustStoreResource.class) +@EnabledIfEnvironmentVariable(named = "TELEGRAM_AUTHORIZATION_TOKEN", matches = "[^ ]+") +public class TelegramTest { + + private static final Logger LOG = Logger.getLogger(TelegramTest.class); + + @Test + public void postText() { + final String uuid = UUID.randomUUID().toString().replace("-", ""); + final String msg = String.format("A message from camel-quarkus-telegram %s", uuid); + + /* Send a message */ + RestAssured.given() + .contentType(ContentType.TEXT) + .body(msg) + .post("/telegram/messages") + .then() + .statusCode(201); + + } + + @Test + public void getText() { + /* Telegram bots by design see neither their own messages nor other bots' messages. + * So receiving messages is currently possible only if you ping the bot manually. + * If you do so, you should see your messages in the test log. */ + for (int i = 0; i < 5; i++) { // For some reason several iterations are needed to pick the messages + final String body = RestAssured.get("/telegram/messages") + .then() + .statusCode(is(both(greaterThanOrEqualTo(200)).and(lessThan(300)))) + .extract().body().asString(); + LOG.info("Telegram Bot received messages: " + body); + } + } + + @Test + public void png() throws IOException { + try (InputStream in = getClass().getClassLoader().getResourceAsStream("camel-quarkus-rocks.png")) { + /* Send a message */ + RestAssured.given() + .contentType("image/png") + .body(in) + .post("/telegram/media") + .then() + .statusCode(201); + } + } + + @Test + public void mp3() throws IOException { + try (InputStream in = getClass().getClassLoader().getResourceAsStream("camel-quarkus-rocks.mp3")) { + /* Send a message */ + RestAssured.given() + .contentType("audio/mpeg") + .body(in) + .post("/telegram/media") + .then() + .statusCode(201); + } + } + + @Test + public void mp4() throws IOException { + try (InputStream in = getClass().getClassLoader().getResourceAsStream("camel-quarkus-rocks.mp4")) { + /* Send a message */ + RestAssured.given() + .contentType("video/mp4") + .body(in) + .post("/telegram/media") + .then() + .statusCode(201); + } + } + + @Test + public void pdf() throws IOException { + try (InputStream in = getClass().getClassLoader().getResourceAsStream("camel-quarkus-rocks.pdf")) { + /* Send a message */ + RestAssured.given() + .contentType("application/pdf") + .body(in) + .post("/telegram/media") + .then() + .statusCode(201); + } + } + + @Test + public void location() throws IOException { + + final SendLocationMessage sendLoc = new SendLocationMessage(29.974834, 31.138577); + sendLoc.setLivePeriod(120); + final MessageResult result = RestAssured.given() + .contentType(ContentType.JSON) + .body(sendLoc) + .post("/telegram/send-location") + .then() + .statusCode(201) + .extract().body().as(MessageResult.class); + + /* Update the location */ + final EditMessageLiveLocationMessage edit = new EditMessageLiveLocationMessage(29.974928, 31.131115); + edit.setChatId(result.getMessage().getChat().getId()); + edit.setMessageId(result.getMessage().getMessageId()); + /* The edit fails with various 400 errors unless we wait a bit */ + Awaitility.await() + .pollDelay(500, TimeUnit.MILLISECONDS) + .pollInterval(100, TimeUnit.MILLISECONDS) + .atMost(10, TimeUnit.SECONDS).until(() -> { + final int code = RestAssured.given() + .contentType(ContentType.JSON) + .body(edit) + .post("/telegram/edit-location") + .then() + .extract().statusCode(); + return code != 201; + }); + + /* Stop updating */ + final StopMessageLiveLocationMessage stop = new StopMessageLiveLocationMessage(); + stop.setChatId(result.getMessage().getChat().getId()); + stop.setMessageId(result.getMessage().getMessageId()); + RestAssured.given() + .contentType(ContentType.JSON) + .body(stop) + .post("/telegram/stop-location") + .then() + .statusCode(201); + } + + @Test + public void venue() throws IOException { + final SendVenueMessage venue = new SendVenueMessage(29.977818, 31.136329, "Pyramid of Queen Henutsen", + "El-Hussein Ibn Ali Ln, Nazlet El-Semman, Al Haram, Giza Governorate, Egypt"); + RestAssured.given() + .contentType(ContentType.JSON) + .body(venue) + .post("/telegram/venue") + .then() + .statusCode(201); + } + +} diff --git a/integration-tests/telegram/src/test/resources/camel-quarkus-rocks.mp3 b/integration-tests/telegram/src/test/resources/camel-quarkus-rocks.mp3 new file mode 100644 index 0000000..d615407 Binary files /dev/null and b/integration-tests/telegram/src/test/resources/camel-quarkus-rocks.mp3 differ diff --git a/integration-tests/telegram/src/test/resources/camel-quarkus-rocks.mp4 b/integration-tests/telegram/src/test/resources/camel-quarkus-rocks.mp4 new file mode 100644 index 0000000..608d4b7 Binary files /dev/null and b/integration-tests/telegram/src/test/resources/camel-quarkus-rocks.mp4 differ diff --git a/integration-tests/telegram/src/test/resources/camel-quarkus-rocks.pdf b/integration-tests/telegram/src/test/resources/camel-quarkus-rocks.pdf new file mode 100644 index 0000000..edb723c Binary files /dev/null and b/integration-tests/telegram/src/test/resources/camel-quarkus-rocks.pdf differ diff --git a/integration-tests/telegram/src/test/resources/camel-quarkus-rocks.png b/integration-tests/telegram/src/test/resources/camel-quarkus-rocks.png new file mode 100644 index 0000000..55b18a7 Binary files /dev/null and b/integration-tests/telegram/src/test/resources/camel-quarkus-rocks.png differ diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml index c3964fb..4d51c91 100644 --- a/poms/bom/pom.xml +++ b/poms/bom/pom.xml @@ -511,6 +511,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-telegram</artifactId> + <version>${camel.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-timer</artifactId> <version>${camel.version}</version> </dependency> @@ -531,6 +536,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-webhook</artifactId> + <version>${camel.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-xml-jaxb</artifactId> <version>${camel.version}</version> </dependency> @@ -973,6 +983,11 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-telegram</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-timer</artifactId> <version>${camel-quarkus.version}</version> </dependency>