Skip to content

feat(messenger): PoC Integrating AgriConnect with Facebook Messenger #198

Closed

Description

@wayangalihpratama

Objective & Problem Statement

Currently, AgriConnect engages farmers and community users primarily through WhatsApp (via Twilio/Meta WhatsApp Cloud API). To broaden accessibility and support new partner channels, we need a Proof of Concept (PoC) demonstrating multi-channel support by integrating with Facebook Messenger.

Scope & Implementation Plan

  1. Webhook Handshake & Ingestion (/api/messenger/webhook):
    • GET /api/messenger/webhook: Handles Meta webhook challenge verification (hub.challenge, hub.verify_token).
    • POST /api/messenger/webhook: Ingests incoming messages, quick reply selections, and attachments with X-Hub-Signature-256 HMAC validation.
    • Ignore echo messages (is_echo: true) and delivery receipts.
  2. Meta Graph Send API (MessengerService):
    • Outbound messaging service utilizing Meta Graph API (https://graph.facebook.com/v21.0/me/messages) with Page Access Token.
    • Support for text messages and quick replies.
  3. Channel & Customer Identification (Zero Migration):
    • Identify Facebook users by mapping Page-Scoped User IDs (PSID) to Customer.phone_number as messenger:<PSID>.
    • Reuses existing OnboardingService, FollowUpService, and ExternalAIService without breaking changes or database migrations.
  4. Data Privacy & Account Deletion Support:
    • In-Chat Self-Service Deletion: Ingests "delete" / "futa" commands and prompts for confirmation before permanently purging user data via CustomerService.delete_customer().
    • Meta Platform Data Deletion Callback: Implements POST /api/messenger/data-deletion parsing Meta signed requests and returning status verification URLs.

Acceptance Criteria

  • Meta webhook verification handshake (GET) passes with configured MESSENGER_VERIFY_TOKEN.
  • Incoming text message from Facebook Messenger triggers automated onboarding or AI advisory response.
  • Response is sent back to the user's Facebook Messenger chat via Graph API.
  • Message echo events and duplicate deliveries are safely ignored.
  • In-chat account deletion ("delete" / "futa" + "yes") successfully deletes customer and all associated records.
  • Meta data deletion callback (POST /api/messenger/data-deletion) validates signed requests and removes user data.
  • Unit & integration tests with pytest covering webhook handling, signature verification, and mocked Meta API outbound calls.

Documentation & References

  • Specification: docs/FACEBOOK_MESSENGER_INTEGRATION.md

Asana task: https://app.asana.com/1/77063628301548/project/1210637539897027/task/1218915575364073?focus=true

Activity

  1. added 10 commits that reference this issue on Sep 29, 2026
  2. added 3 commits that reference this issue on Sep 30, 2026
  3. added a commit that references this issue on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions