Skip to content

fix: fetchMessages REST shape + streaming truncation; feat: onReaction (v0.3.0) - #4

Merged
mikipalet merged 1 commit into
mainfrom
fix/fetchmessages-shape-and-streaming
May 21, 2026
Merged

fix: fetchMessages REST shape + streaming truncation; feat: onReaction (v0.3.0)#4
mikipalet merged 1 commit into
mainfrom
fix/fetchmessages-shape-and-streaming

Conversation

@mikipalet

Copy link
Copy Markdown
Member

Three fixes reported via support (Crisp ticket) + GitHub issue #3.

1. fetchMessages threw Cannot read properties of undefined (reading 'id') (#3)

The REST GET /messages endpoint returns a flat message shape (senderId / message / createdAt), but parseMessage() was written for the webhook shape (sender.id / text / sentAt), so raw.sender.id dereferenced undefined.

  • Added restToRawMessage() to normalize either shape before parsing.
  • Forward the previously-dropped FetchOptions (limit / cursor / direction) to the REST endpoint, and wire nextCursor from pagination.nextCursor (was hardcoded undefined).
  • The old test masked the bug by mocking the webhook shape via makeRawMessage(). Fixed the fixture (makeRestMessage) and added regression tests for the real shape, options forwarding, desc→chronological ordering, and pagination.

2. thread.post(stream) only delivered the first chunk on non-Telegram platforms

stream() posted chunk 1 then editMessaged the rest, but only Telegram supports edits, so on WhatsApp/IG/FB/X/Bluesky/Reddit every edit threw (silently caught) and the recipient saw only the first chunk.

  • Detect the platform via fetchThread: Telegram keeps live edit-streaming; everyone else buffers the full response and posts once. Falls back to post-once if detection fails.

3. onReaction never fired

Reactions arrived as message.received and were routed to onDirectMessage. Now route the new reaction.received webhook event (see Schedule-Posts-API PR) to chat.processReaction, normalizing the raw unicode emoji to an EmojiValue via defaultEmojiResolver.fromGChat.

Verification

  • 84 tests pass (npm test), tsc --noEmit clean.

Release / consumer notes

  • Bumped to v0.3.0 (backward-compatible additions). Publish runs on a v* tag push after merge.
  • Consumers who want reactions must subscribe to the reaction.received webhook event.

Depends on: zernio-dev/Schedule-Posts-API feat/reaction-received-webhook (the reaction.received event).

🤖 Generated with Claude Code

…n support (v0.3.0)

Three fixes reported via support (Crisp) + GitHub issue #3:

1. fetchMessages threw "Cannot read properties of undefined (reading 'id')".
   The REST GET /messages endpoint returns a flat shape (senderId/message/
   createdAt) but parseMessage expected the webhook shape (sender.id/text/
   sentAt). Added restToRawMessage() to normalize either shape. Also forward
   the previously-dropped FetchOptions (limit/cursor/direction) and wire
   nextCursor from pagination. The old test masked the bug by mocking the
   webhook shape; fixed the fixture and added regression tests.

2. thread.post(stream) only delivered the first chunk on non-Telegram
   platforms: stream() posted chunk 1 then editMessage'd the rest, but only
   Telegram supports edits so every edit threw silently. Now detect the
   platform via fetchThread: Telegram keeps live edit-streaming, all others
   buffer the full response and post once (post-once on detection failure).

3. onReaction never fired: reactions arrived as message.received and routed
   to onDirectMessage. Route the new reaction.received webhook event to
   chat.processReaction with the emoji normalized to an EmojiValue.

84 tests pass, tsc clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mikipalet
mikipalet merged commit 64b8c92 into main May 21, 2026
2 checks passed
@mikipalet
mikipalet deleted the fix/fetchmessages-shape-and-streaming branch May 21, 2026 10:04
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