You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2021/02/24 15:40:41 UTC

[GitHub] [camel] Kinae opened a new pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Kinae opened a new pull request #5121:
URL: https://github.com/apache/camel/pull/5121


   The point is to add this functionality without breaking the current component.
   
   Not sure about using the Gson to transform the Message Object to JSON but the model has a lot of properties.
   It's included in the library
   I can spend time to write code to use json-simple if we do not want to use it.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] Kinae commented on pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
Kinae commented on pull request #5121:
URL: https://github.com/apache/camel/pull/5121#issuecomment-788900806


   I am not sure about the doc. Feel free to review and criticise anything. I am here to reply to any question you have


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] Kinae commented on a change in pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
Kinae commented on a change in pull request #5121:
URL: https://github.com/apache/camel/pull/5121#discussion_r585643683



##########
File path: components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackConstants.java
##########
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.slack;
 
+@Deprecated

Review comment:
       Yes but the class is public instead of package only so I was not sure about removing it. Maybe some used them in their code to do something. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] omarsmak commented on pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
omarsmak commented on pull request #5121:
URL: https://github.com/apache/camel/pull/5121#issuecomment-785770593


   I am actually not in favor of creating another component because that might confuse users on which component to use and what is really the difference. My question is, if we can use the Slack SDK in this existing component? Of course as long having the same input data, same configs and the same output data that doesn't break the experience for users. 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] Kinae commented on a change in pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
Kinae commented on a change in pull request #5121:
URL: https://github.com/apache/camel/pull/5121#discussion_r585649917



##########
File path: components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackConsumer.java
##########
@@ -141,68 +129,40 @@ public int processBatch(Queue<Object> exchanges) throws Exception {
         return total;
     }
 
-    private String getChannelId(String channel) throws IOException, DeserializationException {
-        HttpPost httpPost = new HttpPost(slackEndpoint.getServerUrl() + "/api/conversations.list");
-
-        List<BasicNameValuePair> params = new ArrayList<>();
-        params.add(new BasicNameValuePair("token", slackEndpoint.getToken()));
-        httpPost.setEntity(new UrlEncodedFormEntity(params));
-
-        HttpResponse response = client.execute(httpPost);
-
-        String jsonString = readResponse(response);
-        JsonObject c = (JsonObject) Jsoner.deserialize(jsonString);
-
-        checkSlackReply(c);
-
-        Collection<JsonObject> channels = c.getCollection("channels");
-        if (channels == null) {
-            throw new RuntimeCamelException("The response was successful but no channel list was provided");
-        }
-
-        for (JsonObject singleChannel : channels) {
-            if (singleChannel.get("name") != null) {
-                if (singleChannel.get("name").equals(channel)) {
-                    if (singleChannel.get("id") != null) {
-                        return (String) singleChannel.get("id");
-                    }
-                }
+    private String getChannelId(final String channel, final String cursor) {
+        try {
+            // Maximum limit is 1000. Slack recommends no more than 200 results at a time.
+            // https://api.slack.com/methods/conversations.list
+            ConversationsListResponse response = slack.methods(slackEndpoint.getToken()).conversationsList(req -> req
+                    .types(Collections.singletonList(slackEndpoint.getConversationType()))
+                    .cursor(cursor)
+                    .limit(200));
+
+            if (!response.isOk()) {
+                throw new RuntimeCamelException("API request conversations.list to Slack failed: " + response);
             }
-        }
 
-        return jsonString;
+            return response.getChannels().stream()
+                    .filter(it -> it.getName().equals(channel))
+                    .map(Conversation::getId)
+                    .findFirst().orElseGet(() -> {
+                        if (isNullOrEmpty(response.getResponseMetadata().getNextCursor())) {
+                            throw new RuntimeCamelException(String.format("Channel %s not found", channel));
+                        }
+                        return getChannelId(channel, response.getResponseMetadata().getNextCursor());
+                    });
+        } catch (IOException | SlackApiException e) {
+            throw new RuntimeCamelException("API request conversations.list to Slack failed", e);
+        }
     }
 
-    private void checkSlackReply(JsonObject c) {
-        boolean okStatus = c.getBoolean("ok");
-
-        if (!okStatus) {
-            String errorMessage = c.getString("error");
-
-            if (errorMessage == null || errorMessage.isEmpty()) {
-                errorMessage = "the slack server did not provide error details";
-            }
-
-            throw new RuntimeCamelException(String.format("API request to Slack failed: %s", errorMessage));
-        }
+    private static boolean isNullOrEmpty(String str) {
+        return str == null || str.isEmpty();

Review comment:
       Yes ! thank you




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] oscerd commented on a change in pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
oscerd commented on a change in pull request #5121:
URL: https://github.com/apache/camel/pull/5121#discussion_r585669211



##########
File path: catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/slack-component.adoc
##########
@@ -164,6 +168,35 @@ A CamelContext with Blueprint could be as:
 </blueprint>
 ---------------------------------------------------------------------------------------------------------------------------
 
+== Producer
+
+*Since Camel 3.9.0* +

Review comment:
       The since is not needed here. The documentation will be only for latest, so just remove the since, because the documentation is versioned

##########
File path: components/camel-slack/src/main/docs/slack-component.adoc
##########
@@ -164,6 +168,35 @@ A CamelContext with Blueprint could be as:
 </blueprint>
 ---------------------------------------------------------------------------------------------------------------------------
 
+== Producer
+
+*Since Camel 3.9.0* +

Review comment:
       Remove the since here, the other part will be re-generated

##########
File path: components/camel-slack/src/main/docs/slack-component.adoc
##########
@@ -180,6 +213,15 @@ You'll need to create a Slack app and use it on your workspace.
 
 Use the 'Bot User OAuth Access Token' as token for the consumer endpoint.
 
-IMPORTANT: Add the `channels:history` and `channels:read` user token scope to your app to grant it permission to view messages in the user's public channels.
+IMPORTANT: Add the corresponding history (`channels:history` or `groups:history` or `mpim:history` or `im:history`) and
+read (`channels:read` or `groups:read` or `mpim:read` or `im:read`) user token scope to your app to grant it permission to
+view messages in the corresponding channel. You will need to use the conversationType option to set it up too (`PUBLIC_CHANNEL`, `PRIVATE_CHANNEL`, `MPIM`, `IM`)
+
+*Since Camel 3.9.0* +

Review comment:
       Same




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] Kinae commented on pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
Kinae commented on pull request #5121:
URL: https://github.com/apache/camel/pull/5121#issuecomment-787421518


   I think I can transform the legacy module to use the slack SDK without breaking it.
   The first issue I ran into is the version of the **okhttp**.They are using the 4.9.1 and apache camel is using 3.14.7 
   Tried to force the SDK to use old version but I got some **ClassNotFoundException** using the webhook compatibility (but no issue if using slack app token)
   
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] Kinae commented on a change in pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
Kinae commented on a change in pull request #5121:
URL: https://github.com/apache/camel/pull/5121#discussion_r585641381



##########
File path: components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackComponentVerifierExtension.java
##########
@@ -118,23 +101,12 @@ private void verifyCredentials(ResultBuilder builder, Map<String, Object> parame
             String token = (String) parameters.get("token");
 
             try {
-                HttpClient client = HttpClientBuilder.create().useSystemProperties().build();
-                HttpPost httpPost = new HttpPost(parameters.get("serverUrl") + "/api/conversations.list");
-
-                List<BasicNameValuePair> params = new ArrayList<>();
-                params.add(new BasicNameValuePair("token", token));
-                httpPost.setEntity(new UrlEncodedFormEntity(params));
+                ConversationsListResponse response = Slack.getInstance(new CustomSlackHttpClient()).methods(token)
+                        .conversationsList(req -> req
+                                .types(Collections.singletonList(ConversationType.PUBLIC_CHANNEL))

Review comment:
       Very good question, I created an empty slack workspace and for now it's impossible to remove all public channel. You can't delete the general one. 
   
   So I tried with the opposite side, asked to list all private channels without having any and it replies 200 with this : 
   ```
   {
       "ok": true,
       "channels": [],
       "response_metadata": {
           "next_cursor": ""
       }
   }
   ```

##########
File path: components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackComponentVerifierExtension.java
##########
@@ -118,23 +101,12 @@ private void verifyCredentials(ResultBuilder builder, Map<String, Object> parame
             String token = (String) parameters.get("token");
 
             try {
-                HttpClient client = HttpClientBuilder.create().useSystemProperties().build();
-                HttpPost httpPost = new HttpPost(parameters.get("serverUrl") + "/api/conversations.list");
-
-                List<BasicNameValuePair> params = new ArrayList<>();
-                params.add(new BasicNameValuePair("token", token));
-                httpPost.setEntity(new UrlEncodedFormEntity(params));
+                ConversationsListResponse response = Slack.getInstance(new CustomSlackHttpClient()).methods(token)
+                        .conversationsList(req -> req
+                                .types(Collections.singletonList(ConversationType.PUBLIC_CHANNEL))

Review comment:
       Very good question, I created an empty Slack workspace and for now it's impossible to remove all public channel. You can't delete the general one. 
   
   So I tried with the opposite side, asked to list all private channels without having any and it replies 200 with this : 
   ```
   {
       "ok": true,
       "channels": [],
       "response_metadata": {
           "next_cursor": ""
       }
   }
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] Kinae commented on pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
Kinae commented on pull request #5121:
URL: https://github.com/apache/camel/pull/5121#issuecomment-787798770


   Thank you all. I am working on it so you can get a look at it.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] omarsmak commented on a change in pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
omarsmak commented on a change in pull request #5121:
URL: https://github.com/apache/camel/pull/5121#discussion_r585588672



##########
File path: components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackComponentVerifierExtension.java
##########
@@ -118,23 +101,12 @@ private void verifyCredentials(ResultBuilder builder, Map<String, Object> parame
             String token = (String) parameters.get("token");
 
             try {
-                HttpClient client = HttpClientBuilder.create().useSystemProperties().build();
-                HttpPost httpPost = new HttpPost(parameters.get("serverUrl") + "/api/conversations.list");
-
-                List<BasicNameValuePair> params = new ArrayList<>();
-                params.add(new BasicNameValuePair("token", token));
-                httpPost.setEntity(new UrlEncodedFormEntity(params));
+                ConversationsListResponse response = Slack.getInstance(new CustomSlackHttpClient()).methods(token)
+                        .conversationsList(req -> req
+                                .types(Collections.singletonList(ConversationType.PUBLIC_CHANNEL))

Review comment:
       If we only have private channels, does still return `200`?

##########
File path: components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackConstants.java
##########
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.slack;
 
+@Deprecated

Review comment:
       These constants before used to build the Json request to Slack APIs, isn't? Is there any reason to deprecate them instead of removing this class entirely?  

##########
File path: components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackConsumer.java
##########
@@ -141,68 +129,40 @@ public int processBatch(Queue<Object> exchanges) throws Exception {
         return total;
     }
 
-    private String getChannelId(String channel) throws IOException, DeserializationException {
-        HttpPost httpPost = new HttpPost(slackEndpoint.getServerUrl() + "/api/conversations.list");
-
-        List<BasicNameValuePair> params = new ArrayList<>();
-        params.add(new BasicNameValuePair("token", slackEndpoint.getToken()));
-        httpPost.setEntity(new UrlEncodedFormEntity(params));
-
-        HttpResponse response = client.execute(httpPost);
-
-        String jsonString = readResponse(response);
-        JsonObject c = (JsonObject) Jsoner.deserialize(jsonString);
-
-        checkSlackReply(c);
-
-        Collection<JsonObject> channels = c.getCollection("channels");
-        if (channels == null) {
-            throw new RuntimeCamelException("The response was successful but no channel list was provided");
-        }
-
-        for (JsonObject singleChannel : channels) {
-            if (singleChannel.get("name") != null) {
-                if (singleChannel.get("name").equals(channel)) {
-                    if (singleChannel.get("id") != null) {
-                        return (String) singleChannel.get("id");
-                    }
-                }
+    private String getChannelId(final String channel, final String cursor) {
+        try {
+            // Maximum limit is 1000. Slack recommends no more than 200 results at a time.
+            // https://api.slack.com/methods/conversations.list
+            ConversationsListResponse response = slack.methods(slackEndpoint.getToken()).conversationsList(req -> req
+                    .types(Collections.singletonList(slackEndpoint.getConversationType()))
+                    .cursor(cursor)
+                    .limit(200));

Review comment:
       Can we move the limit number into a constant somewhere? Let's say this class

##########
File path: components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackConsumer.java
##########
@@ -141,68 +129,40 @@ public int processBatch(Queue<Object> exchanges) throws Exception {
         return total;
     }
 
-    private String getChannelId(String channel) throws IOException, DeserializationException {
-        HttpPost httpPost = new HttpPost(slackEndpoint.getServerUrl() + "/api/conversations.list");
-
-        List<BasicNameValuePair> params = new ArrayList<>();
-        params.add(new BasicNameValuePair("token", slackEndpoint.getToken()));
-        httpPost.setEntity(new UrlEncodedFormEntity(params));
-
-        HttpResponse response = client.execute(httpPost);
-
-        String jsonString = readResponse(response);
-        JsonObject c = (JsonObject) Jsoner.deserialize(jsonString);
-
-        checkSlackReply(c);
-
-        Collection<JsonObject> channels = c.getCollection("channels");
-        if (channels == null) {
-            throw new RuntimeCamelException("The response was successful but no channel list was provided");
-        }
-
-        for (JsonObject singleChannel : channels) {
-            if (singleChannel.get("name") != null) {
-                if (singleChannel.get("name").equals(channel)) {
-                    if (singleChannel.get("id") != null) {
-                        return (String) singleChannel.get("id");
-                    }
-                }
+    private String getChannelId(final String channel, final String cursor) {
+        try {
+            // Maximum limit is 1000. Slack recommends no more than 200 results at a time.
+            // https://api.slack.com/methods/conversations.list
+            ConversationsListResponse response = slack.methods(slackEndpoint.getToken()).conversationsList(req -> req
+                    .types(Collections.singletonList(slackEndpoint.getConversationType()))
+                    .cursor(cursor)
+                    .limit(200));
+
+            if (!response.isOk()) {
+                throw new RuntimeCamelException("API request conversations.list to Slack failed: " + response);
             }
-        }
 
-        return jsonString;
+            return response.getChannels().stream()
+                    .filter(it -> it.getName().equals(channel))
+                    .map(Conversation::getId)
+                    .findFirst().orElseGet(() -> {
+                        if (isNullOrEmpty(response.getResponseMetadata().getNextCursor())) {
+                            throw new RuntimeCamelException(String.format("Channel %s not found", channel));
+                        }
+                        return getChannelId(channel, response.getResponseMetadata().getNextCursor());
+                    });
+        } catch (IOException | SlackApiException e) {
+            throw new RuntimeCamelException("API request conversations.list to Slack failed", e);
+        }
     }
 
-    private void checkSlackReply(JsonObject c) {
-        boolean okStatus = c.getBoolean("ok");
-
-        if (!okStatus) {
-            String errorMessage = c.getString("error");
-
-            if (errorMessage == null || errorMessage.isEmpty()) {
-                errorMessage = "the slack server did not provide error details";
-            }
-
-            throw new RuntimeCamelException(String.format("API request to Slack failed: %s", errorMessage));
-        }
+    private static boolean isNullOrEmpty(String str) {
+        return str == null || str.isEmpty();

Review comment:
       You can use `ObjectHelper.isNotEmpty()` in `org.apache.camel.util` to check for empty strings as well nulls

##########
File path: components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackConsumer.java
##########
@@ -17,102 +17,90 @@
 package org.apache.camel.component.slack;
 
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
+import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Queue;
 
+import com.slack.api.Slack;
+import com.slack.api.methods.SlackApiException;
+import com.slack.api.methods.response.conversations.ConversationsHistoryResponse;
+import com.slack.api.methods.response.conversations.ConversationsListResponse;
+import com.slack.api.model.Conversation;
+import com.slack.api.model.Message;
 import org.apache.camel.Exchange;
-import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.component.slack.helper.SlackMessage;
 import org.apache.camel.support.ScheduledBatchPollingConsumer;
 import org.apache.camel.util.CastUtils;
 import org.apache.camel.util.ObjectHelper;
-import org.apache.camel.util.json.DeserializationException;
-import org.apache.camel.util.json.JsonArray;
-import org.apache.camel.util.json.JsonObject;
-import org.apache.camel.util.json.Jsoner;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.entity.UrlEncodedFormEntity;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.message.BasicNameValuePair;
-
-import static org.apache.camel.component.slack.utils.SlackUtils.readResponse;
 
 public class SlackConsumer extends ScheduledBatchPollingConsumer {
 
-    private SlackEndpoint slackEndpoint;
+    private final SlackEndpoint slackEndpoint;
+    private Slack slack;
     private String timestamp;
     private String channelId;
-    private CloseableHttpClient client;
 
-    public SlackConsumer(SlackEndpoint endpoint, Processor processor) throws IOException, DeserializationException {
+    public SlackConsumer(SlackEndpoint endpoint, Processor processor) {
         super(endpoint, processor);
         this.slackEndpoint = endpoint;
     }
 
     @Override
     protected void doStart() throws Exception {
-        this.client = HttpClientBuilder.create().useSystemProperties().build();
+        this.slack = Slack.getInstance();

Review comment:
       This instance of the client, differs from the one that was used in the verifier whereby the `CustomSlackHttpClient`, is this intentional?
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] omarsmak commented on pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
omarsmak commented on pull request #5121:
URL: https://github.com/apache/camel/pull/5121#issuecomment-787792362


   > I found a working method while forcing the **okhttp** version to 3.14.7
   > We can just override one class and one method to provide our configuration. Just tested and it works well and does not break the camel-slack component
   
   That will be good if you can get it to work on the existing component


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] omarsmak commented on pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
omarsmak commented on pull request #5121:
URL: https://github.com/apache/camel/pull/5121#issuecomment-789799804


   Shall we merge this?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] omarsmak commented on a change in pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
omarsmak commented on a change in pull request #5121:
URL: https://github.com/apache/camel/pull/5121#discussion_r585652500



##########
File path: components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackComponentVerifierExtension.java
##########
@@ -118,23 +101,12 @@ private void verifyCredentials(ResultBuilder builder, Map<String, Object> parame
             String token = (String) parameters.get("token");
 
             try {
-                HttpClient client = HttpClientBuilder.create().useSystemProperties().build();
-                HttpPost httpPost = new HttpPost(parameters.get("serverUrl") + "/api/conversations.list");
-
-                List<BasicNameValuePair> params = new ArrayList<>();
-                params.add(new BasicNameValuePair("token", token));
-                httpPost.setEntity(new UrlEncodedFormEntity(params));
+                ConversationsListResponse response = Slack.getInstance(new CustomSlackHttpClient()).methods(token)
+                        .conversationsList(req -> req
+                                .types(Collections.singletonList(ConversationType.PUBLIC_CHANNEL))

Review comment:
       so I guess, it doesn't really makes difference since we just want to check if the token is valid 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] omarsmak commented on pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
omarsmak commented on pull request #5121:
URL: https://github.com/apache/camel/pull/5121#issuecomment-785788213


   > I think it is possible to have the same component with the new model, but I don't think we could introduce the usage of SDK without breaking the current behavior.
   
   If it is going to break the existing behavior, then definitely a new component with the SDK would make sense. Then I would at least rename this component to something like `camel-slack-legacy` and keep the new one with `camel-slack` to have it least confusing for the users. Of course this needs to be mentioned in the migration guides 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] Kinae commented on pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
Kinae commented on pull request #5121:
URL: https://github.com/apache/camel/pull/5121#issuecomment-787456815


   I found a working method while forcing the **okhttp** version to 3.14.7
   We can just override one class and one method to provide our configuration. Just tested and it works well and does not break the camel-slack component 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] Kinae commented on a change in pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
Kinae commented on a change in pull request #5121:
URL: https://github.com/apache/camel/pull/5121#discussion_r585649143



##########
File path: components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackConsumer.java
##########
@@ -141,68 +129,40 @@ public int processBatch(Queue<Object> exchanges) throws Exception {
         return total;
     }
 
-    private String getChannelId(String channel) throws IOException, DeserializationException {
-        HttpPost httpPost = new HttpPost(slackEndpoint.getServerUrl() + "/api/conversations.list");
-
-        List<BasicNameValuePair> params = new ArrayList<>();
-        params.add(new BasicNameValuePair("token", slackEndpoint.getToken()));
-        httpPost.setEntity(new UrlEncodedFormEntity(params));
-
-        HttpResponse response = client.execute(httpPost);
-
-        String jsonString = readResponse(response);
-        JsonObject c = (JsonObject) Jsoner.deserialize(jsonString);
-
-        checkSlackReply(c);
-
-        Collection<JsonObject> channels = c.getCollection("channels");
-        if (channels == null) {
-            throw new RuntimeCamelException("The response was successful but no channel list was provided");
-        }
-
-        for (JsonObject singleChannel : channels) {
-            if (singleChannel.get("name") != null) {
-                if (singleChannel.get("name").equals(channel)) {
-                    if (singleChannel.get("id") != null) {
-                        return (String) singleChannel.get("id");
-                    }
-                }
+    private String getChannelId(final String channel, final String cursor) {
+        try {
+            // Maximum limit is 1000. Slack recommends no more than 200 results at a time.
+            // https://api.slack.com/methods/conversations.list
+            ConversationsListResponse response = slack.methods(slackEndpoint.getToken()).conversationsList(req -> req
+                    .types(Collections.singletonList(slackEndpoint.getConversationType()))
+                    .cursor(cursor)
+                    .limit(200));

Review comment:
       done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] omarsmak commented on a change in pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
omarsmak commented on a change in pull request #5121:
URL: https://github.com/apache/camel/pull/5121#discussion_r585651937



##########
File path: components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackConstants.java
##########
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.slack;
 
+@Deprecated

Review comment:
       okay we can keep it for one version and then remove it




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] Kinae commented on a change in pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
Kinae commented on a change in pull request #5121:
URL: https://github.com/apache/camel/pull/5121#discussion_r585647958



##########
File path: components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackConsumer.java
##########
@@ -17,102 +17,90 @@
 package org.apache.camel.component.slack;
 
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
+import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Queue;
 
+import com.slack.api.Slack;
+import com.slack.api.methods.SlackApiException;
+import com.slack.api.methods.response.conversations.ConversationsHistoryResponse;
+import com.slack.api.methods.response.conversations.ConversationsListResponse;
+import com.slack.api.model.Conversation;
+import com.slack.api.model.Message;
 import org.apache.camel.Exchange;
-import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.component.slack.helper.SlackMessage;
 import org.apache.camel.support.ScheduledBatchPollingConsumer;
 import org.apache.camel.util.CastUtils;
 import org.apache.camel.util.ObjectHelper;
-import org.apache.camel.util.json.DeserializationException;
-import org.apache.camel.util.json.JsonArray;
-import org.apache.camel.util.json.JsonObject;
-import org.apache.camel.util.json.Jsoner;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.entity.UrlEncodedFormEntity;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.message.BasicNameValuePair;
-
-import static org.apache.camel.component.slack.utils.SlackUtils.readResponse;
 
 public class SlackConsumer extends ScheduledBatchPollingConsumer {
 
-    private SlackEndpoint slackEndpoint;
+    private final SlackEndpoint slackEndpoint;
+    private Slack slack;
     private String timestamp;
     private String channelId;
-    private CloseableHttpClient client;
 
-    public SlackConsumer(SlackEndpoint endpoint, Processor processor) throws IOException, DeserializationException {
+    public SlackConsumer(SlackEndpoint endpoint, Processor processor) {
         super(endpoint, processor);
         this.slackEndpoint = endpoint;
     }
 
     @Override
     protected void doStart() throws Exception {
-        this.client = HttpClientBuilder.create().useSystemProperties().build();
+        this.slack = Slack.getInstance();

Review comment:
       Mistake, thank you !




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] oscerd commented on pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
oscerd commented on pull request #5121:
URL: https://github.com/apache/camel/pull/5121#issuecomment-785782758


   My idea was to have a new component and deprecate the other one. I think it is possible to have the same component with the new model, but I don't think we could introduce the usage of SDK without breaking the current behavior.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] Kinae commented on pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
Kinae commented on pull request #5121:
URL: https://github.com/apache/camel/pull/5121#issuecomment-789002684


   Done ! Thank you for the review, I did not know about that versioning in the documentation. 
   
   I volunteer to help to support the module if there is any JIRA ticket that comes for it later. 
   Apache Camel is the center of two big applications in my company


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] oscerd commented on pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
oscerd commented on pull request #5121:
URL: https://github.com/apache/camel/pull/5121#issuecomment-787434548


   That would be a problem. Okhttp 4.x is kotlin based.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] omarsmak merged pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
omarsmak merged pull request #5121:
URL: https://github.com/apache/camel/pull/5121


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] Kinae commented on pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
Kinae commented on pull request #5121:
URL: https://github.com/apache/camel/pull/5121#issuecomment-785170374


   Ok I will try to create a new component camel-slack-sdk


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] oscerd commented on pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
oscerd commented on pull request #5121:
URL: https://github.com/apache/camel/pull/5121#issuecomment-789801665


   +1, @omarsmak if you have time go ahead.
   
   Thanks!


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] Kinae closed pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
Kinae closed pull request #5121:
URL: https://github.com/apache/camel/pull/5121


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [camel] oscerd commented on pull request #5121: CAMEL-16255 Use of the slack-api-model to create rich content

Posted by GitBox <gi...@apache.org>.
oscerd commented on pull request #5121:
URL: https://github.com/apache/camel/pull/5121#issuecomment-785171801


   I think it gives you more freedom of developing the component as you wish, without having to deal with the older implementation. Btw lets leave this open for others to comment. My comment is not mandatory :-)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org