Skip to content

🐛 stop dropping received card messages - #179

Merged
StarHeartHunt merged 1 commit into
masterfrom
fix/received-card-message
Nov 7, 2026
Merged

StarHeartHunt merged 1 commit into
masterfrom
fix/received-card-message

Conversation

@StarHeartHunt

Copy link
Copy Markdown
Member

Forwarding a card to the bot lost the event without any reply or error message. Message.deserialize passed the received content to the segment builders as arguments, and a received card has title and elements, which MessageSegment.interactive() does not accept. The TypeError was raised inside Bot.handle_event, before any matcher ran.

The same crash applied to two more cases:

  • Divider system messages: MessageSegment.system() does not accept their documented divider_text field.
  • Any message type: the event would be lost as soon as Feishu added a field to its content.

Changes

Parsing

deserialize no longer expands the content into builder arguments. _RECEIVED_SEGMENTS maps each message type to its segment class, and the segment keeps the received content as it is. Types without a class, such as merge_forward and vote, stay generic as before.

seg.data now holds exactly what Feishu sent:

  • A field that Feishu omits is missing, where a builder used to fill it with None.
  • An unknown field stays in data, so it is also sent if the segment is sent again.

Received system messages are still System segments, so the check from #176 keeps working, including for dividers.

Sending a received card

Received cards become ReceivedInteractive, a subclass of Interactive. seg.type is still interactive.

The documentation states that the received structure differs from the sent card JSON, which is the same situation as #176. Message.serialize() now raises ValueError before any request is made, both alone and combined with other segments:

Cannot send a received card, use MessageSegment.interactive instead

Testing

  • 38 tests added, 20 of which fail without this fix. They use the structures from the documentation linked above.
  • test_received_message_reaches_matchers runs Bot.handle_event with a card and with an unknown field, because that is where the event was lost.
  • pytest passes on Python 3.11 and 3.15. Ruff passes, and Pyright reports nothing new in message.py.

This was not tested with a card forwarded in a real Feishu client. The received structure comes from the documentation only.

This is independent of #178. Merging the two gives no conflicts and 140 passing tests, and a local fake Feishu confirmed that a card sent over the long connection reaches a matcher.

Message.deserialize passed the received content to the segment builders as arguments. Received cards and divider system messages have fields the builders do not accept, so it raised TypeError before any matcher ran and the event was lost. Any field Feishu adds later would have done the same.
@StarHeartHunt StarHeartHunt added the bug Something isn't working label Nov 7, 2026
@codecov

codecov Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.19%. Comparing base (201aa75) to head (44e13c7).
⚠️ Report is 3 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #179      +/-   ##
==========================================
+ Coverage   83.82%   89.19%   +5.36%     
==========================================
  Files          15       11       -4     
  Lines        1719     1499     -220     
==========================================
- Hits         1441     1337     -104     
+ Misses        278      162     -116     
Flag Coverage Δ
unittests 89.19% <100.00%> (+5.36%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

@StarHeartHunt
StarHeartHunt merged commit 674f19a into master Nov 7, 2026
21 checks passed
@StarHeartHunt
StarHeartHunt deleted the fix/received-card-message branch November 7, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant