Record Class WhatsAppChannelConfig

java.lang.Object
java.lang.Record
com.tnsai.channels.whatsapp.WhatsAppChannelConfig
Record Components:
accessToken - Graph API bearer token. Required.
phoneNumberId - sending phone number ID for outbound. Required.
verifyToken - echoed back to Meta on the verification GET. Required.
appSecret - HMAC-SHA256 key for X-Hub-Signature-256. Required.
graphBaseUrl - Graph API base URL. Defaults to https://graph.facebook.com/v18.0; tests override to a MockWebServer. Always lacks a trailing slash.
webhookPort - port the embedded HTTP server binds to. Defaults to DEFAULT_WEBHOOK_PORT.
webhookPath - URL path the embedded server serves. Defaults to /webhook.
webhookBindAddress - bind address; defaults to 127.0.0.1 (loopback only) — production deploys put a reverse proxy in front. Tests use the same loopback.

public record WhatsAppChannelConfig(String accessToken, String phoneNumberId, String verifyToken, String appSecret, String graphBaseUrl, int webhookPort, String webhookPath, String webhookBindAddress) extends Record
Configuration for WhatsAppChannel.

WhatsApp Business Cloud API uses four distinct secrets:

  • accessToken — bearer used on outbound Graph API calls (POST /v.../{phone_id}/messages).
  • phoneNumberId — selects which WhatsApp business phone number outbound messages originate from. Sent as part of the URL path.
  • verifyToken — shared secret that Meta echoes back at webhook subscription time (the hub.verify_token query param on the GET handshake). Set in the Meta dev console; we compare equality.
  • appSecret — used to compute the X-Hub-Signature-256 HMAC that authenticates every inbound POST. Without this we'd trust any anonymous request to /webhook as Meta — so it's required, not optional.

The webhook is served by an embedded JDK HttpServer bound to the configured port and path. A production deployment puts this behind a reverse proxy (Caddy / nginx) that terminates TLS; the adapter itself speaks plain HTTP on localhost. For development the canonical setup is cloudflared tunnel or ngrok http <port> to expose the local server to Meta's webhook delivery.

  • Field Details

    • DEFAULT_GRAPH_BASE_URL

      public static final String DEFAULT_GRAPH_BASE_URL
      Default Graph API base URL — v18.0.
      See Also:
    • DEFAULT_WEBHOOK_PORT

      public static final int DEFAULT_WEBHOOK_PORT
      Default webhook port. 8443 stays out of the 80/443 reserved range.
      See Also:
    • DEFAULT_WEBHOOK_PATH

      public static final String DEFAULT_WEBHOOK_PATH
      Default webhook URL path.
      See Also:
    • DEFAULT_BIND_ADDRESS

      public static final String DEFAULT_BIND_ADDRESS
      Default bind address — loopback only; production is fronted by a reverse proxy.
      See Also:
  • Constructor Details

    • WhatsAppChannelConfig

      public WhatsAppChannelConfig(String accessToken, String phoneNumberId, String verifyToken, String appSecret, String graphBaseUrl, int webhookPort, String webhookPath, String webhookBindAddress)
      Creates an instance of a WhatsAppChannelConfig record class.
      Parameters:
      accessToken - the value for the accessToken record component
      phoneNumberId - the value for the phoneNumberId record component
      verifyToken - the value for the verifyToken record component
      appSecret - the value for the appSecret record component
      graphBaseUrl - the value for the graphBaseUrl record component
      webhookPort - the value for the webhookPort record component
      webhookPath - the value for the webhookPath record component
      webhookBindAddress - the value for the webhookBindAddress record component
  • Method Details

    • fromEnvironment

      public static Optional<WhatsAppChannelConfig> fromEnvironment()
      Populate from environment variables. Missing any required var returns Optional.empty() so the channel can decline to start without raising an exception.

      Recognised vars: WHATSAPP_ACCESS_TOKEN (required), WHATSAPP_PHONE_NUMBER_ID (required), WHATSAPP_VERIFY_TOKEN (required), WHATSAPP_APP_SECRET (required, HMAC), WHATSAPP_GRAPH_BASE_URL (optional), WHATSAPP_WEBHOOK_PORT (optional int), WHATSAPP_WEBHOOK_PATH (optional), WHATSAPP_WEBHOOK_BIND_ADDRESS (optional).

    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      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.
    • accessToken

      public String accessToken()
      Returns the value of the accessToken record component.
      Returns:
      the value of the accessToken record component
    • phoneNumberId

      public String phoneNumberId()
      Returns the value of the phoneNumberId record component.
      Returns:
      the value of the phoneNumberId record component
    • verifyToken

      public String verifyToken()
      Returns the value of the verifyToken record component.
      Returns:
      the value of the verifyToken record component
    • appSecret

      public String appSecret()
      Returns the value of the appSecret record component.
      Returns:
      the value of the appSecret record component
    • graphBaseUrl

      public String graphBaseUrl()
      Returns the value of the graphBaseUrl record component.
      Returns:
      the value of the graphBaseUrl record component
    • webhookPort

      public int webhookPort()
      Returns the value of the webhookPort record component.
      Returns:
      the value of the webhookPort record component
    • webhookPath

      public String webhookPath()
      Returns the value of the webhookPath record component.
      Returns:
      the value of the webhookPath record component
    • webhookBindAddress

      public String webhookBindAddress()
      Returns the value of the webhookBindAddress record component.
      Returns:
      the value of the webhookBindAddress record component