Files
openswarm/backend/apps
Arnav Naval 7729d5957e [arnav] twitter: add DM support — 1:1, groups, reactions
Add 12 new routes under /api/twitter that wrap every twikit Client
DM method that exists directly (no inbox listing — twikit has no
high-level method for it). Same gate discipline as the tweet writes:
all sends/deletes/reactions go through pick_writable so only
role=primary accounts can DM on the user's behalf, and DM reads cache
on short TTLs (15s for conversations, 60s for group metadata).

1:1 reactions compute the X-side conversation_id
("{partner_id}-{my_user_id}") inside the route via client.user_id(),
matching twikit's own Message.add_reaction formula; group reactions
pass the group_id directly. The send_dm path inherits twikit's own
user_id() lookup, which is cached after first hit so the bucket cost
is one-time.

- models: SendDMRequest, AddGroupMembersRequest, ChangeGroupNameRequest,
  AddDMReactionRequest, AddGroupReactionRequest
- ratelimit: 8 new DEFAULT_BUDGETS entries (send_dm/delete_dm/
  dm_conversation/get_group/add_members_to_group/change_group_name/
  add_reaction_to_message/remove_reaction_from_message). DM caps are
  tight by default — operators dial up via trust_multiplier once
  they've observed no 429s
- serializers: message_to_dict (Message + GroupMessage; group_id is
  None for 1:1), group_to_dict (members serialized via user_to_dict)
- twitter.py: POST/GET /users/{user_id}/dms, DELETE /dms/{message_id},
  POST/DELETE /dms/{message_id}/reaction, POST/GET /groups/{group_id}/dms,
  GET /groups/{group_id}, POST /groups/{group_id}/members, PATCH
  /groups/{group_id}/name, POST/DELETE /groups/{group_id}/messages/
  {message_id}/reaction — plus dm_conversation/get_group cache TTLs
- twitter_mcp_shim: 10 new MCP tools (1:1 reactions only; group
  reactions reachable via HTTP route, no shim tool for parity with the
  1:1 flow and to keep the tool count modest)
- tests: extend _add_fake_account with the DM AsyncMock surface
  (incl. user_id returning "me-1" for conv_id assertions); 23 new
  route tests covering happy paths, kwarg forwarding, caching, the
  computed 1:1 conv_id ("u-42-me-1"), group reactions (conv_id =
  group_id), 429 surfacing on the send_dm bucket, and role gating;
  expanded shim tools-list expected to 25 entries and added 16
  per-tool dispatch tests
2026-05-17 20:28:32 -05:00
..
2026-03-13 12:09:25 -07:00
2026-03-13 12:09:25 -07:00
2026-03-13 12:09:25 -07:00
2026-03-13 12:09:25 -07:00