Record Class SlackChannelConfig

java.lang.Object
java.lang.Record
com.tnsai.channels.slack.SlackChannelConfig
Record Components:
botToken - xoxb-... Bot User OAuth token for the Slack Web API. Required.
appToken - xapp-... App-Level Token granting the connections:write scope, used to open the Socket Mode WebSocket. Required.
webApiBaseUrl - base URL for the Slack Web API. Defaults to https://slack.com/api; tests override this to point at a MockWebServer instance. Always lacks a trailing slash.
reconnectInitialBackoff - initial WebSocket reconnect delay. Doubled on each consecutive failure up to reconnectMaxBackoff.
reconnectMaxBackoff - cap for the reconnect delay.

public record SlackChannelConfig(String botToken, String appToken, String webApiBaseUrl, Duration reconnectInitialBackoff, Duration reconnectMaxBackoff) extends Record
Configuration for SlackChannel.

Slack auth uses two distinct tokens because the channel runs in Socket Mode: the bot token (xoxb-...) is the Bot User OAuth token used for outbound Web API calls (chat.postMessage et al), and the app token (xapp-...) is the App-Level Token used to open the inbound WebSocket via apps.connections.open. Both are mandatory; without either, the channel declines to start.

Socket Mode is chosen over the Events API webhook for v1 (TNS-350 spec called for the latter) because the framework intentionally has no HTTP server inside tnsai-channels — every adapter today pulls from its platform (Telegram long-poll, Email IMAP poll) rather than accepting inbound HTTP. Adding a public-URL-exposing webhook receiver would be a much larger architectural change than wiring up a WebSocket, and would block a homelab deployment topology where inbound HTTP is not feasible. A signing-secret-verifying SlackWebhookChannel sibling can be added later if a use case needs it.

  • Field Details

    • DEFAULT_WEB_API_BASE_URL

      public static final String DEFAULT_WEB_API_BASE_URL
      Default base URL for the Slack Web API.
      See Also:
    • DEFAULT_RECONNECT_INITIAL

      public static final Duration DEFAULT_RECONNECT_INITIAL
      Default initial reconnect delay — 1s.
    • DEFAULT_RECONNECT_MAX

      public static final Duration DEFAULT_RECONNECT_MAX
      Default max reconnect delay — 60s.
  • Constructor Details

    • SlackChannelConfig

      public SlackChannelConfig(String botToken, String appToken, String webApiBaseUrl, Duration reconnectInitialBackoff, Duration reconnectMaxBackoff)
      Creates an instance of a SlackChannelConfig record class.
      Parameters:
      botToken - the value for the botToken record component
      appToken - the value for the appToken record component
      webApiBaseUrl - the value for the webApiBaseUrl record component
      reconnectInitialBackoff - the value for the reconnectInitialBackoff record component
      reconnectMaxBackoff - the value for the reconnectMaxBackoff record component
  • Method Details

    • fromEnvironment

      public static Optional<SlackChannelConfig> fromEnvironment()
      Populate from environment variables. Missing required vars return Optional.empty() so the channel can decline to start without raising an exception.

      Recognised vars: SLACK_BOT_TOKEN (required), SLACK_APP_TOKEN (required), SLACK_WEB_API_BASE_URL (optional override for mirrors/proxies).

    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • botToken

      public String botToken()
      Returns the value of the botToken record component.
      Returns:
      the value of the botToken record component
    • appToken

      public String appToken()
      Returns the value of the appToken record component.
      Returns:
      the value of the appToken record component
    • webApiBaseUrl

      public String webApiBaseUrl()
      Returns the value of the webApiBaseUrl record component.
      Returns:
      the value of the webApiBaseUrl record component
    • reconnectInitialBackoff

      public Duration reconnectInitialBackoff()
      Returns the value of the reconnectInitialBackoff record component.
      Returns:
      the value of the reconnectInitialBackoff record component
    • reconnectMaxBackoff

      public Duration reconnectMaxBackoff()
      Returns the value of the reconnectMaxBackoff record component.
      Returns:
      the value of the reconnectMaxBackoff record component