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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
