Skip to content

fix(8): read interactive action_id from context, not top-level#36

Merged
jordanpartridge merged 1 commit into
mainfrom
fix/8-interactive-payload-format
Apr 27, 2026
Merged

fix(8): read interactive action_id from context, not top-level#36
jordanpartridge merged 1 commit into
mainfrom
fix/8-interactive-payload-format

Conversation

@jordanpartridge
Copy link
Copy Markdown
Contributor

Summary

Fix-forward for the bug Lexi flagged on PR #33 — her CHANGES_REQUESTED review landed 6 minutes after the merge, so the broken DTO is currently in main.

InteractiveAction::actionId() and value() were reading top-level action / value keys that do not exist in real Mattermost interactive webhook payloads. Mattermost passes the integrator's context object back unchanged — by convention this package keys the action name as context.action. The original tests passed because MattermostFixtures::fakeButtonClick() fabricated both shapes (the real context key plus spurious top-level shortcuts). In production the top-level shortcuts are absent, so actionId() returned '' and the router never matched any registered handler.

Note on Lexi's review

She had the right diagnosis (DTO reads from the wrong place) but described the format as Slack's (application/x-www-form-urlencoded with a payload field holding JSON). Mattermost's actual format is JSON — see the Mattermost docs. The controller's $request->all() is correct as-is; only the DTO and fixture needed changes.

Changes

  • src/Interactive/InteractiveAction.phpactionId() reads from $payload['context']['action']; value() reads from $payload['context']['value']. Doc-blocks explain the integrator-supplied-context convention.
  • src/Testing/MattermostFixtures.phpfakeButtonClick() no longer emits the spurious top-level action / value keys. Both nest inside context to mirror real Mattermost payloads.
  • tests/Unit/Testing/MattermostFixturesTest.php — assertion updated for the new shape and explicitly checks no top-level action/value keys leak.

Test plan

  • vendor/bin/pest --compact — 341 passed (14 integration skipped)
  • vendor/bin/pint --test — clean
  • vendor/bin/phpstan analyse — clean at level 8
  • vendor/bin/rector process --dry-run — clean

The 34 existing tests/Unit/Interactive/* tests still pass without modification — the fixture continues to expose context.action (where they read it) but no longer emits the spurious top-level fields.

PR #33's Lexi review (CHANGES_REQUESTED, posted 6m after the merge)
flagged that InteractiveAction::actionId() and value() were reading
fields that don't exist in real Mattermost webhook payloads. The bug
was real but the format diagnosis in the review was off — Mattermost
sends JSON (not Slack-style form-urlencoded with a `payload` field),
but it does NOT put `action` or `value` at the top level. Both come
back inside the integrator-supplied `context` object.

The DTO's tests passed because MattermostFixtures::fakeButtonClick()
fabricated both layouts (top-level shortcuts AND the real `context`
key). In production the top-level keys are absent, so actionId()
returned '' and the router never matched any registered handler.

- src/Interactive/InteractiveAction.php: actionId() and value() now
  read from `context.action` and `context.value` respectively, with
  doc-blocks explaining the convention (integrator stuffs the action
  name into the button definition's `integration.context.action`).
- src/Testing/MattermostFixtures.php: drop the spurious top-level
  `action` and `value` shortcuts; nest both inside `context` to match
  what real Mattermost sends.
- tests/Unit/Testing/MattermostFixturesTest.php: updated the
  fakeButtonClick assertion to verify the new shape and explicitly
  assert no top-level `action`/`value` keys.

Controller is unchanged — `$request->all()` works fine for MM's real
JSON body.

341 passed (14 integration skipped); pint, phpstan level 8, rector
all clean.
Copy link
Copy Markdown

@lexi-chief-of-staff lexi-chief-of-staff Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ship it.

  • Clean fix matching Mattermost's context convention; tests now mirror real payloads.
  • Existing InteractiveAction consumers unaffected.
  • All checks green.

@jordanpartridge jordanpartridge merged commit bc5489a into main Apr 27, 2026
4 checks passed
@jordanpartridge jordanpartridge deleted the fix/8-interactive-payload-format branch April 27, 2026 03:19
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.

1 participant