You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2022/04/06 15:22:38 UTC

[camel] 01/20: CAMEL-17792: Add doc about the message headers of camel-telegram

This is an automated email from the ASF dual-hosted git repository.

nfilotto pushed a commit to branch CAMEL-17792/doc-message-headers
in repository https://gitbox.apache.org/repos/asf/camel.git

commit aab4635cc6712023d94723c7a89c412e8cb7c7ed
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Tue Apr 5 18:37:10 2022 +0200

    CAMEL-17792: Add doc about the message headers of camel-telegram
---
 .../apache/camel/component/telegram/telegram.json  |  8 +++++++
 .../src/main/docs/telegram-component.adoc          | 26 +++-----------------
 .../component/telegram/TelegramConstants.java      | 28 ++++++++++++++++++----
 .../camel/component/telegram/TelegramEndpoint.java |  2 +-
 .../telegram/util/TelegramMessageHelper.java       |  4 ++--
 5 files changed, 38 insertions(+), 30 deletions(-)

diff --git a/components/camel-telegram/src/generated/resources/org/apache/camel/component/telegram/telegram.json b/components/camel-telegram/src/generated/resources/org/apache/camel/component/telegram/telegram.json
index c2e24d72b7d..ab289765a82 100644
--- a/components/camel-telegram/src/generated/resources/org/apache/camel/component/telegram/telegram.json
+++ b/components/camel-telegram/src/generated/resources/org/apache/camel/component/telegram/telegram.json
@@ -30,6 +30,14 @@
     "clientConfig": { "kind": "property", "displayName": "Client Config", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.asynchttpclient.AsyncHttpClientConfig", "deprecated": false, "autowired": false, "secret": false, "description": "To configure the AsyncHttpClient to use a custom com.ning.http.client.AsyncHttpClientConfig instance." },
     "authorizationToken": { "kind": "property", "displayName": "Authorization Token", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "description": "The default Telegram authorization token to be used when the information is not provided in the endpoints." }
   },
+  "headers": {
+    "CamelTelegramChatId": { "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "Object", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "This header is used by the producer endpoint in order to resolve the chat id that will receive the message. The recipient chat id can be placed (in order of priority) in message body, in the CamelTelegramChatId header or in the endpoint configura [...]
+    "CamelTelegramMediaType": { "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "org.apache.camel.component.telegram.TelegramMediaType or String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "This header is used to identify the media type when the outgoing message is composed of pure binary data. Possible values are strings or enum values belonging to the org.apache.camel.component.tel [...]
+    "CamelTelegramMediaTitleCaption": { "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "This header is used to provide a caption or title for outgoing binary messages." },
+    "CamelTelegramMediaMarkup": { "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "org.apache.camel.component.telegram.model.ReplyMarkup", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The reply markup." },
+    "CamelTelegramParseMode": { "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "org.apache.camel.component.telegram.TelegramParseMode", "enum": [ "HTML", "MARKDOWN" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "This header is used to format text messages using HTML or Markdown" },
+    "CamelMessageTimestamp": { "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "long", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The message timestamp." }
+  },
   "properties": {
     "type": { "kind": "path", "displayName": "Type", "group": "common", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "enum": [ "bots" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.telegram.TelegramConfiguration", "configurationField": "configuration", "description": "The endpoint type. Currently, only the 'bots' type is supported." },
     "bridgeErrorHandler": { "kind": "parameter", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a m [...]
diff --git a/components/camel-telegram/src/main/docs/telegram-component.adoc b/components/camel-telegram/src/main/docs/telegram-component.adoc
index 3f942474d78..a7e5d3db9b6 100644
--- a/components/camel-telegram/src/main/docs/telegram-component.adoc
+++ b/components/camel-telegram/src/main/docs/telegram-component.adoc
@@ -64,29 +64,9 @@ include::partial$component-endpoint-options.adoc[]
 // endpoint options: START
 
 // endpoint options: END
-
-
-== Message Headers
-
-[width="100%",cols="20%,80%",options="header",]
-|=======================================================================
-|Name |Description
-|`CamelTelegramChatId` |This header is used by the producer endpoint in order to
-resolve the chat id that will receive the message. The recipient chat id can be
-placed (in order of priority) in message body, in the `CamelTelegramChatId` header
-or in the endpoint configuration (`chatId` option).
-This header is also present in all incoming messages.
-
-|`CamelTelegramMediaType` |This header is used to identify the media type when
-the outgoing message is composed of pure binary data. Possible values are strings or enum values
-belonging to the `org.apache.camel.component.telegram.TelegramMediaType` enumeration.
-
-|`CamelTelegramMediaTitleCaption` |This header is used to provide a caption or title
-for outgoing binary messages.
-
-|`CamelTelegramParseMode` |This header is used to format text messages using HTML or Markdown (see `org.apache.camel.component.telegram.TelegramParseMode`).
-
-|=======================================================================
+// component headers: START
+include::partial$component-endpoint-headers.adoc[]
+// component headers: END
 
 == Usage
 
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramConstants.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramConstants.java
index 2c6a6471e70..6861dbe4456 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramConstants.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramConstants.java
@@ -16,20 +16,40 @@
  */
 package org.apache.camel.component.telegram;
 
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.Metadata;
+
 /**
  * Useful constants for the Telegram component.
  */
 public final class TelegramConstants {
 
+    @Metadata(label = "producer", description = "This header is used by the producer endpoint in order to\n" +
+                                                "resolve the chat id that will receive the message. The recipient chat id can be\n"
+                                                +
+                                                "placed (in order of priority) in message body, in the `CamelTelegramChatId` header\n"
+                                                +
+                                                "or in the endpoint configuration (`chatId` option).\n" +
+                                                "This header is also present in all incoming messages.",
+              javaType = "Object")
     public static final String TELEGRAM_CHAT_ID = "CamelTelegramChatId";
-
+    @Metadata(description = "This header is used to identify the media type when\n" +
+                            "the outgoing message is composed of pure binary data. Possible values are strings or enum values\n"
+                            +
+                            "belonging to the `org.apache.camel.component.telegram.TelegramMediaType` enumeration.",
+              javaType = "org.apache.camel.component.telegram.TelegramMediaType or String")
     public static final String TELEGRAM_MEDIA_TYPE = "CamelTelegramMediaType";
-
+    @Metadata(description = "This header is used to provide a caption or title\n" +
+                            "for outgoing binary messages.",
+              javaType = "String")
     public static final String TELEGRAM_MEDIA_TITLE_CAPTION = "CamelTelegramMediaTitleCaption";
-
+    @Metadata(description = "The reply markup.", javaType = "org.apache.camel.component.telegram.model.ReplyMarkup")
     public static final String TELEGRAM_MEDIA_MARKUP = "CamelTelegramMediaMarkup";
-
+    @Metadata(description = "This header is used to format text messages using HTML or Markdown",
+              javaType = "org.apache.camel.component.telegram.TelegramParseMode")
     public static final String TELEGRAM_PARSE_MODE = "CamelTelegramParseMode";
+    @Metadata(description = "The message timestamp.", javaType = "long")
+    public static final String MESSAGE_TIMESTAMP = Exchange.MESSAGE_TIMESTAMP;
 
     private TelegramConstants() {
     }
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramEndpoint.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramEndpoint.java
index 535b20f0be0..3c049efe52b 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramEndpoint.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramEndpoint.java
@@ -45,7 +45,7 @@ import org.slf4j.LoggerFactory;
  * Send and receive messages acting as a Telegram Bot <a href="https://core.telegram.org/bots/api">Telegram Bot API</a>.
  */
 @UriEndpoint(firstVersion = "2.18.0", scheme = "telegram", title = "Telegram", syntax = "telegram:type",
-             category = { Category.CLOUD, Category.API, Category.CHAT })
+             category = { Category.CLOUD, Category.API, Category.CHAT }, headersClass = TelegramConstants.class)
 public class TelegramEndpoint extends ScheduledPollEndpoint implements WebhookCapableEndpoint {
     private static final Logger LOG = LoggerFactory.getLogger(TelegramEndpoint.class);
 
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/util/TelegramMessageHelper.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/util/TelegramMessageHelper.java
index a3066face74..7e72a7b81dd 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/util/TelegramMessageHelper.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/util/TelegramMessageHelper.java
@@ -34,7 +34,7 @@ public final class TelegramMessageHelper {
             }
             if (update.getMessage().getDate() != null) {
                 // convert seconds to millis
-                exchange.getMessage().setHeader(Exchange.MESSAGE_TIMESTAMP,
+                exchange.getMessage().setHeader(TelegramConstants.MESSAGE_TIMESTAMP,
                         update.getMessage().getDate().getEpochSecond() * 1000);
             }
         } else if (update.getChannelPost() != null) {
@@ -45,7 +45,7 @@ public final class TelegramMessageHelper {
             }
             if (update.getChannelPost().getDate() != null) {
                 // convert seconds to millis
-                exchange.getMessage().setHeader(Exchange.MESSAGE_TIMESTAMP,
+                exchange.getMessage().setHeader(TelegramConstants.MESSAGE_TIMESTAMP,
                         update.getChannelPost().getDate().getEpochSecond() * 1000);
             }
         } else if (update.getCallbackQuery() != null) {