NAME

Discord::Client::Interactions - Interaction handler dispatch

SYNOPSIS

use Discord::Client::Interactions;

# Use an existing registry, transport and loop.
my $dispatcher = Discord::Client::Interactions->new(
    commands => $commands, rest => $rest, loop => $loop,
);

# The host drives the loop while this handler runs.
my $handled = $dispatcher->handle($payload);

DESCRIPTION

Dispatches command, component, autocomplete and modal handlers from Discord::Client::Commands. Handlers receive Discord::Client::Interaction. Acknowledgement and handler completion are tracked separately, so deferred work can continue while the Gateway receives events.

METHODS

new

Returns a dispatcher. commands is required. loop and rest are optional; otherwise a loop is created and contexts create token-only REST when needed. on_error is a synchronous callback receiving ($error, $interaction). Without it, failures warn with sanitized messages.

max_pending defaults to 512 active interactions; max_seen defaults to 10,000 interaction IDs. seen_ttl defaults to 900 seconds; IDs of running handlers remain protected until completion even after expiry. Capacity exhaustion fails with queue_full. Tests can inject clock and delay.

handle

handle(payload_hash, received_at => $time) returns a Future completing when both the initial acknowledgement and handler settle. It resolves with no values or fails with an SDK Error. Cancellation cancels the context and handler. received_at is optional monotonic receipt time; otherwise the current clock is used. Duplicate IDs return the previous Future without running the handler again.

acknowledgement_only => 1 returns the initial-response Future instead; the dispatcher still tracks handler work. An optional initial_sender callback receives an inline response hashref and returns a Future confirming acceptance for HTTP delivery.

stats

Returns a hashref of received, handled, duplicate and error counters, pending handlers and replay entries.

close

Cancels pending contexts and handler work, clears replay entries and returns a completed Future. Supplied REST and Commands objects remain caller-owned.

LICENSE

Apache License 2.0.