--- title: WhatsApp Bot emoji: 💬 colorFrom: green colorTo: blue sdk: docker app_port: 7860 pinned: false thumbnail: >- https://cdn-uploads.huggingface.co/production/uploads/69ef44f7daf9d56653d76e81/D9XBNpMMZAIZyMhg2nLS1.jpeg --- # 💬 WhatsApp Bot on Hugging Face A WhatsApp chatbot powered by AI, deployed as a Docker Space on Hugging Face. ## Architecture ``` WhatsApp Cloud API (Meta) │ ▼ HTTPS webhooks https://miftahulkhairim-whatsapp-bot.hf.space/webhook │ ▼ HF Docker Space (FastAPI, port 7860) ├── GET /webhook → Meta webhook verification ├── POST /webhook → Receive message → AI reply → Send via WhatsApp API └── GET / → Dashboard UI ``` ## Setup Guide ### 1. Meta Developer Portal Setup 1. Go to [developers.facebook.com](https://developers.facebook.com) → **Create App** → Choose **Business** type 2. Add the **WhatsApp** product to your app 3. In WhatsApp → Getting Started, note your: - **Phone Number ID** - **WhatsApp Business Account ID** - **Temporary Access Token** (for testing) 4. Go to WhatsApp → Configuration → Webhook: - **Callback URL**: `https://miftahulkhairim-whatsapp-bot.hf.space/webhook` - **Verify Token**: Choose any secret string (e.g., `my_verify_token_2024`) - Subscribe to: `messages` ### 2. HF Space Secrets Go to Space Settings → **Repository Secrets** and add: | Secret Name | Value | |---|---| | `WHATSAPP_VERIFY_TOKEN` | Your chosen verify token string | | `WHATSAPP_TOKEN` | Meta access token (from Developer Portal) | | `PHONE_NUMBER_ID` | Your WhatsApp Phone Number ID | | `HF_TOKEN` | Your HF token (for AI inference) | ### 3. Deploy The Space auto-builds and deploys when you push changes. ## Features - 🤖 AI-powered responses using Hugging Face Inference API - 💬 Handles text messages from WhatsApp - 📊 Web dashboard showing bot status and recent messages - 🔒 Secure webhook verification - ⚡ Async message processing for fast responses ## Notes - Free Spaces sleep after ~15 min of inactivity. Consider upgrading to paid hardware for always-on availability. - Access tokens from Meta expire. Use a **System User** permanent token for production.