Building a Context-Aware Facebook Messenger AI Gateway with Node.js, Meta Webhooks & Zorgax

Leader 1 27
calendar_today agoschedule3 min read

We recently expanded MyZubster's Facebook Messenger integration from a simple webhook into a context-aware gateway powered by Zorgax, the AI copilot of the MyZubster ecosystem.

The interesting part wasn't getting a webhook to return 200 OK.

The interesting part was everything that happened after that.

Our production pipeline now looks like this:

Facebook Messenger → Meta Webhook → MyZubster API → Zorgax → Intent/Context Router → Meta Send API → Messenger

Here are some of the engineering problems we encountered — and what we changed.

  1. A 200 OK doesn't mean the AI finished

Meta expects webhook acknowledgement quickly.

Initially, Messenger events reached our endpoint correctly, but Zorgax processing happened asynchronously after the response. In a serverless environment, that work isn't guaranteed to survive simply because the HTTP request succeeded.

We fixed this by explicitly keeping the asynchronous processing alive with Vercel's waitUntil().

The production flow became:

Webhook event

Validate Meta signature

Return 200 quickly

waitUntil(...)

Zorgax processing

Meta Send API

Messenger response

This was one of the most useful lessons from the integration:

HTTP success and workflow success are two different things.

  1. Conversation context matters

A useful copilot shouldn't require users to repeat themselves.

We added short-term conversation context so a Messenger interaction can look like:

User: I want to become a Seller.

Zorgax: ...

User: How much does it cost?

Zorgax: ...

User: OK, how do I start?

The later messages can be interpreted in the context of the original Seller intent.

For now, this is intentionally lightweight, warm-instance conversation memory. Persistent cross-instance memory is a separate architectural step.

  1. Never let an LLM improvise commercial facts

This became particularly clear during production testing.

When asked:

How much does it cost?

Zorgax correctly remembered that we were discussing the Seller flow — but initially generated unsupported assumptions about free Seller registration and possible transaction fees.

That's unacceptable for pricing information.

We changed the Messenger layer so commercial responses are grounded in known project configuration.

The configured default Seller plan is currently:

SELLER_MONTHLY
€9.90 / month

Zorgax is instructed to tell users to verify the current Marketplace price because live configuration can change.

More importantly, it must not invent commissions, fees, discounts, refunds or payment conditions.

This reinforced a principle we're increasingly applying across MyZubster:

LLMs can generate language. They shouldn't generate facts that your application already knows.

  1. We added image delivery to the conversation

The next step was connecting Messenger with the MyZubster Comic Universe.

Instead of making every request pass blindly through the LLM, we introduced deterministic intent routing.

A request such as:

Show me the MyZubster comic

can now follow:

Message

Comic intent detection

Select public Comic Universe asset

Meta image attachment

Grounded description

Canonical Comic Universe URL

Messenger can therefore deliver both visual content and conversational guidance.

  1. Deterministic routing can beat another AI call

Our first comic implementation still allowed the generic AI response to override known application state.

During a real Messenger test, Zorgax incorrectly said that the comic wasn't publicly available.

But the application already knew that it was.

So we changed the architecture.

Known Comic Universe requests now take a deterministic path instead of relying entirely on generative reasoning.

This means application truth wins over model speculation.

We also added observability around media delivery so logs can distinguish between:

comic intent detected

and:

image successfully sent

That distinction becomes important when debugging third-party APIs.

  1. Fiction and evidence need explicit boundaries

MyZubster's visual ecosystem contains different categories of material.

Some assets are:

FICTION / CONCEPT

while others may be related to evidence, provenance or reference material.

We therefore added an explicit safety rule:

Comic and concept artwork must never be presented as evidence of real-world events.

For example, Messenger can identify an image as:

MyZubster Comic Universe · Origins
FICTION / CONCEPT

while still allowing the user to explore the associated narrative.

That boundary is enforced at the application/prompt layer rather than left to chance.

What the gateway can do now

The Messenger integration now supports secure Meta webhook validation, Zorgax AI responses, multilingual conversations, short-term conversational context, grounded Seller pricing, intent-based routing, Comic Universe image attachments, deterministic responses for known resources, media-delivery observability, and explicit fiction/evidence separation.

The work was developed incrementally through several pull requests:

#1007 — keep Zorgax processing alive after webhook acknowledgement
#1008 — improve Messenger conversation quality and context
#1009 — ground Seller pricing responses
#1010 — connect Comic Universe images
#1011 — prioritize public Comic Universe responses

The project is open source:

MyZubster on GitHub

MyZubster Comic Universe

MyZubster Marketplace

The biggest takeaway from this work is that building an AI chatbot isn't really about connecting an LLM to a messaging API.

The interesting engineering begins when you decide what the model should control, what the application should control, what must come from verified data, and how all of that survives a real production environment.

That's what we're continuing to build with Zorgax and MyZubster.

NodeJS #ArtificialIntelligence #OpenSource #FacebookMessenger #MetaDevelopers #Vercel #Webhooks #AIAgents #LLM #BuildInPublic #MyZubster #Zorgax

🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

The Zero-Net-Loss Fleet & The Mercenary Squad: A Live AI Economy

DEVPlank - Aug 4

Just completed another large-scale WordPress migration — and the client left this

saqib_devmorph - Apr 7

Sovereign Intelligence: The Complete 25,000 Word Blueprint (Download)

Pocket Portfolio - Apr 1

Architecting a Local-First Hybrid RAG for Finance

Pocket Portfolio - Feb 25

Building a Facebook Messenger ↔ AI ↔ Metaverse Bridge with MyZubster and Zorgax

Myzubster - Sep 6
chevron_left
1.6k Points28 Badges
Rimini
34Posts
2Comments
5Connections

Related Jobs

View all jobs →

Commenters (This Week)

3 comments
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!