--- name: whatsapp-restaurant-reservation-nodejs title: "Restaurant Reservations via WhatsApp with AI Agent (Node.js)" description: "AI-powered restaurant reservations via WhatsApp with Node.js/Express, deployed on Telnyx Edge Compute. Browse restaurants, book tables through AI conversation, phone validation via Number Lookup API, and live dashboard." language: nodejs framework: express telnyx_products: [whatsapp, ai-inference, edge-compute] --- # DineNyx — WhatsApp Restaurant Reservations (Node.js) AI-powered restaurant reservations via WhatsApp, built with Node.js/Express on Telnyx AI Communications Infrastructure and deployed on [Telnyx Edge Compute](https://telnyx.com/products/edge-compute). Browse real restaurants worldwide, book a table through a WhatsApp conversation with an AI agent, and watch reservations update on a live dashboard in real time. ## Features - **WhatsApp AI Agent** — Natural language booking via Telnyx WhatsApp Business API + AI Inference - **Real Restaurant Data** — Google Places API with fallback seed data for 4 Dutch cities - **Live Dashboard** — SSE-powered 3-panel UI: restaurant browser, phone simulator, reservation board - **Edge-Ready** — Deploys globally on Telnyx Edge Compute for low-latency hosting - **Voice Notes** — Transcribes WhatsApp audio messages using Telnyx AI ## Architecture ``` server.js Express entrypoint: routes, SSE, webhook, startup settings.js Edge detection, DINENYX_ prefix for secrets db.js Dual-engine database (local SQLite / Edge SQL REST API) ai.js AI inference loop, tool definitions, tool executor whatsapp.js WhatsApp messaging + audio transcription restaurants.js Google Places API, fallback seed data, DB caching public/ Static dashboard (HTML + CSS + JS) ``` ## Prerequisites - **Node.js 22+** (uses `node:sqlite`, `process.loadEnvFile()`) - **Telnyx account** with API key ([portal.telnyx.com](https://portal.telnyx.com)) - **Telnyx WABA account** with WhatsApp-enabled number - **Google Places API key** (optional — falls back to seed data) ## Quick Start ```bash # Clone and enter the project git clone https://github.com/team-telnyx/telnyx-code-examples.git cd telnyx-code-examples/whatsapp-restaurant-reservation-nodejs # Install dependencies npm install # Configure environment cp .env.example .env # Edit .env with your API keys # Run locally npm start # Dashboard: http://localhost:3000 ``` ## Environment Variables | Variable | Required | Description | |---|---|---| | `TELNYX_API_KEY` | Yes | Main Telnyx API key (AI Inference) | | `TELNYX_WHATSAPP_API_KEY` | Yes | WABA-enabled Telnyx API key | | `WHATSAPP_NUMBER` | Yes | Your WhatsApp business number (E.164) | | `WHATSAPP_MESSAGING_PROFILE_ID` | Yes | Messaging profile ID from Telnyx Portal | | `AI_MODEL` | No | AI model (default: `zai-org/GLM-5.3-Flash`) | | `GOOGLE_PLACES_API_KEY` | No | Google Places API key for live restaurant data | | `DEFAULT_CITY` | No | Default city (default: `Amsterdam`) | | `PORT` | No | Server port (default: `3000`) | | `SQLDB_ID` | No | Telnyx Edge SQL database ID (Edge deployment only) | ## Webhook Setup 1. In the [Telnyx Portal](https://portal.telnyx.com), go to your Messaging Profile 2. Set the webhook URL to `https://your-domain.com/webhooks/whatsapp` 3. For local development, use [ngrok](https://ngrok.com): `ngrok http 3000` ## Deploy on Telnyx Edge Telnyx Edge Compute runs your app on carrier-edge nodes worldwide for global low-latency hosting. ```bash # 1. Create an Edge SQL database telnyx-edge sql create --name dinenyx-db # Note the database ID # 2. Set secrets (prefixed with DINENYX_) telnyx-edge secrets set DINENYX_TELNYX_API_KEY=KEYyour-key telnyx-edge secrets set DINENYX_TELNYX_WHATSAPP_API_KEY=KEYyour-wa-key telnyx-edge secrets set DINENYX_WHATSAPP_NUMBER=+1XXXXXXXXXX telnyx-edge secrets set DINENYX_WHATSAPP_MESSAGING_PROFILE_ID=your-profile telnyx-edge secrets set DINENYX_SQLDB_ID=your-db-id telnyx-edge secrets set DINENYX_GOOGLE_PLACES_API_KEY=your-google-key # 3. Create the Edge function telnyx-edge create --name dinenyx # Note the function ID # 4. Configure func.toml cp edge/func.toml.example edge/func.toml # Edit edge/func.toml with your function ID # 5. Build and ship npm run edge:ship ``` Your app will be available at `https://dinenyx-*.telnyxcompute.com`. Update the webhook URL in the Telnyx Portal to point to this URL. ## Testing ```bash npm test ``` Runs smoke tests using Node.js built-in test runner. All HTTP calls are mocked — no real credentials needed. ## How It Works 1. **Customer sends a WhatsApp message** → Telnyx webhook delivers it to `/webhooks/whatsapp` 2. **Server extracts text** (or transcribes voice notes) and feeds it to the AI inference loop 3. **AI agent uses tools** to search restaurants, check availability, and make reservations 4. **Agent sends response** back via WhatsApp using Telnyx Messaging API 5. **Dashboard updates in real time** via Server-Sent Events (SSE) ## Database Locally, the app uses SQLite via `node:sqlite` (Node 22+). On Edge, it uses the Telnyx Edge SQL REST API — no storage binding needed, so the function deploys to every Edge site globally. Three tables: `restaurants`, `reservations`, `conversations`. Reservation IDs are UUIDs (portable across local and Edge SQL). ## Why Telnyx - **Carrier-edge deployment** — Edge Compute runs your app on Telnyx's carrier-edge network, delivering lower latency than cloud-edge alternatives - **Unified stack** — AI Inference, WhatsApp Business API, Number Lookup, and Edge Compute under one API key — no Frankenstack of third-party services - **Number Lookup validation** — Validate phone numbers at registration using the Telnyx Number Lookup API before engaging customers ## Troubleshooting | Issue | Fix | |---|---| | `TELNYX_API_KEY not set` | Copy `.env.example` to `.env` and fill in your keys | | No restaurants loading | Set `GOOGLE_PLACES_API_KEY` or rely on fallback seed data (20 Amsterdam restaurants) | | WhatsApp messages not arriving | Verify webhook URL points to `/webhooks/whatsapp` and the messaging profile ID matches | | Edge deploy fails | Ensure `func.toml` has the correct function ID and `telnyx-edge` CLI is authenticated | | AI not responding | Check that `TELNYX_API_KEY` has AI Inference access enabled | ## Related Examples - [whatsapp-restaurant-reservation-python](https://github.com/team-telnyx/telnyx-code-examples/tree/main/whatsapp-restaurant-reservation-python) — Python/Flask version of this demo - [whatsapp-order-tracking-notifications-python](https://github.com/team-telnyx/telnyx-code-examples/tree/main/whatsapp-order-tracking-notifications-python) — WhatsApp order tracking with proactive notifications - [whatsapp-sms-bridge-python](https://github.com/team-telnyx/telnyx-code-examples/tree/main/whatsapp-sms-bridge-python) — Bidirectional WhatsApp-SMS bridge - [ai-restaurant-reservation-voice-agent-python](https://github.com/team-telnyx/telnyx-code-examples/tree/main/ai-restaurant-reservation-voice-agent-python) — Voice-based restaurant reservations with AI - [edge-event-microsite](https://github.com/team-telnyx/telnyx-code-examples/tree/main/edge-event-microsite) — Event microsite with AI concierge on Edge Compute ## Agent Discovery ```json { "name": "DineNyx WhatsApp Restaurant Reservations", "description": "AI-powered restaurant reservations via WhatsApp with live dashboard, deployed on Telnyx Edge Compute", "capabilities": ["whatsapp-messaging", "ai-inference", "number-lookup", "edge-compute", "voice-transcription"], "products": ["WhatsApp Business API", "AI Inference", "Number Lookup", "Edge Compute"], "entry_point": "server.js", "webhook_path": "/webhooks/whatsapp" } ``` ## License MIT