Package com.tnsai.channels.whatsapp
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 forX-Hub-Signature-256. Required.graphBaseUrl- Graph API base URL. Defaults tohttps://graph.facebook.com/v18.0; tests override to a MockWebServer. Always lacks a trailing slash.webhookPort- port the embedded HTTP server binds to. Defaults toDEFAULT_WEBHOOK_PORT.webhookPath- URL path the embedded server serves. Defaults to/webhook.webhookBindAddress- bind address; defaults to127.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_tokenquery param on the GET handshake). Set in the Meta dev console; we compare equality. - appSecret — used to compute the
X-Hub-Signature-256HMAC that authenticates every inbound POST. Without this we'd trust any anonymous request to/webhookas 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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault bind address — loopback only; production is fronted by a reverse proxy.static final StringDefault Graph API base URL — v18.0.static final StringDefault webhook URL path.static final intDefault webhook port. 8443 stays out of the 80/443 reserved range. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theaccessTokenrecord component.Returns the value of theappSecretrecord component.final booleanIndicates whether some other object is "equal to" this one.static Optional<WhatsAppChannelConfig> Populate from environment variables.Returns the value of thegraphBaseUrlrecord component.final inthashCode()Returns a hash code value for this object.Returns the value of thephoneNumberIdrecord component.final StringtoString()Returns a string representation of this record class.Returns the value of theverifyTokenrecord component.Returns the value of thewebhookBindAddressrecord component.Returns the value of thewebhookPathrecord component.intReturns the value of thewebhookPortrecord component.
-
Field Details
-
DEFAULT_GRAPH_BASE_URL
Default Graph API base URL — v18.0.- See Also:
-
DEFAULT_WEBHOOK_PORT
public static final int DEFAULT_WEBHOOK_PORTDefault webhook port. 8443 stays out of the 80/443 reserved range.- See Also:
-
DEFAULT_WEBHOOK_PATH
Default webhook URL path.- See Also:
-
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 aWhatsAppChannelConfigrecord class.- Parameters:
accessToken- the value for theaccessTokenrecord componentphoneNumberId- the value for thephoneNumberIdrecord componentverifyToken- the value for theverifyTokenrecord componentappSecret- the value for theappSecretrecord componentgraphBaseUrl- the value for thegraphBaseUrlrecord componentwebhookPort- the value for thewebhookPortrecord componentwebhookPath- the value for thewebhookPathrecord componentwebhookBindAddress- the value for thewebhookBindAddressrecord component
-
-
Method Details
-
fromEnvironment
Populate from environment variables. Missing any required var returnsOptional.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
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
accessToken
Returns the value of theaccessTokenrecord component.- Returns:
- the value of the
accessTokenrecord component
-
phoneNumberId
Returns the value of thephoneNumberIdrecord component.- Returns:
- the value of the
phoneNumberIdrecord component
-
verifyToken
Returns the value of theverifyTokenrecord component.- Returns:
- the value of the
verifyTokenrecord component
-
appSecret
Returns the value of theappSecretrecord component.- Returns:
- the value of the
appSecretrecord component
-
graphBaseUrl
Returns the value of thegraphBaseUrlrecord component.- Returns:
- the value of the
graphBaseUrlrecord component
-
webhookPort
public int webhookPort()Returns the value of thewebhookPortrecord component.- Returns:
- the value of the
webhookPortrecord component
-
webhookPath
Returns the value of thewebhookPathrecord component.- Returns:
- the value of the
webhookPathrecord component
-
webhookBindAddress
Returns the value of thewebhookBindAddressrecord component.- Returns:
- the value of the
webhookBindAddressrecord component
-