PublishSlack 2.0.0

Bundle
org.apache.nifi | nifi-slack-nar
Description
Posts a message to the specified Slack channel. The content of the message can be either a user-defined message that makes use of Expression Language or the contents of the FlowFile can be sent as the message. If sending a user-defined message, the contents of the FlowFile may also be optionally uploaded as a file attachment.
Tags
chat.postMessage, conversation, publish, send, slack, social media, team, text, unstructured, upload, write
Input Requirement
REQUIRED
Supports Sensitive Dynamic Properties
false
  • Additional Details for PublishSlack 2.0.0

    PublishSlack

    Description:

    PublishSlack allows for the ability to send messages to Slack using Slack’s chat.postMessage API. This Processor should be preferred over the deprecated PutSlack and PostSlack Processors, as it aims to incorporate the capabilities of both of those Processors, improve the maintainability, and ease the configuration for the user.

    Slack Setup

    In order use this Processor, it requires that a Slack App be created and installed in your Slack workspace. An OAuth User or Bot Token must be created for the App. The token must have the chat:write Token Scope. Please see Slack’s documentation for the latest information on how to create an Application and install it into your workspace.

    Depending on the Processor’s configuration, you may also require additional Scopes. For example, if configured to upload the contents of the FlowFile as a message attachment, the files:write User Token Scope or Bot Token Scope must be granted. Additionally, the Channels to consume from may be listed either as a Channel ID or (for public Channels) a Channel Name. However, if a name, such as #general is used, the token must be provided the channels:read scope in order to determine the Channel ID for you.

    Rather than requiring the channels:read Scope, you may alternatively supply only Channel IDs for the “Channel” property. To determine the ID of a Channel, navigate to the desired Channel in Slack. Click the name of the Channel at the top of the screen. This provides a popup that provides information about the Channel. Scroll to the bottom of the popup, and you will be shown the Channel ID with the ability to click a button to Copy the ID to your clipboard.

    At the time of this writing, the following steps may be used to create a Slack App with the necessary scope of chat:write scope. However, these instructions are subject to change at any time, so it is best to read through Slack’s Quickstart Guide.

    • Create a Slack App. Click here to get started. From here, click the “Create New App” button and choose “From scratch.” Give your App a name and choose the workspace that you want to use for developing the app.
    • Creating your app will take you to the configuration page for your application. For example, https://api.slack.com/apps/<APP_IDENTIFIER>. From here, click on “OAuth & Permissions” in the left-hand menu. Scroll down to the “Scopes” section and click the “Add an OAuth Scope” button under ‘Bot Token Scopes’. Choose the chat:write scope.
    • Scroll back to the top, and under the “OAuth Tokens for Your Workspace” section, click the “Install to Workspace” button. This will prompt you to allow the application to be added to your workspace, if you have the appropriate permissions. Otherwise, it will generate a notification for a Workspace Owner to approve the installation. Additionally, it will generate a “Bot User OAuth Token”.
    • Copy the value of the “Bot User OAuth Token.” This will be used as the value for the ConsumeSlack Processor’s Access Token property.
    • The Bot must then be enabled for each Channel that you would like to consume messages from. In order to do that, in the Slack application, go to the Channel that you would like to consume from and press /. Choose the Add apps to this channel option, and add the Application that you created as a Bot to the channel.
Properties
Relationships
Name Description
rate limited FlowFiles are routed to 'rate limited' if the Rate Limit has been exceeded
success FlowFiles are routed to success after being successfully sent to Slack
failure FlowFiles are routed to 'failure' if unable to be sent to Slack for any other reason
Writes Attributes
Name Description
slack.channel.id The ID of the Slack Channel from which the messages were retrieved
slack.ts The timestamp of the slack messages that was sent; this is used by Slack as a unique identifier
Use Cases
  • Send specific text as a message to Slack, optionally including the FlowFile's contents as an attached file.
    Description
    Send specific text as a message to Slack, optionally including the FlowFile's contents as an attached file.
    Configuration
    Set "Access Token" to the value of your Slack OAuth Access Token.
    Set "Channel" to the ID of the channel or the name of the channel prefixed with the # symbol. For example, "C0123456789" or "#general".
    Set "Publish Strategy" to "Use 'Message Text' Property".
    Set "Message Text" to the text that you would like to send as the Slack message.
    Set "Include FlowFile Content as Attachment" to "true" if the FlowFile's contents should be attached as a file, or "false" to send just the message text without an attachment.
    
  • Send the contents of the FlowFile as a message to Slack.
    Description
    Send the contents of the FlowFile as a message to Slack.
    Configuration
    Set "Access Token" to the value of your Slack OAuth Access Token.
    Set "Channel" to the ID of the channel or the name of the channel prefixed with the # symbol. For example, "C0123456789" or "#general".
    Set "Publish Strategy" to "Send FlowFile Content as Message".
    
Use Cases Involving Other Components
  • Respond to a Slack message in a thread.
    Description
    Respond to a Slack message in a thread.
    Keywords
    slack, respond, reply, thread
    Processor Configurations
    org.apache.nifi.processors.standard.EvaluateJsonPath
    Set "Destination" to "flowfile-attribute"
    
    Add a new property named "thread.ts" with a value of `$.threadTs`
    Add a new property named "message.ts" with a value of `$.ts`
    Add a new property named "channel.id" with a value of `$.channel`
    Add a new property named "user.id" with a value of `$.user`
    
    Connect the "matched" Relationship to PublishSlack.
    
    org.apache.nifi.processors.slack.PublishSlack
    Set "Access Token" to the value of your Slack OAuth Access Token.
    Set "Channel" to `${'channel.id'}`
    Set "Publish Strategy" to "Use 'Message Text' Property".
    Set "Message Text" to the text that you would like to send as the response. If desired, you can reference the user of the original message by including the text `<@${'user.id'}>`.
        For example: `Hey, <@${'user.id'}>, thanks for asking...`
    Set "Include FlowFile Content as Attachment" to "false".
    Set "Thread Timestamp" to `${'thread.ts':replaceEmpty( ${'message.ts'} )}`
    
See Also