Class SlackEventHook

  • All Implemented Interfaces:
    EventHook

    public class SlackEventHook
    extends java.lang.Object
    implements EventHook
    A dispatcher that sends notifications via Slack's incoming web hooks.
    Since:
    4.5
    • Field Detail

      • USER_NAME_CONFIG_KEY

        public static final java.lang.String USER_NAME_CONFIG_KEY
        See Also:
        Constant Field Values
      • WEBHOOK_URL_CONFIG_KEY

        public static final java.lang.String WEBHOOK_URL_CONFIG_KEY
        See Also:
        Constant Field Values
      • DEFAULT_USERNAME

        public static final java.lang.String DEFAULT_USERNAME
        See Also:
        Constant Field Values
      • DEFAULT_LEVELS

        public static final java.util.Set<Level> DEFAULT_LEVELS
      • DEFAULT_CATEGORIES

        public static final java.util.Set<Category> DEFAULT_CATEGORIES
    • Constructor Detail

      • SlackEventHook

        public SlackEventHook​(java.lang.String userName,
                              java.lang.String webhookUrl,
                              java.util.Set<Level> levels,
                              java.util.Set<Category> categories)
        Creates a new instance with the values. Provided levels and categories restrict which events result in notifications.
        Parameters:
        userName - non-null user name that will post in the Slack channel
        webhookUrl - full web hook URL obtained from Slack (e.g. https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX)
        levels - restricted levels
        categories - restricted categories
    • Method Detail

      • dispatch

        public void dispatch​(Event event)
                      throws java.lang.Exception
        Description copied from interface: EventHook
        This method is invoked for each event, regardless of level or category. Implementors must handle filtering which events require processing depending on the Level and Category.
        Specified by:
        dispatch in interface EventHook
        Throws:
        java.lang.Exception
      • post

        protected void post​(java.lang.String payload)
                     throws java.lang.Exception
        Override to change the actual call to the Slack endpoint.
        Throws:
        java.lang.Exception
      • shouldPostEvent

        protected boolean shouldPostEvent​(Event event)
        Override to get custom behaviour on whether to post to Slack for a given event.
        Returns:
        true if this event should be posted to Slack
      • buildPayload

        protected java.lang.String buildPayload​(Event event)
                                         throws java.lang.Exception
        Override to change the JSON payload that is built for a given event.
        Returns:
        non-null JSON payload representation that can be posted to Slack
        Throws:
        java.lang.Exception
      • getLeadingEmoji

        protected java.lang.String getLeadingEmoji​(Event event)
        Override to change which icon emoji is put in the payload by buildPayload(Event).
        Returns:
        the emoji name (without ":" prefix and suffix), or null
      • getUserName

        public java.lang.String getUserName()
      • getWebhookUrl

        public java.lang.String getWebhookUrl()
      • getLevels

        public java.util.Set<Level> getLevels()
      • getCategories

        public java.util.Set<Category> getCategories()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object