Commit e6e1d18
feat(messenger): scaffolding — types, format converter, cards (PR 1 of 2) (#118)
* feat(messenger): scaffolding — types, format converter, cards (vercel/chat#461)
PR 1 of 2 for the Messenger (Meta) adapter port. Non-adapter scaffolding
only; the adapter (webhook routing, Graph API, signature verification,
send/stream) lands in PR 2. Mirrors how the Telegram port was split.
Adds under src/chat_sdk/adapters/messenger/:
- types.py: MessengerAdapterConfig (app_secret / page_access_token /
verify_token with FACEBOOK_* env fallbacks), MessengerThreadId,
sender/recipient/attachment/message/postback/reaction/delivery/read,
webhook entry/payload, send-API response, user profile, button +
template-element + generic/button template payloads, MessengerRawMessage.
- format_converter.py: MessengerFormatConverter (no markdown rendering;
stringifies AST, overrides render_postable). Mirrors upstream markdown.ts.
- cards.py: card_to_messenger (template|text), card_to_messenger_text,
encode/decode_messenger_callback_data ("chat:{json}" prefix). Generic
template when title/imageUrl present, Button template otherwise; tables /
selects / radio_selects fall back to text. Caps: 20-char button titles,
80 subtitle, 640 button-template text, 3 buttons max.
- __init__.py: exports converter, card helpers, and types only (PR 2 adds
the adapter export).
Tests: tests/test_messenger_cards.py + tests/test_messenger_format.py
(56 tests) ported from upstream cards.test.ts / markdown.test.ts.
Design open question (#110 Q2): decode_messenger_callback_data returns the
raw string as both action_id and value for non-"chat:" payloads. Mirrored
from upstream exactly and pinned with a test + "# Divergence-candidate
(see #110)" breadcrumb; not tightened in this PR.
Refs #110, #98.
https://claude.ai/code/session_01FyMxQn2BEAzmwKS1GZczKj
* refactor(messenger): drop dead MAX_TEXT_LENGTH from cards scaffolding (review)
https://claude.ai/code/session_01FyMxQn2BEAzmwKS1GZczKj
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 1320300 commit e6e1d18
6 files changed
Lines changed: 1541 additions & 0 deletions
File tree
- src/chat_sdk/adapters/messenger
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
0 commit comments