Class SlackFunctions

java.lang.Object
flexagon.fd.services.groovy.functions.BaseFunctions
flexagon.fd.services.groovy.functions.SlackFunctions
Direct Known Subclasses:
WebhookSlackFunctions

public class SlackFunctions extends BaseFunctions
Utility functions used to get information from a Slack payload
Since:
5.3
  • Field Details

  • Constructor Details

    • SlackFunctions

      public SlackFunctions(LogFunctions pFLOG)
  • Method Details

    • getUserFromSlackId

      public FDUser getUserFromSlackId(String pSlackId) throws FlexCheckedException, FlexNotFoundException
      Returns the FlexDeploy User corresponding to the given Slack user id. This will only work if the user has added their Slack Id in their FlexDeploy User Profile
      Parameters:
      pSlackId - The Slack user id. This can be found in the Slack payload from incoming webhook messages.
      Returns:
      FlexDeploy User Object.
      Throws:
      FlexNotFoundException - If no FlexDeploy user was found for the given Slack id.
      FlexCheckedException - All other exceptions
    • postAttachment

      public void postAttachment(String pSlackAccountCode, String pChannel, InputStream pInputStream, String pMessage, String pParentMessage) throws FlexCheckedException, FlexNotFoundException
      Uploads an attachment to the given Slack channel. The bot being used should have the file:write scope.
      Parameters:
      pSlackAccountCode - Messaging account code for Slack account.
      pChannel - Name or Id of channel where the attachment will be uploaded. Use user channel Id to send direct messages.
      pInputStream - The input stream to upload.
      pMessage - Text to display giving context about the attachment
      pParentMessage - Parent message/ts id if you wish to post attachment as a reply, leave as null otherwise
      Throws:
      FlexNotFoundException - If no account is found for give code
      FlexCheckedException
      Since:
      5.4
    • postAttachment

      public void postAttachment(String pSlackAccountCode, String pChannel, File pFile, String pMessage, String pParentMessage) throws FlexCheckedException, FlexNotFoundException
      Uploads an attachment to the given Slack channel. The bot being used should have the file:write scope.
      Parameters:
      pSlackAccountCode - Messaging account code for Slack account.
      pChannel - Name or Id of channel where the attachment will be uploaded. Use user channel Id to send direct messages.
      pFile - The file to upload.
      pMessage - Text to display giving context about the attachment
      pParentMessage - Parent message/ts id if you wish to post attachment as a reply, leave as null otherwise
      Throws:
      FlexNotFoundException - If no account is found for give code
      FlexCheckedException
      Since:
      5.4
    • postMessage

      public String postMessage(String pSlackAccountCode, String pChannel, FlexSlackMessage pMessage) throws FlexCheckedException
      Posts a Slack message using JSON formatted based on Slack API.
      Parameters:
      pSlackAccountCode - Messaging account code for Slack account.
      pChannel - Name or Id of channel where the notification will be sent. Use user channel Id to send direct messages.
      pMessage - FlexSlackMessage to post. Formatted based on Slack API.
      Returns:
      Slack ts message value. This string can be used to reply to this message or start a thread
      Throws:
      FlexCheckedException
      Since:
      5.4
    • postMessage

      public String postMessage(String pSlackAccountCode, String pChannel, String pJson) throws FlexCheckedException
      Posts a Slack message using JSON formatted based on Slack API.
      Parameters:
      pSlackAccountCode - Messaging account code for Slack account.
      pChannel - Name or Id of channel where the notification will be sent. Use user channel Id to send direct messages.
      pJson - Json string of your Slack message body. Formatted based on Slack API.
      Returns:
      Slack ts message value. This string can be used to reply to this message or start a thread
      Throws:
      FlexCheckedException
      Since:
      5.4
    • postSimpleMessage

      public String postSimpleMessage(String pSlackAccountCode, String pChannel, String pMessageText) throws FlexCheckedException
      Posts a simple Slack message to the specified channel. Slack account code that is passed must have the bearer token which is generated by Slack after adding the app to the workspace.
      Parameters:
      pSlackAccountCode - Messaging account code for Slack account.
      pChannel - Name or Id of channel where the notification will be sent. Use user channel Id to send direct messages.
      pMessageText - Text for the message that will be sent.
      Throws:
      FlexNotFoundException
      FlexCheckedException
      Since:
      5.4
    • getGroovyKey

      public String getGroovyKey()
      Specified by:
      getGroovyKey in class BaseFunctions
    • cleanup

      public void cleanup()
      Specified by:
      cleanup in class BaseFunctions