You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "sporadek (via GitHub)" <gi...@apache.org> on 2023/11/17 20:39:30 UTC
[PR] NiFi-12331: add new unified PublishSlack Processor [nifi]
sporadek opened a new pull request, #8047:
URL: https://github.com/apache/nifi/pull/8047
<!-- 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. -->
# Summary
[NIFI-12331](https://issues.apache.org/jira/browse/NIFI-12331)
# Tracking
Please complete the following tracking steps prior to pull request creation.
### Issue Tracking
- [x] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created
### Pull Request Tracking
- [x] Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-00000`
- [x] Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-00000`
### Pull Request Formatting
- [x] Pull Request based on current revision of the `main` branch
- [x] Pull Request refers to a feature branch with one commit containing changes
# Verification
Please indicate the verification steps performed prior to pull request creation.
### Build
- [x] Build completed using `mvn clean install -P contrib-check`
- [x] JDK 21
### Licensing
No new libraries.
### Documentation
- [ ] Documentation formatting appears as expected in rendered files
--
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.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-12331: add new unified PublishSlack Processor [nifi]
Posted by "markap14 (via GitHub)" <gi...@apache.org>.
markap14 commented on code in PR #8047:
URL: https://github.com/apache/nifi/pull/8047#discussion_r1408428736
##########
nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/src/main/java/org/apache/nifi/processors/slack/PublishSlack.java:
##########
@@ -0,0 +1,516 @@
+/*
+ * 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.nifi.processors.slack;
+
+import com.slack.api.bolt.App;
+import com.slack.api.bolt.AppConfig;
+import com.slack.api.methods.MethodsClient;
+import com.slack.api.methods.SlackApiException;
+import com.slack.api.methods.SlackFilesUploadV2Exception;
+import com.slack.api.methods.request.chat.ChatPostMessageRequest;
+import com.slack.api.methods.request.conversations.ConversationsListRequest;
+import com.slack.api.methods.request.files.FilesUploadV2Request;
+import com.slack.api.methods.response.chat.ChatPostMessageResponse;
+import com.slack.api.methods.response.conversations.ConversationsListResponse;
+import com.slack.api.methods.response.files.FilesUploadV2Response;
+import com.slack.api.model.Conversation;
+import com.slack.api.model.File;
+import org.apache.nifi.annotation.behavior.DynamicProperty;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.expression.AttributeExpression;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.flowfile.attributes.CoreAttributes;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.slack.consume.ConsumeSlackUtil;
+import org.apache.nifi.processors.slack.publish.ContentMessageStrategy;
+import org.apache.nifi.processors.slack.publish.MessageOnlyStrategy;
+import org.apache.nifi.processors.slack.publish.PublishConfig;
+import org.apache.nifi.processors.slack.publish.PublishSlackClient;
+import org.apache.nifi.processors.slack.publish.PublishStrategy;
+import org.apache.nifi.processors.slack.publish.UploadAttachmentStrategy;
+import org.apache.nifi.processors.slack.publish.UploadLinkStrategy;
+import org.apache.nifi.processors.slack.publish.UploadOnlyStrategy;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import static org.apache.nifi.util.StringUtils.isEmpty;
+
+
+@Tags({"slack", "publish", "notify", "upload", "message"})
+@CapabilityDescription("Uploads the FlowFile content (e.g. an image) as a file, and/or Sends a message on Slack. The FlowFile content can be used as the message text or attached to the message.")
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@DynamicProperty(name = "<Arbitrary name>", value = "JSON snippet specifying a Slack message \"attachment\"",
+ description = "The property value will be converted to JSON and will be added to the array of attachments in the JSON payload being sent to Slack." +
+ " The property name will not be used by the processor.",
+ expressionLanguageScope = ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+@WritesAttribute(attribute="slack.file.url", description = "The Slack URL of the uploaded file. It will be added if 'Upload FlowFile' has been set to 'Yes'.")
+public class PublishSlack extends AbstractProcessor {
+
+ private static final String UPLOAD_ONLY = "upload-only";
+ private static final String MESSAGE_ONLY = "message-only";
+ private static final String CONTENT_MESSAGE = "content-message";
+ private static final String UPLOAD_ATTACH = "upload-attach";
+ private static final String UPLOAD_LINK = "upload-link";
+
+ public static final PropertyDescriptor BOT_TOKEN = new PropertyDescriptor.Builder()
+ .name("Bot Token")
+ .description("The Bot Token that is registered to your Slack application")
+ .addValidator(StandardValidators.NON_BLANK_VALIDATOR)
+ .required(true)
+ .sensitive(true)
+ .build();
+
+ public static final AllowableValue STRATEGY_UPLOAD_ONLY = new AllowableValue(
+ UPLOAD_ONLY,
+ "Upload File Content Only",
+ "Only upload the FlowFile content - it will be a visible Slack message if 'Upload Channel' is specified."
+ );
+
+ public static final AllowableValue STRATEGY_MESSAGE_ONLY = new AllowableValue(
+ MESSAGE_ONLY,
+ "Post Message Only",
+ "Post a simple Slack message with optional 'Text' and/or dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_CONTENT_MESSAGE = new AllowableValue(
+ CONTENT_MESSAGE,
+ "Post File Content as Message Text",
+ "Post the FlowFile content as a Slack message with optional dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_UPLOAD_ATTACH = new AllowableValue(
+ UPLOAD_ATTACH,
+ "Upload File Content as Attachment to Message",
+ "Upload the FlowFile content and add a link to the uploaded file as an attachment to the posted Slack message. The message will include optional dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_UPLOAD_LINK = new AllowableValue(
+ UPLOAD_LINK,
+ "Upload File Content as Embedded Link",
+ "Upload the FlowFile content and append a link to the uploaded file in the posted Slack message. The message will include optional dynamic Properties as attachments."
+ );
+
+ public static final PropertyDescriptor PUBLISH_STRATEGY = new PropertyDescriptor.Builder()
+ .name("publish-strategy")
+ .displayName("Publish Strategy")
Review Comment:
The use of this naming convention is 'deprecated' and something we ideally avoid. Rather, we should just use a name of "Publish Strategy" and not specify a `displayName`.
##########
nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/src/main/java/org/apache/nifi/processors/slack/PublishSlack.java:
##########
@@ -0,0 +1,516 @@
+/*
+ * 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.nifi.processors.slack;
+
+import com.slack.api.bolt.App;
+import com.slack.api.bolt.AppConfig;
+import com.slack.api.methods.MethodsClient;
+import com.slack.api.methods.SlackApiException;
+import com.slack.api.methods.SlackFilesUploadV2Exception;
+import com.slack.api.methods.request.chat.ChatPostMessageRequest;
+import com.slack.api.methods.request.conversations.ConversationsListRequest;
+import com.slack.api.methods.request.files.FilesUploadV2Request;
+import com.slack.api.methods.response.chat.ChatPostMessageResponse;
+import com.slack.api.methods.response.conversations.ConversationsListResponse;
+import com.slack.api.methods.response.files.FilesUploadV2Response;
+import com.slack.api.model.Conversation;
+import com.slack.api.model.File;
+import org.apache.nifi.annotation.behavior.DynamicProperty;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.expression.AttributeExpression;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.flowfile.attributes.CoreAttributes;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.slack.consume.ConsumeSlackUtil;
+import org.apache.nifi.processors.slack.publish.ContentMessageStrategy;
+import org.apache.nifi.processors.slack.publish.MessageOnlyStrategy;
+import org.apache.nifi.processors.slack.publish.PublishConfig;
+import org.apache.nifi.processors.slack.publish.PublishSlackClient;
+import org.apache.nifi.processors.slack.publish.PublishStrategy;
+import org.apache.nifi.processors.slack.publish.UploadAttachmentStrategy;
+import org.apache.nifi.processors.slack.publish.UploadLinkStrategy;
+import org.apache.nifi.processors.slack.publish.UploadOnlyStrategy;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import static org.apache.nifi.util.StringUtils.isEmpty;
+
+
+@Tags({"slack", "publish", "notify", "upload", "message"})
+@CapabilityDescription("Uploads the FlowFile content (e.g. an image) as a file, and/or Sends a message on Slack. The FlowFile content can be used as the message text or attached to the message.")
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@DynamicProperty(name = "<Arbitrary name>", value = "JSON snippet specifying a Slack message \"attachment\"",
+ description = "The property value will be converted to JSON and will be added to the array of attachments in the JSON payload being sent to Slack." +
+ " The property name will not be used by the processor.",
+ expressionLanguageScope = ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+@WritesAttribute(attribute="slack.file.url", description = "The Slack URL of the uploaded file. It will be added if 'Upload FlowFile' has been set to 'Yes'.")
+public class PublishSlack extends AbstractProcessor {
+
+ private static final String UPLOAD_ONLY = "upload-only";
+ private static final String MESSAGE_ONLY = "message-only";
+ private static final String CONTENT_MESSAGE = "content-message";
+ private static final String UPLOAD_ATTACH = "upload-attach";
+ private static final String UPLOAD_LINK = "upload-link";
+
+ public static final PropertyDescriptor BOT_TOKEN = new PropertyDescriptor.Builder()
+ .name("Bot Token")
+ .description("The Bot Token that is registered to your Slack application")
+ .addValidator(StandardValidators.NON_BLANK_VALIDATOR)
+ .required(true)
+ .sensitive(true)
+ .build();
+
+ public static final AllowableValue STRATEGY_UPLOAD_ONLY = new AllowableValue(
+ UPLOAD_ONLY,
+ "Upload File Content Only",
+ "Only upload the FlowFile content - it will be a visible Slack message if 'Upload Channel' is specified."
+ );
+
+ public static final AllowableValue STRATEGY_MESSAGE_ONLY = new AllowableValue(
+ MESSAGE_ONLY,
+ "Post Message Only",
+ "Post a simple Slack message with optional 'Text' and/or dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_CONTENT_MESSAGE = new AllowableValue(
+ CONTENT_MESSAGE,
+ "Post File Content as Message Text",
+ "Post the FlowFile content as a Slack message with optional dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_UPLOAD_ATTACH = new AllowableValue(
+ UPLOAD_ATTACH,
+ "Upload File Content as Attachment to Message",
+ "Upload the FlowFile content and add a link to the uploaded file as an attachment to the posted Slack message. The message will include optional dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_UPLOAD_LINK = new AllowableValue(
+ UPLOAD_LINK,
+ "Upload File Content as Embedded Link",
+ "Upload the FlowFile content and append a link to the uploaded file in the posted Slack message. The message will include optional dynamic Properties as attachments."
+ );
+
+ public static final PropertyDescriptor PUBLISH_STRATEGY = new PropertyDescriptor.Builder()
+ .name("publish-strategy")
+ .displayName("Publish Strategy")
+ .description("Determines how the FlowFile is sent to Slack and how it appears.")
+ .allowableValues(STRATEGY_UPLOAD_ONLY, STRATEGY_MESSAGE_ONLY, STRATEGY_CONTENT_MESSAGE, STRATEGY_UPLOAD_ATTACH, STRATEGY_UPLOAD_LINK)
+ .required(true)
+ .defaultValue(UPLOAD_ATTACH)
+ .build();
+
+ public static final PropertyDescriptor CHANNEL = new PropertyDescriptor.Builder()
+ .name("channel")
+ .displayName("Channel")
+ .description("Slack channel, private group, or IM channel to post the message to.")
+ .dependsOn(PUBLISH_STRATEGY, MESSAGE_ONLY, CONTENT_MESSAGE, UPLOAD_ATTACH, UPLOAD_LINK)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .build();
+
+ public static final PropertyDescriptor UPLOAD_CHANNEL = new PropertyDescriptor.Builder()
+ .name("upload-channel")
+ .displayName("Upload Channel")
+ .description("Slack channel, private group, or IM channel to upload the file to.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .build();
+
+ public static final PropertyDescriptor THREAD_TS = new PropertyDescriptor.Builder()
+ .name("Thread Timestamp")
+ .description("The timestamp of the parent message, also known as a thread_ts, or Thread Timestamp. If not specified, the message will be send to the channel " +
+ "as an independent message. If this value is populated, the message will be sent as a reply to the message whose timestamp is equal to the given value.")
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .build();
+
+ public static final PropertyDescriptor TEXT = new PropertyDescriptor.Builder()
+ .name("text")
+ .displayName("Text")
+ .description("Text of the Slack message to send. Only required if no attachment has been specified and 'Upload File' has been set to 'No'.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .build();
+
+ public static final PropertyDescriptor INITIAL_COMMENT = new PropertyDescriptor.Builder()
+ .name("upload-text")
+ .displayName("Upload Text")
+ .description("Text of the Slack message to include with a public upload. Only used if 'Publish Mode' has been set to 'Upload Only' and 'Upload Channel' is specified.")
+ .dependsOn(PUBLISH_STRATEGY, UPLOAD_ONLY)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .build();
+
+ public static final PropertyDescriptor FILE_TITLE = new PropertyDescriptor.Builder()
+ .name("file-title")
+ .displayName("File Title")
+ .description("Title of the file displayed in the Slack message." +
+ " The property value will only be used if 'Upload FlowFile' has been set to 'Yes'.")
Review Comment:
Not sure that I understand the description here. There is nowhere for the user to set 'Upload FlowFile'.
##########
nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/src/main/java/org/apache/nifi/processors/slack/PublishSlack.java:
##########
@@ -0,0 +1,516 @@
+/*
+ * 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.nifi.processors.slack;
+
+import com.slack.api.bolt.App;
+import com.slack.api.bolt.AppConfig;
+import com.slack.api.methods.MethodsClient;
+import com.slack.api.methods.SlackApiException;
+import com.slack.api.methods.SlackFilesUploadV2Exception;
+import com.slack.api.methods.request.chat.ChatPostMessageRequest;
+import com.slack.api.methods.request.conversations.ConversationsListRequest;
+import com.slack.api.methods.request.files.FilesUploadV2Request;
+import com.slack.api.methods.response.chat.ChatPostMessageResponse;
+import com.slack.api.methods.response.conversations.ConversationsListResponse;
+import com.slack.api.methods.response.files.FilesUploadV2Response;
+import com.slack.api.model.Conversation;
+import com.slack.api.model.File;
+import org.apache.nifi.annotation.behavior.DynamicProperty;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.expression.AttributeExpression;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.flowfile.attributes.CoreAttributes;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.slack.consume.ConsumeSlackUtil;
+import org.apache.nifi.processors.slack.publish.ContentMessageStrategy;
+import org.apache.nifi.processors.slack.publish.MessageOnlyStrategy;
+import org.apache.nifi.processors.slack.publish.PublishConfig;
+import org.apache.nifi.processors.slack.publish.PublishSlackClient;
+import org.apache.nifi.processors.slack.publish.PublishStrategy;
+import org.apache.nifi.processors.slack.publish.UploadAttachmentStrategy;
+import org.apache.nifi.processors.slack.publish.UploadLinkStrategy;
+import org.apache.nifi.processors.slack.publish.UploadOnlyStrategy;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import static org.apache.nifi.util.StringUtils.isEmpty;
+
+
+@Tags({"slack", "publish", "notify", "upload", "message"})
+@CapabilityDescription("Uploads the FlowFile content (e.g. an image) as a file, and/or Sends a message on Slack. The FlowFile content can be used as the message text or attached to the message.")
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@DynamicProperty(name = "<Arbitrary name>", value = "JSON snippet specifying a Slack message \"attachment\"",
+ description = "The property value will be converted to JSON and will be added to the array of attachments in the JSON payload being sent to Slack." +
+ " The property name will not be used by the processor.",
+ expressionLanguageScope = ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
Review Comment:
I'm not sure that I understand the concept here. As far as I understand it, Slack does not care about the attachment being JSON. Why does the processor care that it's JSON?
##########
nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/src/main/java/org/apache/nifi/processors/slack/PublishSlack.java:
##########
@@ -0,0 +1,516 @@
+/*
+ * 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.nifi.processors.slack;
+
+import com.slack.api.bolt.App;
+import com.slack.api.bolt.AppConfig;
+import com.slack.api.methods.MethodsClient;
+import com.slack.api.methods.SlackApiException;
+import com.slack.api.methods.SlackFilesUploadV2Exception;
+import com.slack.api.methods.request.chat.ChatPostMessageRequest;
+import com.slack.api.methods.request.conversations.ConversationsListRequest;
+import com.slack.api.methods.request.files.FilesUploadV2Request;
+import com.slack.api.methods.response.chat.ChatPostMessageResponse;
+import com.slack.api.methods.response.conversations.ConversationsListResponse;
+import com.slack.api.methods.response.files.FilesUploadV2Response;
+import com.slack.api.model.Conversation;
+import com.slack.api.model.File;
+import org.apache.nifi.annotation.behavior.DynamicProperty;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.expression.AttributeExpression;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.flowfile.attributes.CoreAttributes;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.slack.consume.ConsumeSlackUtil;
+import org.apache.nifi.processors.slack.publish.ContentMessageStrategy;
+import org.apache.nifi.processors.slack.publish.MessageOnlyStrategy;
+import org.apache.nifi.processors.slack.publish.PublishConfig;
+import org.apache.nifi.processors.slack.publish.PublishSlackClient;
+import org.apache.nifi.processors.slack.publish.PublishStrategy;
+import org.apache.nifi.processors.slack.publish.UploadAttachmentStrategy;
+import org.apache.nifi.processors.slack.publish.UploadLinkStrategy;
+import org.apache.nifi.processors.slack.publish.UploadOnlyStrategy;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import static org.apache.nifi.util.StringUtils.isEmpty;
+
+
+@Tags({"slack", "publish", "notify", "upload", "message"})
+@CapabilityDescription("Uploads the FlowFile content (e.g. an image) as a file, and/or Sends a message on Slack. The FlowFile content can be used as the message text or attached to the message.")
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@DynamicProperty(name = "<Arbitrary name>", value = "JSON snippet specifying a Slack message \"attachment\"",
+ description = "The property value will be converted to JSON and will be added to the array of attachments in the JSON payload being sent to Slack." +
+ " The property name will not be used by the processor.",
+ expressionLanguageScope = ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+@WritesAttribute(attribute="slack.file.url", description = "The Slack URL of the uploaded file. It will be added if 'Upload FlowFile' has been set to 'Yes'.")
+public class PublishSlack extends AbstractProcessor {
+
+ private static final String UPLOAD_ONLY = "upload-only";
+ private static final String MESSAGE_ONLY = "message-only";
+ private static final String CONTENT_MESSAGE = "content-message";
+ private static final String UPLOAD_ATTACH = "upload-attach";
+ private static final String UPLOAD_LINK = "upload-link";
+
+ public static final PropertyDescriptor BOT_TOKEN = new PropertyDescriptor.Builder()
+ .name("Bot Token")
+ .description("The Bot Token that is registered to your Slack application")
+ .addValidator(StandardValidators.NON_BLANK_VALIDATOR)
+ .required(true)
+ .sensitive(true)
+ .build();
+
+ public static final AllowableValue STRATEGY_UPLOAD_ONLY = new AllowableValue(
+ UPLOAD_ONLY,
+ "Upload File Content Only",
+ "Only upload the FlowFile content - it will be a visible Slack message if 'Upload Channel' is specified."
+ );
+
+ public static final AllowableValue STRATEGY_MESSAGE_ONLY = new AllowableValue(
+ MESSAGE_ONLY,
+ "Post Message Only",
+ "Post a simple Slack message with optional 'Text' and/or dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_CONTENT_MESSAGE = new AllowableValue(
+ CONTENT_MESSAGE,
+ "Post File Content as Message Text",
+ "Post the FlowFile content as a Slack message with optional dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_UPLOAD_ATTACH = new AllowableValue(
+ UPLOAD_ATTACH,
+ "Upload File Content as Attachment to Message",
+ "Upload the FlowFile content and add a link to the uploaded file as an attachment to the posted Slack message. The message will include optional dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_UPLOAD_LINK = new AllowableValue(
+ UPLOAD_LINK,
+ "Upload File Content as Embedded Link",
+ "Upload the FlowFile content and append a link to the uploaded file in the posted Slack message. The message will include optional dynamic Properties as attachments."
+ );
+
+ public static final PropertyDescriptor PUBLISH_STRATEGY = new PropertyDescriptor.Builder()
+ .name("publish-strategy")
+ .displayName("Publish Strategy")
+ .description("Determines how the FlowFile is sent to Slack and how it appears.")
+ .allowableValues(STRATEGY_UPLOAD_ONLY, STRATEGY_MESSAGE_ONLY, STRATEGY_CONTENT_MESSAGE, STRATEGY_UPLOAD_ATTACH, STRATEGY_UPLOAD_LINK)
+ .required(true)
+ .defaultValue(UPLOAD_ATTACH)
+ .build();
+
+ public static final PropertyDescriptor CHANNEL = new PropertyDescriptor.Builder()
+ .name("channel")
+ .displayName("Channel")
+ .description("Slack channel, private group, or IM channel to post the message to.")
+ .dependsOn(PUBLISH_STRATEGY, MESSAGE_ONLY, CONTENT_MESSAGE, UPLOAD_ATTACH, UPLOAD_LINK)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .build();
+
+ public static final PropertyDescriptor UPLOAD_CHANNEL = new PropertyDescriptor.Builder()
+ .name("upload-channel")
+ .displayName("Upload Channel")
+ .description("Slack channel, private group, or IM channel to upload the file to.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .build();
+
+ public static final PropertyDescriptor THREAD_TS = new PropertyDescriptor.Builder()
+ .name("Thread Timestamp")
+ .description("The timestamp of the parent message, also known as a thread_ts, or Thread Timestamp. If not specified, the message will be send to the channel " +
+ "as an independent message. If this value is populated, the message will be sent as a reply to the message whose timestamp is equal to the given value.")
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .build();
+
+ public static final PropertyDescriptor TEXT = new PropertyDescriptor.Builder()
+ .name("text")
+ .displayName("Text")
+ .description("Text of the Slack message to send. Only required if no attachment has been specified and 'Upload File' has been set to 'No'.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .build();
+
+ public static final PropertyDescriptor INITIAL_COMMENT = new PropertyDescriptor.Builder()
Review Comment:
Not sure that I understand the difference between 'Text' and 'Initial Comment'
##########
nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/src/main/java/org/apache/nifi/processors/slack/PublishSlack.java:
##########
@@ -0,0 +1,516 @@
+/*
+ * 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.nifi.processors.slack;
+
+import com.slack.api.bolt.App;
+import com.slack.api.bolt.AppConfig;
+import com.slack.api.methods.MethodsClient;
+import com.slack.api.methods.SlackApiException;
+import com.slack.api.methods.SlackFilesUploadV2Exception;
+import com.slack.api.methods.request.chat.ChatPostMessageRequest;
+import com.slack.api.methods.request.conversations.ConversationsListRequest;
+import com.slack.api.methods.request.files.FilesUploadV2Request;
+import com.slack.api.methods.response.chat.ChatPostMessageResponse;
+import com.slack.api.methods.response.conversations.ConversationsListResponse;
+import com.slack.api.methods.response.files.FilesUploadV2Response;
+import com.slack.api.model.Conversation;
+import com.slack.api.model.File;
+import org.apache.nifi.annotation.behavior.DynamicProperty;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.expression.AttributeExpression;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.flowfile.attributes.CoreAttributes;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.slack.consume.ConsumeSlackUtil;
+import org.apache.nifi.processors.slack.publish.ContentMessageStrategy;
+import org.apache.nifi.processors.slack.publish.MessageOnlyStrategy;
+import org.apache.nifi.processors.slack.publish.PublishConfig;
+import org.apache.nifi.processors.slack.publish.PublishSlackClient;
+import org.apache.nifi.processors.slack.publish.PublishStrategy;
+import org.apache.nifi.processors.slack.publish.UploadAttachmentStrategy;
+import org.apache.nifi.processors.slack.publish.UploadLinkStrategy;
+import org.apache.nifi.processors.slack.publish.UploadOnlyStrategy;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import static org.apache.nifi.util.StringUtils.isEmpty;
+
+
+@Tags({"slack", "publish", "notify", "upload", "message"})
+@CapabilityDescription("Uploads the FlowFile content (e.g. an image) as a file, and/or Sends a message on Slack. The FlowFile content can be used as the message text or attached to the message.")
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@DynamicProperty(name = "<Arbitrary name>", value = "JSON snippet specifying a Slack message \"attachment\"",
+ description = "The property value will be converted to JSON and will be added to the array of attachments in the JSON payload being sent to Slack." +
+ " The property name will not be used by the processor.",
+ expressionLanguageScope = ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+@WritesAttribute(attribute="slack.file.url", description = "The Slack URL of the uploaded file. It will be added if 'Upload FlowFile' has been set to 'Yes'.")
+public class PublishSlack extends AbstractProcessor {
+
+ private static final String UPLOAD_ONLY = "upload-only";
+ private static final String MESSAGE_ONLY = "message-only";
+ private static final String CONTENT_MESSAGE = "content-message";
+ private static final String UPLOAD_ATTACH = "upload-attach";
+ private static final String UPLOAD_LINK = "upload-link";
+
+ public static final PropertyDescriptor BOT_TOKEN = new PropertyDescriptor.Builder()
+ .name("Bot Token")
+ .description("The Bot Token that is registered to your Slack application")
+ .addValidator(StandardValidators.NON_BLANK_VALIDATOR)
+ .required(true)
+ .sensitive(true)
+ .build();
+
+ public static final AllowableValue STRATEGY_UPLOAD_ONLY = new AllowableValue(
+ UPLOAD_ONLY,
+ "Upload File Content Only",
+ "Only upload the FlowFile content - it will be a visible Slack message if 'Upload Channel' is specified."
+ );
+
+ public static final AllowableValue STRATEGY_MESSAGE_ONLY = new AllowableValue(
+ MESSAGE_ONLY,
+ "Post Message Only",
+ "Post a simple Slack message with optional 'Text' and/or dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_CONTENT_MESSAGE = new AllowableValue(
+ CONTENT_MESSAGE,
+ "Post File Content as Message Text",
+ "Post the FlowFile content as a Slack message with optional dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_UPLOAD_ATTACH = new AllowableValue(
+ UPLOAD_ATTACH,
+ "Upload File Content as Attachment to Message",
+ "Upload the FlowFile content and add a link to the uploaded file as an attachment to the posted Slack message. The message will include optional dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_UPLOAD_LINK = new AllowableValue(
+ UPLOAD_LINK,
+ "Upload File Content as Embedded Link",
+ "Upload the FlowFile content and append a link to the uploaded file in the posted Slack message. The message will include optional dynamic Properties as attachments."
+ );
+
+ public static final PropertyDescriptor PUBLISH_STRATEGY = new PropertyDescriptor.Builder()
+ .name("publish-strategy")
+ .displayName("Publish Strategy")
+ .description("Determines how the FlowFile is sent to Slack and how it appears.")
+ .allowableValues(STRATEGY_UPLOAD_ONLY, STRATEGY_MESSAGE_ONLY, STRATEGY_CONTENT_MESSAGE, STRATEGY_UPLOAD_ATTACH, STRATEGY_UPLOAD_LINK)
+ .required(true)
+ .defaultValue(UPLOAD_ATTACH)
+ .build();
+
+ public static final PropertyDescriptor CHANNEL = new PropertyDescriptor.Builder()
+ .name("channel")
+ .displayName("Channel")
Review Comment:
Same comment on all of these, using just `.name()` instead of using both a name and a display name.
##########
nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/src/main/java/org/apache/nifi/processors/slack/PublishSlack.java:
##########
@@ -0,0 +1,516 @@
+/*
+ * 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.nifi.processors.slack;
+
+import com.slack.api.bolt.App;
+import com.slack.api.bolt.AppConfig;
+import com.slack.api.methods.MethodsClient;
+import com.slack.api.methods.SlackApiException;
+import com.slack.api.methods.SlackFilesUploadV2Exception;
+import com.slack.api.methods.request.chat.ChatPostMessageRequest;
+import com.slack.api.methods.request.conversations.ConversationsListRequest;
+import com.slack.api.methods.request.files.FilesUploadV2Request;
+import com.slack.api.methods.response.chat.ChatPostMessageResponse;
+import com.slack.api.methods.response.conversations.ConversationsListResponse;
+import com.slack.api.methods.response.files.FilesUploadV2Response;
+import com.slack.api.model.Conversation;
+import com.slack.api.model.File;
+import org.apache.nifi.annotation.behavior.DynamicProperty;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.expression.AttributeExpression;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.flowfile.attributes.CoreAttributes;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.slack.consume.ConsumeSlackUtil;
+import org.apache.nifi.processors.slack.publish.ContentMessageStrategy;
+import org.apache.nifi.processors.slack.publish.MessageOnlyStrategy;
+import org.apache.nifi.processors.slack.publish.PublishConfig;
+import org.apache.nifi.processors.slack.publish.PublishSlackClient;
+import org.apache.nifi.processors.slack.publish.PublishStrategy;
+import org.apache.nifi.processors.slack.publish.UploadAttachmentStrategy;
+import org.apache.nifi.processors.slack.publish.UploadLinkStrategy;
+import org.apache.nifi.processors.slack.publish.UploadOnlyStrategy;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import static org.apache.nifi.util.StringUtils.isEmpty;
+
+
+@Tags({"slack", "publish", "notify", "upload", "message"})
+@CapabilityDescription("Uploads the FlowFile content (e.g. an image) as a file, and/or Sends a message on Slack. The FlowFile content can be used as the message text or attached to the message.")
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@DynamicProperty(name = "<Arbitrary name>", value = "JSON snippet specifying a Slack message \"attachment\"",
+ description = "The property value will be converted to JSON and will be added to the array of attachments in the JSON payload being sent to Slack." +
+ " The property name will not be used by the processor.",
+ expressionLanguageScope = ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+@WritesAttribute(attribute="slack.file.url", description = "The Slack URL of the uploaded file. It will be added if 'Upload FlowFile' has been set to 'Yes'.")
+public class PublishSlack extends AbstractProcessor {
+
+ private static final String UPLOAD_ONLY = "upload-only";
+ private static final String MESSAGE_ONLY = "message-only";
+ private static final String CONTENT_MESSAGE = "content-message";
+ private static final String UPLOAD_ATTACH = "upload-attach";
+ private static final String UPLOAD_LINK = "upload-link";
+
+ public static final PropertyDescriptor BOT_TOKEN = new PropertyDescriptor.Builder()
+ .name("Bot Token")
+ .description("The Bot Token that is registered to your Slack application")
+ .addValidator(StandardValidators.NON_BLANK_VALIDATOR)
+ .required(true)
+ .sensitive(true)
+ .build();
+
+ public static final AllowableValue STRATEGY_UPLOAD_ONLY = new AllowableValue(
+ UPLOAD_ONLY,
+ "Upload File Content Only",
+ "Only upload the FlowFile content - it will be a visible Slack message if 'Upload Channel' is specified."
+ );
+
+ public static final AllowableValue STRATEGY_MESSAGE_ONLY = new AllowableValue(
+ MESSAGE_ONLY,
+ "Post Message Only",
+ "Post a simple Slack message with optional 'Text' and/or dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_CONTENT_MESSAGE = new AllowableValue(
+ CONTENT_MESSAGE,
+ "Post File Content as Message Text",
+ "Post the FlowFile content as a Slack message with optional dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_UPLOAD_ATTACH = new AllowableValue(
+ UPLOAD_ATTACH,
+ "Upload File Content as Attachment to Message",
+ "Upload the FlowFile content and add a link to the uploaded file as an attachment to the posted Slack message. The message will include optional dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_UPLOAD_LINK = new AllowableValue(
+ UPLOAD_LINK,
+ "Upload File Content as Embedded Link",
+ "Upload the FlowFile content and append a link to the uploaded file in the posted Slack message. The message will include optional dynamic Properties as attachments."
+ );
+
+ public static final PropertyDescriptor PUBLISH_STRATEGY = new PropertyDescriptor.Builder()
+ .name("publish-strategy")
+ .displayName("Publish Strategy")
+ .description("Determines how the FlowFile is sent to Slack and how it appears.")
+ .allowableValues(STRATEGY_UPLOAD_ONLY, STRATEGY_MESSAGE_ONLY, STRATEGY_CONTENT_MESSAGE, STRATEGY_UPLOAD_ATTACH, STRATEGY_UPLOAD_LINK)
+ .required(true)
+ .defaultValue(UPLOAD_ATTACH)
+ .build();
+
+ public static final PropertyDescriptor CHANNEL = new PropertyDescriptor.Builder()
+ .name("channel")
+ .displayName("Channel")
+ .description("Slack channel, private group, or IM channel to post the message to.")
+ .dependsOn(PUBLISH_STRATEGY, MESSAGE_ONLY, CONTENT_MESSAGE, UPLOAD_ATTACH, UPLOAD_LINK)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .build();
+
+ public static final PropertyDescriptor UPLOAD_CHANNEL = new PropertyDescriptor.Builder()
+ .name("upload-channel")
+ .displayName("Upload Channel")
+ .description("Slack channel, private group, or IM channel to upload the file to.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .build();
+
+ public static final PropertyDescriptor THREAD_TS = new PropertyDescriptor.Builder()
+ .name("Thread Timestamp")
+ .description("The timestamp of the parent message, also known as a thread_ts, or Thread Timestamp. If not specified, the message will be send to the channel " +
+ "as an independent message. If this value is populated, the message will be sent as a reply to the message whose timestamp is equal to the given value.")
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .build();
+
+ public static final PropertyDescriptor TEXT = new PropertyDescriptor.Builder()
+ .name("text")
+ .displayName("Text")
+ .description("Text of the Slack message to send. Only required if no attachment has been specified and 'Upload File' has been set to 'No'.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .build();
+
+ public static final PropertyDescriptor INITIAL_COMMENT = new PropertyDescriptor.Builder()
+ .name("upload-text")
+ .displayName("Upload Text")
+ .description("Text of the Slack message to include with a public upload. Only used if 'Publish Mode' has been set to 'Upload Only' and 'Upload Channel' is specified.")
+ .dependsOn(PUBLISH_STRATEGY, UPLOAD_ONLY)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .build();
+
+ public static final PropertyDescriptor FILE_TITLE = new PropertyDescriptor.Builder()
+ .name("file-title")
+ .displayName("File Title")
+ .description("Title of the file displayed in the Slack message." +
+ " The property value will only be used if 'Upload FlowFile' has been set to 'Yes'.")
+ .dependsOn(PUBLISH_STRATEGY, UPLOAD_ONLY, UPLOAD_ATTACH, UPLOAD_LINK)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .build();
+
+ public static final PropertyDescriptor FILE_NAME = new PropertyDescriptor.Builder()
+ .name("file-name")
+ .displayName("File Name")
+ .description("Name of the file to be uploaded." +
+ " The property value will only be used if 'Upload FlowFile' has been set to 'Yes'." +
+ " If the property evaluated to null or empty string, then the file name will be set to 'file' in the Slack message.")
+ .dependsOn(PUBLISH_STRATEGY, UPLOAD_ONLY, UPLOAD_ATTACH, UPLOAD_LINK)
+ .defaultValue("${" + CoreAttributes.FILENAME.key() + "}")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .build();
Review Comment:
Specifying the filename is not really necessary, since there is already a well-known attribute that specifies the filename. If user was to use a different filename, they should change the filename attribute. While having the extra property doesn't necessarily hurt anything, it does lead to more properties that the user is forced to consider, so best to avoid.
##########
nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/src/main/java/org/apache/nifi/processors/slack/PublishSlack.java:
##########
@@ -0,0 +1,516 @@
+/*
+ * 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.nifi.processors.slack;
+
+import com.slack.api.bolt.App;
+import com.slack.api.bolt.AppConfig;
+import com.slack.api.methods.MethodsClient;
+import com.slack.api.methods.SlackApiException;
+import com.slack.api.methods.SlackFilesUploadV2Exception;
+import com.slack.api.methods.request.chat.ChatPostMessageRequest;
+import com.slack.api.methods.request.conversations.ConversationsListRequest;
+import com.slack.api.methods.request.files.FilesUploadV2Request;
+import com.slack.api.methods.response.chat.ChatPostMessageResponse;
+import com.slack.api.methods.response.conversations.ConversationsListResponse;
+import com.slack.api.methods.response.files.FilesUploadV2Response;
+import com.slack.api.model.Conversation;
+import com.slack.api.model.File;
+import org.apache.nifi.annotation.behavior.DynamicProperty;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.expression.AttributeExpression;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.flowfile.attributes.CoreAttributes;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.slack.consume.ConsumeSlackUtil;
+import org.apache.nifi.processors.slack.publish.ContentMessageStrategy;
+import org.apache.nifi.processors.slack.publish.MessageOnlyStrategy;
+import org.apache.nifi.processors.slack.publish.PublishConfig;
+import org.apache.nifi.processors.slack.publish.PublishSlackClient;
+import org.apache.nifi.processors.slack.publish.PublishStrategy;
+import org.apache.nifi.processors.slack.publish.UploadAttachmentStrategy;
+import org.apache.nifi.processors.slack.publish.UploadLinkStrategy;
+import org.apache.nifi.processors.slack.publish.UploadOnlyStrategy;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import static org.apache.nifi.util.StringUtils.isEmpty;
+
+
+@Tags({"slack", "publish", "notify", "upload", "message"})
+@CapabilityDescription("Uploads the FlowFile content (e.g. an image) as a file, and/or Sends a message on Slack. The FlowFile content can be used as the message text or attached to the message.")
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@DynamicProperty(name = "<Arbitrary name>", value = "JSON snippet specifying a Slack message \"attachment\"",
+ description = "The property value will be converted to JSON and will be added to the array of attachments in the JSON payload being sent to Slack." +
+ " The property name will not be used by the processor.",
+ expressionLanguageScope = ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+@WritesAttribute(attribute="slack.file.url", description = "The Slack URL of the uploaded file. It will be added if 'Upload FlowFile' has been set to 'Yes'.")
+public class PublishSlack extends AbstractProcessor {
+
+ private static final String UPLOAD_ONLY = "upload-only";
+ private static final String MESSAGE_ONLY = "message-only";
+ private static final String CONTENT_MESSAGE = "content-message";
+ private static final String UPLOAD_ATTACH = "upload-attach";
+ private static final String UPLOAD_LINK = "upload-link";
+
+ public static final PropertyDescriptor BOT_TOKEN = new PropertyDescriptor.Builder()
+ .name("Bot Token")
+ .description("The Bot Token that is registered to your Slack application")
+ .addValidator(StandardValidators.NON_BLANK_VALIDATOR)
+ .required(true)
+ .sensitive(true)
+ .build();
+
+ public static final AllowableValue STRATEGY_UPLOAD_ONLY = new AllowableValue(
+ UPLOAD_ONLY,
+ "Upload File Content Only",
+ "Only upload the FlowFile content - it will be a visible Slack message if 'Upload Channel' is specified."
+ );
+
+ public static final AllowableValue STRATEGY_MESSAGE_ONLY = new AllowableValue(
+ MESSAGE_ONLY,
+ "Post Message Only",
+ "Post a simple Slack message with optional 'Text' and/or dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_CONTENT_MESSAGE = new AllowableValue(
+ CONTENT_MESSAGE,
+ "Post File Content as Message Text",
+ "Post the FlowFile content as a Slack message with optional dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_UPLOAD_ATTACH = new AllowableValue(
+ UPLOAD_ATTACH,
+ "Upload File Content as Attachment to Message",
+ "Upload the FlowFile content and add a link to the uploaded file as an attachment to the posted Slack message. The message will include optional dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_UPLOAD_LINK = new AllowableValue(
+ UPLOAD_LINK,
+ "Upload File Content as Embedded Link",
+ "Upload the FlowFile content and append a link to the uploaded file in the posted Slack message. The message will include optional dynamic Properties as attachments."
+ );
+
+ public static final PropertyDescriptor PUBLISH_STRATEGY = new PropertyDescriptor.Builder()
+ .name("publish-strategy")
+ .displayName("Publish Strategy")
+ .description("Determines how the FlowFile is sent to Slack and how it appears.")
+ .allowableValues(STRATEGY_UPLOAD_ONLY, STRATEGY_MESSAGE_ONLY, STRATEGY_CONTENT_MESSAGE, STRATEGY_UPLOAD_ATTACH, STRATEGY_UPLOAD_LINK)
+ .required(true)
+ .defaultValue(UPLOAD_ATTACH)
+ .build();
+
+ public static final PropertyDescriptor CHANNEL = new PropertyDescriptor.Builder()
+ .name("channel")
+ .displayName("Channel")
+ .description("Slack channel, private group, or IM channel to post the message to.")
+ .dependsOn(PUBLISH_STRATEGY, MESSAGE_ONLY, CONTENT_MESSAGE, UPLOAD_ATTACH, UPLOAD_LINK)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .build();
+
+ public static final PropertyDescriptor UPLOAD_CHANNEL = new PropertyDescriptor.Builder()
+ .name("upload-channel")
+ .displayName("Upload Channel")
+ .description("Slack channel, private group, or IM channel to upload the file to.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .build();
+
+ public static final PropertyDescriptor THREAD_TS = new PropertyDescriptor.Builder()
+ .name("Thread Timestamp")
+ .description("The timestamp of the parent message, also known as a thread_ts, or Thread Timestamp. If not specified, the message will be send to the channel " +
+ "as an independent message. If this value is populated, the message will be sent as a reply to the message whose timestamp is equal to the given value.")
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .build();
+
+ public static final PropertyDescriptor TEXT = new PropertyDescriptor.Builder()
+ .name("text")
+ .displayName("Text")
+ .description("Text of the Slack message to send. Only required if no attachment has been specified and 'Upload File' has been set to 'No'.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .build();
+
+ public static final PropertyDescriptor INITIAL_COMMENT = new PropertyDescriptor.Builder()
+ .name("upload-text")
+ .displayName("Upload Text")
+ .description("Text of the Slack message to include with a public upload. Only used if 'Publish Mode' has been set to 'Upload Only' and 'Upload Channel' is specified.")
+ .dependsOn(PUBLISH_STRATEGY, UPLOAD_ONLY)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .build();
+
+ public static final PropertyDescriptor FILE_TITLE = new PropertyDescriptor.Builder()
Review Comment:
I would actually lean toward removing this property all together. Like Filename, it can easily default to the just using the `filename` attribute and the user can change the `filename` attribute as necessary.
##########
nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/src/main/java/org/apache/nifi/processors/slack/PublishSlack.java:
##########
@@ -0,0 +1,516 @@
+/*
+ * 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.nifi.processors.slack;
+
+import com.slack.api.bolt.App;
+import com.slack.api.bolt.AppConfig;
+import com.slack.api.methods.MethodsClient;
+import com.slack.api.methods.SlackApiException;
+import com.slack.api.methods.SlackFilesUploadV2Exception;
+import com.slack.api.methods.request.chat.ChatPostMessageRequest;
+import com.slack.api.methods.request.conversations.ConversationsListRequest;
+import com.slack.api.methods.request.files.FilesUploadV2Request;
+import com.slack.api.methods.response.chat.ChatPostMessageResponse;
+import com.slack.api.methods.response.conversations.ConversationsListResponse;
+import com.slack.api.methods.response.files.FilesUploadV2Response;
+import com.slack.api.model.Conversation;
+import com.slack.api.model.File;
+import org.apache.nifi.annotation.behavior.DynamicProperty;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.expression.AttributeExpression;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.flowfile.attributes.CoreAttributes;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.slack.consume.ConsumeSlackUtil;
+import org.apache.nifi.processors.slack.publish.ContentMessageStrategy;
+import org.apache.nifi.processors.slack.publish.MessageOnlyStrategy;
+import org.apache.nifi.processors.slack.publish.PublishConfig;
+import org.apache.nifi.processors.slack.publish.PublishSlackClient;
+import org.apache.nifi.processors.slack.publish.PublishStrategy;
+import org.apache.nifi.processors.slack.publish.UploadAttachmentStrategy;
+import org.apache.nifi.processors.slack.publish.UploadLinkStrategy;
+import org.apache.nifi.processors.slack.publish.UploadOnlyStrategy;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import static org.apache.nifi.util.StringUtils.isEmpty;
+
+
+@Tags({"slack", "publish", "notify", "upload", "message"})
+@CapabilityDescription("Uploads the FlowFile content (e.g. an image) as a file, and/or Sends a message on Slack. The FlowFile content can be used as the message text or attached to the message.")
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@DynamicProperty(name = "<Arbitrary name>", value = "JSON snippet specifying a Slack message \"attachment\"",
+ description = "The property value will be converted to JSON and will be added to the array of attachments in the JSON payload being sent to Slack." +
+ " The property name will not be used by the processor.",
+ expressionLanguageScope = ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+@WritesAttribute(attribute="slack.file.url", description = "The Slack URL of the uploaded file. It will be added if 'Upload FlowFile' has been set to 'Yes'.")
+public class PublishSlack extends AbstractProcessor {
+
+ private static final String UPLOAD_ONLY = "upload-only";
+ private static final String MESSAGE_ONLY = "message-only";
+ private static final String CONTENT_MESSAGE = "content-message";
+ private static final String UPLOAD_ATTACH = "upload-attach";
+ private static final String UPLOAD_LINK = "upload-link";
+
+ public static final PropertyDescriptor BOT_TOKEN = new PropertyDescriptor.Builder()
+ .name("Bot Token")
+ .description("The Bot Token that is registered to your Slack application")
+ .addValidator(StandardValidators.NON_BLANK_VALIDATOR)
+ .required(true)
+ .sensitive(true)
+ .build();
+
+ public static final AllowableValue STRATEGY_UPLOAD_ONLY = new AllowableValue(
+ UPLOAD_ONLY,
+ "Upload File Content Only",
+ "Only upload the FlowFile content - it will be a visible Slack message if 'Upload Channel' is specified."
+ );
+
+ public static final AllowableValue STRATEGY_MESSAGE_ONLY = new AllowableValue(
+ MESSAGE_ONLY,
+ "Post Message Only",
+ "Post a simple Slack message with optional 'Text' and/or dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_CONTENT_MESSAGE = new AllowableValue(
+ CONTENT_MESSAGE,
+ "Post File Content as Message Text",
+ "Post the FlowFile content as a Slack message with optional dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_UPLOAD_ATTACH = new AllowableValue(
+ UPLOAD_ATTACH,
+ "Upload File Content as Attachment to Message",
+ "Upload the FlowFile content and add a link to the uploaded file as an attachment to the posted Slack message. The message will include optional dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_UPLOAD_LINK = new AllowableValue(
+ UPLOAD_LINK,
+ "Upload File Content as Embedded Link",
+ "Upload the FlowFile content and append a link to the uploaded file in the posted Slack message. The message will include optional dynamic Properties as attachments."
+ );
+
+ public static final PropertyDescriptor PUBLISH_STRATEGY = new PropertyDescriptor.Builder()
+ .name("publish-strategy")
+ .displayName("Publish Strategy")
+ .description("Determines how the FlowFile is sent to Slack and how it appears.")
+ .allowableValues(STRATEGY_UPLOAD_ONLY, STRATEGY_MESSAGE_ONLY, STRATEGY_CONTENT_MESSAGE, STRATEGY_UPLOAD_ATTACH, STRATEGY_UPLOAD_LINK)
+ .required(true)
+ .defaultValue(UPLOAD_ATTACH)
+ .build();
+
+ public static final PropertyDescriptor CHANNEL = new PropertyDescriptor.Builder()
Review Comment:
Should be required.
--
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.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-12331: add new unified PublishSlack Processor [nifi]
Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory closed pull request #8047: NIFI-12331: add new unified PublishSlack Processor
URL: https://github.com/apache/nifi/pull/8047
--
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.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-12331: add new unified PublishSlack Processor [nifi]
Posted by "krisztina-zsihovszki (via GitHub)" <gi...@apache.org>.
krisztina-zsihovszki commented on code in PR #8047:
URL: https://github.com/apache/nifi/pull/8047#discussion_r1414309808
##########
nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/src/main/java/org/apache/nifi/processors/slack/PublishSlack.java:
##########
@@ -0,0 +1,516 @@
+/*
+ * 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.nifi.processors.slack;
+
+import com.slack.api.bolt.App;
+import com.slack.api.bolt.AppConfig;
+import com.slack.api.methods.MethodsClient;
+import com.slack.api.methods.SlackApiException;
+import com.slack.api.methods.SlackFilesUploadV2Exception;
+import com.slack.api.methods.request.chat.ChatPostMessageRequest;
+import com.slack.api.methods.request.conversations.ConversationsListRequest;
+import com.slack.api.methods.request.files.FilesUploadV2Request;
+import com.slack.api.methods.response.chat.ChatPostMessageResponse;
+import com.slack.api.methods.response.conversations.ConversationsListResponse;
+import com.slack.api.methods.response.files.FilesUploadV2Response;
+import com.slack.api.model.Conversation;
+import com.slack.api.model.File;
+import org.apache.nifi.annotation.behavior.DynamicProperty;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.expression.AttributeExpression;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.flowfile.attributes.CoreAttributes;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.slack.consume.ConsumeSlackUtil;
+import org.apache.nifi.processors.slack.publish.ContentMessageStrategy;
+import org.apache.nifi.processors.slack.publish.MessageOnlyStrategy;
+import org.apache.nifi.processors.slack.publish.PublishConfig;
+import org.apache.nifi.processors.slack.publish.PublishSlackClient;
+import org.apache.nifi.processors.slack.publish.PublishStrategy;
+import org.apache.nifi.processors.slack.publish.UploadAttachmentStrategy;
+import org.apache.nifi.processors.slack.publish.UploadLinkStrategy;
+import org.apache.nifi.processors.slack.publish.UploadOnlyStrategy;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import static org.apache.nifi.util.StringUtils.isEmpty;
+
+
+@Tags({"slack", "publish", "notify", "upload", "message"})
+@CapabilityDescription("Uploads the FlowFile content (e.g. an image) as a file, and/or Sends a message on Slack. The FlowFile content can be used as the message text or attached to the message.")
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@DynamicProperty(name = "<Arbitrary name>", value = "JSON snippet specifying a Slack message \"attachment\"",
+ description = "The property value will be converted to JSON and will be added to the array of attachments in the JSON payload being sent to Slack." +
+ " The property name will not be used by the processor.",
+ expressionLanguageScope = ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+@WritesAttribute(attribute="slack.file.url", description = "The Slack URL of the uploaded file. It will be added if 'Upload FlowFile' has been set to 'Yes'.")
+public class PublishSlack extends AbstractProcessor {
+
+ private static final String UPLOAD_ONLY = "upload-only";
+ private static final String MESSAGE_ONLY = "message-only";
+ private static final String CONTENT_MESSAGE = "content-message";
+ private static final String UPLOAD_ATTACH = "upload-attach";
+ private static final String UPLOAD_LINK = "upload-link";
+
+ public static final PropertyDescriptor BOT_TOKEN = new PropertyDescriptor.Builder()
+ .name("Bot Token")
+ .description("The Bot Token that is registered to your Slack application")
Review Comment:
It'd be very useful if the required scopes would be listed here as it is done e.g. for ConsumeSlack ACCESS_TOKEN property.
##########
nifi-nar-bundles/nifi-slack-bundle/nifi-slack-processors/src/main/java/org/apache/nifi/processors/slack/PublishSlack.java:
##########
@@ -0,0 +1,516 @@
+/*
+ * 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.nifi.processors.slack;
+
+import com.slack.api.bolt.App;
+import com.slack.api.bolt.AppConfig;
+import com.slack.api.methods.MethodsClient;
+import com.slack.api.methods.SlackApiException;
+import com.slack.api.methods.SlackFilesUploadV2Exception;
+import com.slack.api.methods.request.chat.ChatPostMessageRequest;
+import com.slack.api.methods.request.conversations.ConversationsListRequest;
+import com.slack.api.methods.request.files.FilesUploadV2Request;
+import com.slack.api.methods.response.chat.ChatPostMessageResponse;
+import com.slack.api.methods.response.conversations.ConversationsListResponse;
+import com.slack.api.methods.response.files.FilesUploadV2Response;
+import com.slack.api.model.Conversation;
+import com.slack.api.model.File;
+import org.apache.nifi.annotation.behavior.DynamicProperty;
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.components.AllowableValue;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.expression.AttributeExpression;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.flowfile.attributes.CoreAttributes;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.slack.consume.ConsumeSlackUtil;
+import org.apache.nifi.processors.slack.publish.ContentMessageStrategy;
+import org.apache.nifi.processors.slack.publish.MessageOnlyStrategy;
+import org.apache.nifi.processors.slack.publish.PublishConfig;
+import org.apache.nifi.processors.slack.publish.PublishSlackClient;
+import org.apache.nifi.processors.slack.publish.PublishStrategy;
+import org.apache.nifi.processors.slack.publish.UploadAttachmentStrategy;
+import org.apache.nifi.processors.slack.publish.UploadLinkStrategy;
+import org.apache.nifi.processors.slack.publish.UploadOnlyStrategy;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import static org.apache.nifi.util.StringUtils.isEmpty;
+
+
+@Tags({"slack", "publish", "notify", "upload", "message"})
+@CapabilityDescription("Uploads the FlowFile content (e.g. an image) as a file, and/or Sends a message on Slack. The FlowFile content can be used as the message text or attached to the message.")
+@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
+@DynamicProperty(name = "<Arbitrary name>", value = "JSON snippet specifying a Slack message \"attachment\"",
+ description = "The property value will be converted to JSON and will be added to the array of attachments in the JSON payload being sent to Slack." +
+ " The property name will not be used by the processor.",
+ expressionLanguageScope = ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+@WritesAttribute(attribute="slack.file.url", description = "The Slack URL of the uploaded file. It will be added if 'Upload FlowFile' has been set to 'Yes'.")
+public class PublishSlack extends AbstractProcessor {
+
+ private static final String UPLOAD_ONLY = "upload-only";
+ private static final String MESSAGE_ONLY = "message-only";
+ private static final String CONTENT_MESSAGE = "content-message";
+ private static final String UPLOAD_ATTACH = "upload-attach";
+ private static final String UPLOAD_LINK = "upload-link";
+
+ public static final PropertyDescriptor BOT_TOKEN = new PropertyDescriptor.Builder()
+ .name("Bot Token")
+ .description("The Bot Token that is registered to your Slack application")
+ .addValidator(StandardValidators.NON_BLANK_VALIDATOR)
+ .required(true)
+ .sensitive(true)
+ .build();
+
+ public static final AllowableValue STRATEGY_UPLOAD_ONLY = new AllowableValue(
+ UPLOAD_ONLY,
+ "Upload File Content Only",
+ "Only upload the FlowFile content - it will be a visible Slack message if 'Upload Channel' is specified."
+ );
+
+ public static final AllowableValue STRATEGY_MESSAGE_ONLY = new AllowableValue(
+ MESSAGE_ONLY,
+ "Post Message Only",
+ "Post a simple Slack message with optional 'Text' and/or dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_CONTENT_MESSAGE = new AllowableValue(
+ CONTENT_MESSAGE,
+ "Post File Content as Message Text",
+ "Post the FlowFile content as a Slack message with optional dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_UPLOAD_ATTACH = new AllowableValue(
+ UPLOAD_ATTACH,
+ "Upload File Content as Attachment to Message",
+ "Upload the FlowFile content and add a link to the uploaded file as an attachment to the posted Slack message. The message will include optional dynamic Properties as attachments."
+ );
+
+ public static final AllowableValue STRATEGY_UPLOAD_LINK = new AllowableValue(
+ UPLOAD_LINK,
+ "Upload File Content as Embedded Link",
+ "Upload the FlowFile content and append a link to the uploaded file in the posted Slack message. The message will include optional dynamic Properties as attachments."
+ );
+
+ public static final PropertyDescriptor PUBLISH_STRATEGY = new PropertyDescriptor.Builder()
+ .name("publish-strategy")
+ .displayName("Publish Strategy")
+ .description("Determines how the FlowFile is sent to Slack and how it appears.")
+ .allowableValues(STRATEGY_UPLOAD_ONLY, STRATEGY_MESSAGE_ONLY, STRATEGY_CONTENT_MESSAGE, STRATEGY_UPLOAD_ATTACH, STRATEGY_UPLOAD_LINK)
+ .required(true)
+ .defaultValue(UPLOAD_ATTACH)
+ .build();
+
+ public static final PropertyDescriptor CHANNEL = new PropertyDescriptor.Builder()
+ .name("channel")
+ .displayName("Channel")
+ .description("Slack channel, private group, or IM channel to post the message to.")
+ .dependsOn(PUBLISH_STRATEGY, MESSAGE_ONLY, CONTENT_MESSAGE, UPLOAD_ATTACH, UPLOAD_LINK)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .build();
+
+ public static final PropertyDescriptor UPLOAD_CHANNEL = new PropertyDescriptor.Builder()
+ .name("upload-channel")
+ .displayName("Upload Channel")
+ .description("Slack channel, private group, or IM channel to upload the file to.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .build();
+
+ public static final PropertyDescriptor THREAD_TS = new PropertyDescriptor.Builder()
+ .name("Thread Timestamp")
+ .description("The timestamp of the parent message, also known as a thread_ts, or Thread Timestamp. If not specified, the message will be send to the channel " +
+ "as an independent message. If this value is populated, the message will be sent as a reply to the message whose timestamp is equal to the given value.")
+ .required(false)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .build();
+
+ public static final PropertyDescriptor TEXT = new PropertyDescriptor.Builder()
+ .name("text")
+ .displayName("Text")
+ .description("Text of the Slack message to send. Only required if no attachment has been specified and 'Upload File' has been set to 'No'.")
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+ .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+ .build();
+
+ public static final PropertyDescriptor INITIAL_COMMENT = new PropertyDescriptor.Builder()
+ .name("upload-text")
+ .displayName("Upload Text")
+ .description("Text of the Slack message to include with a public upload. Only used if 'Publish Mode' has been set to 'Upload Only' and 'Upload Channel' is specified.")
Review Comment:
I believe 'Publish Mode' was changed to 'Publish Strategy' and 'Upload Only' is now 'Upload File Content Only'
--
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.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-12331: add new unified PublishSlack Processor [nifi]
Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on PR #8047:
URL: https://github.com/apache/nifi/pull/8047#issuecomment-1839995418
Thanks for your work on this new Processor @sporadek, it provided helpful background for subsequent follow-on work in PR #8120. Thanks for the review as well @krisztina-zsihovszki. The other pull request is close to completion, so I am closing this PR in favor of the others.
--
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.
To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org