Skip to content

[#198] feat(messenger): integrate Facebook Messenger messaging channel - #202

Merged
wayangalihpratama merged 36 commits into
mainfrom
feature/198-facebook-messenger
Sep 30, 2026
Merged

wayangalihpratama merged 36 commits into
mainfrom
feature/198-facebook-messenger

Conversation

@wayangalihpratama

Copy link
Copy Markdown
Collaborator

Summary & Context

This PR implements and hardens Facebook Messenger as a first-class messaging channel for AgriConnect alongside WhatsApp, resolving [#198]. It enables automated AI advisory responses, human Extension Officer (EO) live chat replies, ticket escalation quick replies, and weather intents for Messenger users (messenger:<PSID>).


Key Changes

1. Facebook Messenger Webhook & Routing

  • Webhook Handlers (backend/routers/messenger.py):
    • GET /api/messenger/webhook: Hub challenge verification with configurable verify token.
    • POST /api/messenger/webhook: Message and postback event ingestion secured by HMAC SHA-256 (X-Hub-Signature-256) timing-safe verification.
  • Channel-Agnostic Dispatch (backend/routers/callbacks.py, backend/routers/messages.py):
    • Dynamically routes outbound messages to MessengerService or WhatsAppService based on customer identifier prefix (messenger:PSID vs phone number).

2. Message Reliability & Hardening

  • Message Chunking (backend/services/messenger_service.py):
    • Automatically splits AI answers exceeding Meta's 2,000-character limit into sequential chunks.
  • Standard Policy Window Compliance:
    • Tags outbound messages with "messaging_type": "RESPONSE" for Meta Graph API v21.0 compliance.
  • Error Rollback & Resilience:
    • Catches outbound delivery failures gracefully without crashing workers with HTTP 500, performing atomic rollbacks of pending messages.

3. Configurable Channels & Typing Indicator

  • Channel Feature Toggles (backend/config.py, config.template.json):
    • Added channels.messenger.enabled and channels.whatsapp.enabled settings.
  • Non-Blocking Typing Indicator:
    • Added channels.messenger.typing_indicator_enabled (defaults to false to minimize Meta API quota consumption).

4. Interactive Features

  • Escalation Quick Replies: Generates YES/NO postback buttons for ticket escalation confirmation.
  • Weather Intents: Routes natural-language weather queries to WeatherIntentService.

Testing & Quality Gates

  • Flake8 Compliance: 0 lint errors across the backend repository (--exclude=alembic,patches).
  • Targeted Test Suite: 84 passed tests in tests/test_messenger_router.py, test_messenger_service.py, test_message_endpoint.py, and test_follow_up_service.py.
  • Full Backend Regression Suite: 1,186 passed tests.
  • Live ngrok Verification: End-to-end webhook ingestion and external RAG AI worker callbacks verified.

Issue Reference

Closes #198

anjarakvo and others added 30 commits August 18, 2026 13:13
Trigger on tenant/com; target app-name com-agriconnect, namespace
com-agriconnect-namespace, env CoM-Hydroponics; bake WEBDOMAIN
com.agriconnect.akvotest.org. Images eu.gcr.io/akvo-lumen/com-agriconnect/*.
build.sh IMAGE_PREFIX=com-agriconnect; docker-compose.test.yml must match
or the backend test service tries to pull agriconnect2/backend (denied).
Branch tenant/com contains a slash; composite-actions tags images with
$GITHUB_REF_NAME.$GITHUB_SHA (build/push/rollout), and a slash is an
invalid docker tag. Override GITHUB_REF_NAME=tenant-com on build-push and
rollout so the tag is tenant-com.<sha>.
Each tenant deploys to its own namespace; a global deploy-to-test group
needlessly serialized tenant deploys behind main. Use
deploy-to-test-${{ github.ref_name }} so tenants deploy independently.
The env override for GITHUB_REF_NAME doesn't reach inside the composite
action (GitHub re-injects the default). Instead, after checking out
composite-actions, sed-patch the helper scripts (build/push/k8s-rollout)
to run $3 through 'tr / -', so images tag/deploy as tenant-com.<sha>.
Expo @akvo/com-hydroponics-mobile (projectId 7e9f4622-d223-4d99-a005-5b96293bd978),
slug com-hydroponics-mobile, app name CoM Hydroponics, Android package
com.akvo.comhydroponics (test: .test).
…m-hydroponics

[#189] feat(tenant): setup initial COM hydroponics administrative hierarchy and configuration
…nt-com

[#195] merge(tenant/com): sync configurable escalation feature from main
@wayangalihpratama wayangalihpratama self-assigned this Sep 30, 2026
@wayangalihpratama wayangalihpratama linked an issue Sep 30, 2026 that may be closed by this pull request
7 tasks
@wayangalihpratama
wayangalihpratama merged commit 9e03171 into main Sep 30, 2026
1 check passed
@wayangalihpratama
wayangalihpratama deleted the feature/198-facebook-messenger branch September 30, 2026 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(messenger): PoC Integrating AgriConnect with Facebook Messenger

2 participants