Class WebhookHandler
java.lang.Object
lv.id.jc.dicechess.runtime.WebhookHandler
Orchestrates one webhook delivery: the ownership handshake, signature verification, and
dispatch to the bot's move-choosing function.
handle(Map, String, long) never throws — every failure mode, including an exception from the
strategy function, becomes a Response with an appropriate status code, so a caller
can always write its result straight back to the HTTP client.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringHeader carrying the hex HMAC-SHA256 signature (seeSignatures).static final StringHeader carrying the delivery's Unix-epoch-seconds timestamp. -
Constructor Summary
ConstructorsConstructorDescriptionWebhookHandler(String secret, String playApiBaseUrl, Function<TurnContext, List<String>> strategy) Creates a handler bound to one secret and one strategy, fetchingGET /games/{id}/movesfromplayApiBaseUrlwhenever the envelope's inline legal-move tree is capped — seeTurnContext.legalMoves().WebhookHandler(String secret, Function<TurnContext, List<String>> strategy) Creates a handler bound to one secret and one strategy, without theGET /games/{id}/movesfallback —TurnContext.legalMoves()will benullon the rare turn where the envelope's inline tree is capped. -
Method Summary
-
Field Details
-
TIMESTAMP_HEADER
Header carrying the delivery's Unix-epoch-seconds timestamp.- See Also:
-
SIGNATURE_HEADER
Header carrying the hex HMAC-SHA256 signature (seeSignatures).- See Also:
-
-
Constructor Details
-
WebhookHandler
Creates a handler bound to one secret and one strategy, without theGET /games/{id}/movesfallback —TurnContext.legalMoves()will benullon the rare turn where the envelope's inline tree is capped.- Parameters:
secret- the webhook secret issued by the platform when the bot registeredstrategy- chooses moves for a turn: aTurnContextin, a UCI move path out
-
WebhookHandler
public WebhookHandler(String secret, String playApiBaseUrl, Function<TurnContext, List<String>> strategy) Creates a handler bound to one secret and one strategy, fetchingGET /games/{id}/movesfromplayApiBaseUrlwhenever the envelope's inline legal-move tree is capped — seeTurnContext.legalMoves(). That endpoint is public, so no additional credential is needed.- Parameters:
secret- the webhook secret issued by the platform when the bot registeredplayApiBaseUrl- play-api's base URL (e.g.https://play-api.jc.id.lv); a trailing slash is toleratedstrategy- chooses moves for a turn: aTurnContextin, a UCI move path out
-
-
Method Details
-
handle
Handles one delivery.- Parameters:
headers- the request headers; lookup is case-insensitive, so any casing worksrawBody- the raw request body, exactly as received (the signature covers these exact bytes)nowEpochSeconds- the current time, Unix epoch seconds- Returns:
- the response to send back — status 200 (handshake echoed, or moves chosen), 400 (unparseable or unrecognized body), 401 (missing, expired, or wrong signature), or 500 (the strategy function threw)
-