Inbox injection endpoint: POST /api/messages + MCP inject_message (#12) #18

Merged
kamilkrzywda merged 1 commits from feat/inbox-endpoint into main 2026-09-25 01:51:50 +02:00
Owner

What

New POST /api/messages — injects a synthetic inbound (rx) message into the bot's inbox, as if received on the mesh. For external systems to trigger communication later (issue #12). NOT transmitted over RF.

{ "text": "hello bot", "from": 2594370888 }
  • text required non-empty; from optional node number (integer 1..0xffffffff) — omitted → record has no from
  • Record lands in the same history buffer as real traffic: {id, dir:"rx", from?, text, channel:0, at} and appears in GET /api/messages newest-first like any rx message
  • Returns { id }; invalid input → 400 with the same messages on REST and MCP

Details

  • New MeshService.injectMessage(text, from?) — pushes via the existing HISTORY_LIMIT push+shift cap; shared buffer with captured packets (verified by test)
  • Shared randomPacketId() extracted in codec.ts (was inline in buildTextToRadio) — tx sends and injections use the same id generation
  • 9th MCP tool inject_message({text, from?}) — JSON-in-text-block pattern; test asserts nothing reaches the bridge socket (no ToRadio packet on the wire)

Verification

  • npm run build ✓
  • npm test — 42/42 passed (was 37, +5: newest-first rx records, from omitted when absent, empty/invalid rejection, cap at 100, shared buffer with captured packets)
  • v0.9.0, CHANGELOG entry added

Closes #12

## What New `POST /api/messages` — injects a **synthetic inbound (rx) message** into the bot's inbox, as if received on the mesh. For external systems to trigger communication later (issue #12). NOT transmitted over RF. ```json { "text": "hello bot", "from": 2594370888 } ``` - `text` required non-empty; `from` optional node number (integer 1..0xffffffff) — omitted → record has no `from` - Record lands in the same history buffer as real traffic: `{id, dir:"rx", from?, text, channel:0, at}` and appears in `GET /api/messages` newest-first like any rx message - Returns `{ id }`; invalid input → 400 with the same messages on REST and MCP ## Details - New `MeshService.injectMessage(text, from?)` — pushes via the existing HISTORY_LIMIT push+shift cap; shared buffer with captured packets (verified by test) - Shared `randomPacketId()` extracted in codec.ts (was inline in buildTextToRadio) — tx sends and injections use the same id generation - 9th MCP tool `inject_message({text, from?})` — JSON-in-text-block pattern; test asserts nothing reaches the bridge socket (no ToRadio packet on the wire) ## Verification - `npm run build` ✓ - `npm test` — 42/42 passed (was 37, +5: newest-first rx records, from omitted when absent, empty/invalid rejection, cap at 100, shared buffer with captured packets) - v0.9.0, CHANGELOG entry added Closes #12
kamilkrzywda added 1 commit 2026-09-25 01:50:49 +02:00
Inbox injection: POST /api/messages + MCP inject_message (#12)
CI / build + unit (pull_request) Successful in 41s
ca39bb9671
kamilkrzywda merged commit 756086d107 into main 2026-09-25 01:51:50 +02:00
kamilkrzywda deleted branch feat/inbox-endpoint 2026-09-25 01:51:50 +02:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: OpenCode/MeshBot#18