You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by gi...@apache.org on 2026/09/07 15:52:10 UTC

(seatunnel) 01/01: [Fix][Connector-V2] Use OAuth token for Slack messages (#12171)

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

github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/dev/pr-12171-c3f79ffb7ce1f4439f34f5ac32ff46a85a8721b7
in repository https://gitbox.apache.org/repos/asf/seatunnel.git

commit d85d8cc734bc3c8dc4fab7b3011daf5649719e56
Author: Nikhil kumar <ni...@gmail.com>
AuthorDate: Mon Sep 7 15:51:44 2026 +0000

    [Fix][Connector-V2] Use OAuth token for Slack messages (#12171)
---
 .../seatunnel/slack/client/SlackClient.java        | 26 +++++++++++----
 .../seatunnel/slack/client/SlackClientTest.java    | 37 ++++++++++++++++++++++
 2 files changed, 57 insertions(+), 6 deletions(-)

diff --git a/seatunnel-connectors-v2/connector-slack/src/main/java/org/apache/seatunnel/connectors/seatunnel/slack/client/SlackClient.java b/seatunnel-connectors-v2/connector-slack/src/main/java/org/apache/seatunnel/connectors/seatunnel/slack/client/SlackClient.java
index 8b037bbb5c..89047dfe5a 100644
--- a/seatunnel-connectors-v2/connector-slack/src/main/java/org/apache/seatunnel/connectors/seatunnel/slack/client/SlackClient.java
+++ b/seatunnel-connectors-v2/connector-slack/src/main/java/org/apache/seatunnel/connectors/seatunnel/slack/client/SlackClient.java
@@ -25,6 +25,7 @@ import org.apache.seatunnel.connectors.seatunnel.slack.exception.SlackConnectorE
 import com.slack.api.Slack;
 import com.slack.api.methods.MethodsClient;
 import com.slack.api.methods.SlackApiException;
+import com.slack.api.methods.request.chat.ChatPostMessageRequest;
 import com.slack.api.methods.response.chat.ChatPostMessageResponse;
 import com.slack.api.methods.response.conversations.ConversationsListResponse;
 import com.slack.api.model.Conversation;
@@ -80,12 +81,7 @@ public class SlackClient {
         try {
             ChatPostMessageResponse chatPostMessageResponse =
                     methodsClient.chatPostMessage(
-                            r ->
-                                    r
-                                            // The Token used to initialize app
-                                            .token(pluginConfig.get(SLACK_CHANNEL))
-                                            .channel(channelId)
-                                            .text(text));
+                            createMessageRequest(pluginConfig.get(OAUTH_TOKEN), channelId, text));
             publishMessageSuccess = chatPostMessageResponse.isOk();
         } catch (IOException | SlackApiException e) {
             log.error("error: {}", ExceptionUtils.getMessage(e));
@@ -93,6 +89,24 @@ public class SlackClient {
         return publishMessageSuccess;
     }
 
+    /**
+     * Builds a chat.postMessage request authenticated with the configured OAuth token, not the
+     * channel name.
+     *
+     * @param oauthToken OAuth token used to authenticate the request
+     * @param channelId resolved ID of the destination channel
+     * @param text message text to publish
+     * @return the request with authentication and message fields populated
+     */
+    static ChatPostMessageRequest createMessageRequest(
+            String oauthToken, String channelId, String text) {
+        return ChatPostMessageRequest.builder()
+                .token(oauthToken)
+                .channel(channelId)
+                .text(text)
+                .build();
+    }
+
     /** Close Conversion */
     public void closeMethodClient() {}
 }
diff --git a/seatunnel-connectors-v2/connector-slack/src/test/java/org/apache/seatunnel/connectors/seatunnel/slack/client/SlackClientTest.java b/seatunnel-connectors-v2/connector-slack/src/test/java/org/apache/seatunnel/connectors/seatunnel/slack/client/SlackClientTest.java
new file mode 100644
index 0000000000..09e518122c
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-slack/src/test/java/org/apache/seatunnel/connectors/seatunnel/slack/client/SlackClientTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.slack.client;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import com.slack.api.methods.request.chat.ChatPostMessageRequest;
+
+class SlackClientTest {
+
+    @Test
+    void testCreateMessageRequestUsesOAuthToken() {
+        ChatPostMessageRequest request =
+                SlackClient.createMessageRequest(
+                        "xoxb-test-token", "resolved-channel-id", "test-message");
+
+        Assertions.assertEquals("xoxb-test-token", request.getToken());
+        Assertions.assertEquals("resolved-channel-id", request.getChannel());
+        Assertions.assertEquals("test-message", request.getText());
+    }
+}