Skip to content

feat(events): bot check-in integration - #326

Merged
danielhe4rt merged 4 commits into
he4rt:feat/eventsfrom
GabrielFVDev:feat/integration-event-bot
Jun 14, 2026
Merged

danielhe4rt merged 4 commits into
he4rt:feat/eventsfrom
GabrielFVDev:feat/integration-event-bot

Conversation

@GabrielFVDev

Copy link
Copy Markdown
Contributor

Summary

Implements the Events-module side of bot-triggered check-in (Discord/Twitch). The bot dispatches a CheckInRequested domain event; Events listens (HandleBotCheckIn), resolves the user and enrollment, processes the check-in by reusing the numeric-code validation, and dispatches a CheckInProcessed response so the bot can reply to the member in chat. The bot is pure transport; Events owns the rules (ADR-0005).

Flow: CheckInRequested → HandleBotCheckIn → NumericCodeCheckInAction → CheckInProcessed

Closes #248


What changed — app-modules/events

File Role
src/CheckIn/Events/CheckInRequested.php Inbound domain event dispatched by the bot. Payload: provider, externalUserId, code, tenantId, eventId? (reserved, see below), channelContext.
src/CheckIn/Events/CheckInProcessed.php Outbound response event for the bot to reply in chat. Payload: provider, externalUserId, status, message, channelContext, enrollmentId?.
src/CheckIn/Enums/BotCheckInStatus.php Success / Error status for the response event.
src/CheckIn/Listeners/HandleBotCheckIn.php Resolves the user via Identity (FindExternalIdentity), resolves the enrollment, delegates to NumericCodeCheckInAction, dispatches CheckInProcessed. Catches ExternalIdentityException / CheckInException → error response.
src/CheckIn/Exceptions/CheckInException.php Adds botNoActiveEnrollment() and botMultipleActiveEvents() factories.
lang/en/check_in.php, lang/pt_BR/check_in.php Bot-facing messages (user not linked, no active enrollment, success) + reworded multiple-events message.
src/EventsServiceProvider.php Registers CheckInRequested → HandleBotCheckIn.

Event resolution (the important bit)

The listener finds the user's check-in-able enrollments (confirmed/checked_in) for a published event happening today, scoped to the tenant. When the user has more than one active event the same day (e.g. a morning and an evening online event), the typed code identifies which event — each CheckInCode belongs to a single event.

This replaces an earlier date-only resolution that errored on any 2-same-day case, which would have wrongly blocked the legitimate morning+evening scenario. The single-event flow is unchanged; only a genuine collision (same code value on two same-day events the user is enrolled in) returns an ambiguity error pointing to the panel.


Acceptance criteria

  • CheckInRequested defined with proper payload
  • Events listener resolves the user and processes the check-in
  • CheckInProcessed response dispatched with success/error status
  • Numeric code validation applies the same rules as the web flow (delegates to NumericCodeCheckInAction)
  • Error cases handled: user not linked, not enrolled, invalid code, already checked in, ambiguous code
  • Listener registered via EventsServiceProvider — manual registration (Laravel event auto-discovery is disabled app-wide; matches the existing GenerateQrTokenOnConfirmed pattern)
  • Feature tests (see Test plan)
  • Pint passes

Test plan

# Bot check-in tests
vendor/bin/pest app-modules/events/tests/Feature/HandleBotCheckInTest.php

# Full events module (must stay green)
vendor/bin/pest app-modules/events/tests

# Style + static analysis
make pint && make phpstan

Results:

  • HandleBotCheckInTest: 11/11
  • Events module: 133/133 (0 regressions)
  • Pint: clean · PHPStan: 0 errors · Rector (dry-run): clean

Scenarios covered: success + success response · unlinked user · invalid code · no active enrollment · event not today · multiple events → typed code selects the right one · multiple events + non-matching code → invalid · same code on two events → ambiguity error · already checked in today · waitlisted enrollment ignored.


Out of scope (separate issues)

  • The bot-side command that dispatches CheckInRequested (app-modules/bot-discord/) — separate concern, per the issue.
  • Rate limiting on the bot path — deferred to the bot command (the web flow already throttles 5/60s).
  • Explicit event selection (eventId / "path A") — the field stays reserved in the payload but is not honored; the typed code already resolves the event.

@GabrielFVDev GabrielFVDev self-assigned this Jun 14, 2026
@danielhe4rt
danielhe4rt merged commit 98342e9 into he4rt:feat/events Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants