Add Facebook comment and reaction webhook handling - #145
Conversation
Introduce comment/reaction adapters and filters, extend the Graph API helpers and webhook routing so page comments and reactions can be ingested alongside existing Messenger message flows. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Review follow-ups on the comments/reactions work. Two of these compound into the same user-visible failure. Meta delivers webhooks at-least-once and retries for days. The Messenger path guards that on `mid` via remember_meta_wamid; the feed paths did not, so a redelivery posted a SECOND public reply under the same comment. Both now dedupe through the same helper. Comments key on the comment_id, which is stable and cannot be an edit -- only verb == "add" reaches here. Reactions carry no id, so the key is composed, and it includes the event timestamp on purpose: a retry repeats the timestamp, while a user who removes and re-adds a reaction produces a new one and is still heard. Keying on (post, comment, sender, type) alone would have silently eaten the second case. The retries were partly self-inflicted. Both feed paths awaited a full orchestrator turn inline in the webhook handler, holding the response open while the model and tools ran, so Meta timed the delivery out and resent it. They now dispatch via create_task with the same inline fallback the Messenger path uses for runtimes that cannot background. A comment longer than FEED_COMMENT_UTTERANCE_MAX was dropped with `continue` and no log -- the commenter got no reply and nothing explained why, while the reaction path 60 lines below truncated. It now truncates and logs. The markdown-to-plain-text transformation existed twice, once in the filter and once in the adapter, along with two independent declarations of FACEBOOK_COMMENT_MAX_LENGTH. Both now call facebook_comment_text, so a fix to one cannot leave the other emitting raw markdown into a public comment. Links keep their destination there -- `[label](url)` becomes `label (url)` -- because a comment reader cannot hover or recover a URL that was thrown away. Adds the first tests for this feature. TestEndpointWiring asserts on source structure rather than behaviour, and says so: driving the webhook needs a live graph, an agent and a model, so it guards that the dedup and the backgrounding are present, while the dedup keys themselves are exercised through the real helper. All three fixes were mutation-checked -- reverting each one turns the suite red.
|
Reviewed this and pushed the fixes in 3b9109b rather than leaving a list — full reasoning in the commit message. Two of the findings compound into the same user-visible failure, so they are worth reading together. Duplicate public commentsMeta delivers webhooks at-least-once and retries for days. The Messenger path guards that on Both paths now dedupe through the same helper:
The retries were partly self-inflictedBoth feed paths Long comments were dropped silently
One copy of the text shaping
While there: links keep their destination — Tests14, where the feature had none. Mutation-checked — reverting each fix turns the suite red:
One honest limit: Worth calling out as genuinely good
Local gate green: |
Summary
pageindex-lean-hits(Slim PageIndex search hits and list payloads for observation budgets. #141) because it builds on the proactive Messenger / startup-webhook work already on that branch. Retarget tomainafter Slim PageIndex search hits and list payloads for observation budgets. #141 merges.Test plan
pytest tests/action/facebook_action/(and any new coverage if added) passesMade with Cursor