Discord-Client

 view release on metacpan or  search on metacpan

lib/Discord/Client/HTTPInteractions.pm  view on Meta::CPAN

Returns the supplied or created IO::Async::Loop.

=head2 rest

Returns the REST client used for followups.

=head2 commands

Returns the Commands registry.

=head2 dispatcher

Returns the Interactions dispatcher.

=head2 stats

Returns request, signature, duplicate and error counters as a hashref, plus
C<pending_requests>, C<replay_entries> and C<seen_entries>.

=head2 close

Returns a Future for cleanup. Pending HTTP responses complete with 503;
handlers and timers are cancelled, and owned resources are closed.
Injected REST and Commands objects remain caller-owned. Call it when the host
stops.

=head1 PSGI AND ASYNCHRONOUS HANDLERS

C<psgi_app> returns a coderef accepting POST requests. It reads C<psgi.input>
using Content-Length and returns an immediate response or delayed responder.
The initial response deadline is three seconds, including body reading and
verification.

Immediate handlers work on an ordinary PSGI host. Asynchronous handlers and
work after defer need a host that advertises C<psgi.streaming> and drives the
supplied C<IO::Async::Loop>. Streaming alone does not run pending Futures.
The adapter does not run another loop. Without delayed-response support,
a pending initial response is cancelled and returns 503.

=head1 DUPLICATES

Signed duplicates of running handlers share the initial response. Completed
responses are copied for replay until C<replay_ttl> expires or C<max_replay>
requires eviction of the oldest completed response. Evicted responses return
409 for duplicate IDs; their handlers do not run again while the IDs are retained.

C<max_seen> bounds the retained IDs; reaching it rejects new requests with 503.
Entries expire on subsequent requests, after their handlers finish. A dispatcher
capacity rejection before a handler starts is not retained, so a retry can run
when capacity returns. Failures after dispatch remain protected because the
handler may have performed side effects. This is process-local.
Use shared deduplication across workers if your side effects require it.

=head1 SERVE THE EXAMPLE

Set C<DISCORD_PUBLIC_KEY> to the application's 64-character hexadecimal public
key from the Developer Portal. Install Plack and a PSGI server, then run:

    PERL5LIB=lib plackup examples/http-interactions.psgi

Expose the service over public HTTPS and set its L<Interactions Endpoint URL|https://docs.discord.com/developers/interactions/overview#configuring-an-interactions-endpoint-url> in
the Developer Portal. C<plackup> alone serves local HTTP. The SDK verifies
signatures and answers signed PING requests. HTTP and Gateway are alternative
interaction delivery methods for the application.

=head1 LICENSE

Apache License 2.0.

=cut



( run in 0.705 second using v1.01-cache-2.11-cpan-eb134014566 )